0

Is there a way to implement in C program a next feature: it's need to making outgoing TCP connections through specified network interface? as example:

eth0 - 172.16.0.1 eth1 - 192.168.1.1

In some case I'm need to make outgoing connections from source address 172.16.0.1, and under some other circumstances from 192.168.1.1.

Is this possible ? Is this can be achieved with bind() routine?

TIA.

0

Use command line parameter to assign the local address in following way

struct sockaddr_in localaddr;

localaddr.sin_family = AF_INET;

localaddr.sin_addr.s_addr = inet_addr("172.16.0.1");

localaddr.sin_port = 0; // Any local port will do

bind(sockfd, (struct sockaddr *)&localaddr, sizeof(localaddr));

And when you want to use other IP then use it instead of 172.16.0.1

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.