networking - Specify source IP address for TCP socket when using Linux network device aliases -
For some specific networking tests, I have created a VLAN tool, eth1.900, and some nicknames, eth1.
900: 1 and at 1.900.2.
eth1.900 Link Anep: Ethernet HDWder 00: 18: E7: 17: 2F: 13 Inset Adrer: 1.0.1.120 Back: 1.0.1.255 Mask: 255.255.255.0 Eth1.900: 1 Link Encaps: Ethernet HDW 00: 18: E7: 17: 2F: 13 Inset adrer: 1.0.1.200 Back: 1.0.1.255 Mask: 255.255.255.0 eth1.900: 2 Link Enepap: Ethernet HWAD 00:18: E7: 17: 2F: 13 Inset Adrer: 1.0.1.201 Best: 1.0.1.255 Mask: 255.255.255.0
When connecting to a server, is there a way to specify which of these aliases will be used? I-Eye & lt; Ip & gt; Which address is the option to use the nickname, but I do not know how it can do with the TCP socket in the code without using raw sockets, because I would like to run without additional socket privileges, that is, if possible If not, then the route is not running Unfortunately, even with root, SO_BINDTODEVICE does not work because the name of the device is not recognized:
from printf ("% s \ n" Bind T, devname); If (Satochopet (S, SOL_COCK, SOBIDTODAVCE, (Four *) Deenam, Size (DNAN))! = 0) {Pyr ("SO_BINDTODEVICE"); Return 1; }
Use getifaddrs () to point to all the interfaces and find the IP address for the interface, which you want to bind. Then use the bind () on that IP address before calling ().
Comments
Post a Comment