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: Which network interface is being used??? (CFNetwork question)




On Mar 12, 2006, at 14:23 , John Turnipseed wrote:

Maybe I'm missing something obvious... or I'm trying to do the impossible... (neither would be a first for me unfortunately ;^)

Not entirely obvious; you have to understand how routing works, for IP, both inside the kernel and across the network.


Is there an easy way... or I guess even a hard way if necessary... to determine which network interface a connection is using?

You can tell, given a destination address, what the kernel will choose as the next-hop router, and by inference, which interface it will use to send the packet.


Getting this info is a bit, um, involved. Your best source is Stevens's website (<http://www.kohala.com/>). Look for the source tarball for his "Unix Network Programming", V1, 2nd Ed. It's a book worth the investment if you're doing a bunch of this kind of programming. There is a 3rd ed., written by others, that should also be worth the bucks.

The scenario is a hierarchy of interfaces are defined in system preferences Ethernet, then AIrport, then one or more modem dial-up configurations. I need to know which one is being used to connect to a specified host.

I'd hoped that the SCNetworkReachability APIs might help, but it only appears to tell if a destination is reachable and if it would require some type of connection.

This API is a hold-over from Mac OS 9, and is useful only if you are in a fairly simple environment, where you have a dialup connection that you want to use only sparingly. It's not a general-purpose "can I get from here to there" indicator.


My application already makes periodic network calls using CFNetwork. Is it possible to determine which interface a CFReadStream is using? And if so, can that result then be resolved back to the user visible name from System Preferences... especially if the interface used is a dial-up connection.

You will need to open a "raw" AF_ROUTE socket, with which you can query the state of the kernel's routing table. Stevens has a chunk of code (route/getrt.c) that does essentially what you want.


Regards,

Justin

--
Justin C. Walker, Curmudgeon-At-Large
Institute for the Absorption of Federal Funds
--------
Men are from Earth.
Women are from Earth.
   Deal with it.
--------



_______________________________________________
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: 
 >Which network interface is being used??? (CFNetwork question) (From: John Turnipseed <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.