I have multiple network adapters, and need to be able to specify which adapter my socket uses for outbound connections, so that I can have one or more sockets bound to each network. I`ve looked at the other answers to this questions but can't seem to make it work.
Binding the socket to the
IP address of the adapter I want to connect via does not work.
SO_BINDTODEVICE does not appear to work either, have tried passing either the adapter name, or the adapter index, the call succeeds but the socket can't connect. I can't find a complete example that uses
SO_BINDTODEVICE to clarify the correct usage.
The symptoms using the above methods are that the connection is received by the server, but the
connect() fails on the client with error code 2 (?). I read that ip route is needed to ensure that reply packets are sent via the same adapter they were received, but can not seem to get the ip route commands right.
The tables Teth0 and Twlan0 have been added. For eth0, the IP address is 192.168.1.23, the gateway is 192.168.1.1 For wlan0, the IP address is 192.168.2.100, the gateway is 192.168.2.1 ip route add 192.168.1.1/32 dev eth0 src 192.168.1.23 table Teth0 ip route add default via 192.168.1.1 table Teth0 ip rule add from 192.168.1.23 table Teth0 ip route add 192.168.2.1/32 dev wlan0 src 192.168.2.100 table Twlan0 ip route add default via 192.168.2.1 table Twlan0 ip rule add from 192.168.2.100 table Twlan0
ip route flush cache
m usingOpen Embedded Linux 2.6.36 on a GumStix Overo (Omap3)`.
Any tips would be greatly appreciated as I`m going nuts here ;)