Scenario is like this: I have a couple of devices using autoip and mdns over rndis (ethernet over USB) to connect to a host: You connect them with usb, the PC detects an rndis device, both ends choose a IPv4 address and keep it if it's not occupied. The device has a unique ID as hostname, so the PC can open a socket to ID342384734.local and everything is fine.
Now once in a while two devices attached at the same time will both choose the same IP, say 169.254.42.42. They will not know, because they are on different networks and will not see each other. No collision. The PC doesn't care. But both .local names will get resolved to the same IP address 169.254.42.42, so opening a socket to ID1.local and to ID2.local will end on the same device, because after name resolution they can't be distinguished!
Using IPv6 solves that problem, but is there a smart solution also for IPv4 like teaching socket() to connect to the IP via the interface where the mdns request was answered?
Host and device are Linux with avahi-daemon and avahi-autoipd.