I have machine with two Ethernet network interfaces. eno0 and eno1. eno0 is where the internet is plugged in and eno1 has a connected Ethernet device. I got its IP through Link-Local Address method and it's 168.254.80.23. I would like to send a packet to port 5000.
I would like to use Rust's UdpSocket to connect to this address and given port and send some packet. One such packet is already correctly described in the variable buf_with_message:
let sock = UdpSocket::bind("0.0.0.0:0"); //Let system assign me an ip and port
sock.connect(("168.254.80.23",5000)); // Connect to device ip and pre-designated port 5000
sock.send(&buf_with_message).unwrap(); //Send the packet
That connection occurs as it should, but the packet is send over eno0 instead of eno1. I have no idea how to specify the interface it should use. I have found some answers that in C SO_BINDTODEVICE could be used to do this.
I have also tried assigning an IP to the interface through
sudo ifconfig eno1 192.0.2.10
and then changing the 0.0.0.0 address in UdpSocket::bind to this new address with no positive result.
I see a potential solution to go straight to raw sockets using the pnet crate but I think that would be overkill.
I am aware that RFC 3927 warns against hosts with multiple interfaces, but I didn't find any options for an alternative without ditching LLA and implementing a DHCP server.
192.0.2.*is a range reserved for examples and documentation. You shouldn't, and might not be able, to use it. - mcarton0.0.0.0is an unspecified address, sobindmay not happen on the network interface where the targeted device is attached. Try to bind with the ip assigned at eno1 interface. - attdona55.55.0.2and bind to it. Saddly the message still goes through the interfaceeno0. @attdona I am aware of that. Thank you. I have tried ipconfig ip of the interface and set it to it, but the message keeps going on the wrong interface. Probably I am missing some important step. - Urban Avsec