Re: (correction) how to tell a socket to use a specific interface...
Re: (correction) how to tell a socket to use a specific interface...
- Subject: Re: (correction) how to tell a socket to use a specific interface...
- From: Philip George <email@hidden>
- Date: Fri, 20 May 2005 14:39:19 -0500
i had a typo in the code i sent. correction below ('int drval = 1'
changed to 'int val = 1').
also, i didn't specify before that i'm talking about an outgoing
connection. in other words, i use send() a few lines after what is
shown here to send a web request and recv() to get the requested page.
the catch being that i need to specify that the request be routed
through a specific interface, not just any old interface (assuming that
at runtime there are 2 or more available connections from the computer
out to the internet).
CORRECTED CODE SNIPPET:
// setup local address stuff...
struct sockaddr_in LOCaddr;
LOCaddr.sin_family = AF_INET;
LOCaddr.sin_addr.s_addr = inet_addr(local_ip);
// set to true for SO_DONTROUTE...
int val = 1;
// bind to specific interface and then set SO_DONTROUTE...
if (bind(sockethandle, (struct sockaddr *)&LOCaddr,
sizeof(LOCaddr))==0) {
setsockopt(sockethandle, SOL_SOCKET, SO_DONTROUTE, &val, sizeof(val));
}
thanks again.
- philip
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden