Re: Connect to two network interfaces simultaneously?
Re: Connect to two network interfaces simultaneously?
- Subject: Re: Connect to two network interfaces simultaneously?
- From: Daniel Stødle <email@hidden>
- Date: Tue, 26 Sep 2006 12:05:18 +0200
Hi Roland,
I have both en0 (wired) and en1 (wireless) network interfaces active
on a MacBook, but I don't know how to specify one connect() call to
go through en0, and another to go through en1. Programmatically, how
does one "connect" to or use a specific network interface?
You can select the interface used when the socket is connected by
first binding the socket to the IP address of the interface you want
to use, and then connecting it. Something like the following (code
written in Mail, so no guarantees that it'll compile):
int s;
struct sockaddr_in addr;
s = socket(AF_INET, SOCK_STREAM, 0)
addr.sin_family = AF_INET;
// We don't care about the port number
addr.sin_port = 0;
// Replace the address with IP of the interface you want
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
memset(&(addr.sin_zero), 0, 8);
bind(s, (struct sockaddr*)&addr, sizeof(struct sockaddr))
// The socket is bound to the interface with IP as given
// above. Now all we need to do is to connect the socket.
connect(s, ...)
Hope this helps :)
Best Regards,
Daniel Stødle
Check out FolderGlance:
<http://home.online.no/~stoedle/YLS/YLS-products/FolderGlance.html>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden