Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to find the primary network interface?




On Oct 12, 2006, at 3:37 PM, Allan Nathanson wrote:


On Oct 12, 2006, at 7:27 AM, Stephane wrote:

In Mac OS X, there can be multiple network interface enabled and running at the same time. For instance, you can be connected to the Internet though the Ethernet Port and sharing the connection with other computers on AirPort. But AFAIK, there is only one interface that is used to send packets to the outside using applications such as Safari, Mail, iChat, ftp, etc...

I would like to know what this interface is.

I had a look at the SystemConfiguration frameworks API and while I saw some yummy features, I didn't seem to find any API to do this.

A look at the Networking sample code list didn't show anything either.

So is there a way with the system configuration framework to get this information without having to use some "tricky" stuff such as creating a socket to find which default network interface is going to be used? Could it be something like enumerating all the network configurations and finding the first one with an enabled IP address?

How about something like :

CFStringRef
getPrimaryAddress(void)
{
	[...] Nice code [...]

	return address;
}

It looks really good, I will test it extensively. Actually, I was focusing on the SCNetworkConfiguration.h header.


BTW, it would be very cool to be able to get a SCNetworkInterfaceRef from a BSDName (i.e. the opposite of SCNetworkInterfaceGetBSDName). This can be done apparently easily with the available APIs but a shortcut would be great.

Thanks for the sample code.


_______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden
References: 
 >How to find the primary network interface? (From: Stephane <email@hidden>)
 >Re: How to find the primary network interface? (From: Allan Nathanson <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.