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 - eth1 -

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

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



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("");

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

|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.