Saravana
Saravana

Reputation: 31

Sending packets on a defined Ethernet Interface

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

Answers (2)

caf
caf

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

bjrnt
bjrnt

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

Related Questions