• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Connect to two network interfaces simultaneously?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Getting an NSManagedObject just added through an NSArrayController
  • Next by Date: Re: How to implement an Xcode-style hierarchical file browser
  • Previous by thread: Re: Connect to two network interfaces simultaneously?
  • Next by thread: Right-click not working to trigger menu in NSStatusItem
  • Index(es):
    • Date
    • Thread