Reputation: 31
I have 2 Ethernet interfaces configured in my Linux Machine. Lets say Interface A and Interface B.
I am writing a tcp client socket program and need to send the packets on the defined interface.
For example.
./client -intf interface A/B
if it the input is interface A, then the client has to send packets only via interface A and vice versa.
Could anyone provides some hint on how to implement this?.
Thanks in advance!!!
Upvotes: 3
Views: 3213
Reputation: 239011
You can use bind()
before you call connect()
to bind your client socket to a particular IP address. You can use getifaddrs()
to list the interfaces and their associated IP addresses.
Upvotes: 6
Reputation: 2822
Had to do something similar before, have you tried this? https://austinmarton.wordpress.com/2011/09/14/sending-raw-ethernet-packets-from-a-specific-interface-in-c-on-linux/
Upvotes: 0