0
votes

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.

1
192.0.2.* is a range reserved for examples and documentation. You shouldn't, and might not be able, to use it. - mcarton
0.0.0.0 is an unspecified address, so bind may not happen on the network interface where the targeted device is attached. Try to bind with the ip assigned at eno1 interface. - attdona
@mcarton I have tried to change the ip to the outside of the documentation range to 55.55.0.2 and bind to it. Saddly the message still goes through the interface eno0 . @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
@UrbanAvsec this IP doesn't belong to any reserved ranged, which means it's available for use on the internet, and it's probably already routed on the other interface. You can't just use any range. - mcarton

1 Answers

0
votes

I have started a DHCP server and I am communication over the IP that is given through DHCP. I have no idea why LLA assigned IP doesn't work when DHCP does, but it works for now.