• 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: Getting own IP address
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting own IP address


  • Subject: Re: Getting own IP address
  • From: Justin Walker <email@hidden>
  • Date: Mon, 28 Apr 2003 16:20:17 -0700

On Monday, Apr 28, 2003, at 15:42 US/Pacific, Matt Slot wrote:

Yes, I know... lots of interfaces, everything is dynamic, yadda yadda.

I'm working on some code to cope with NAT limitations, and I need to
detect when the client is behind the same NAT as the computer it wants
to join (ignoring the double-NAT case).

I've written an abstraction function to return the list of currently
available interfaces/IP addresses, but I'm getting inconsistent and
strange results from the various APIs.

My home machine is configured as follows:

Default: Ethernet / DHCP - gets IP 24.95.76.171
Airport / Manual - set to 10.0.1.2

Airport Internet Sharing is on, one host connects using 10.0.1.3.


When I use ioctl(OSIOCGIFCONF) to talk to the BSD layer, I get the
following list on my home machine.

10.0.2.1
10.0.1.2
24.95.76.171
127.0.0.1

I don't know where the first address comes from, but its not listed in
my Network preferences.

I believe that Internet sharing, with Airport support checked on the Prefs panel, generates the 10.0.2/24 addresses automatically. If you want to use internet sharing, you have to let the computer handle things (don't manually assign addresses, either on the "internal" interfaces or on the systems on the internal nets). I use this configuration, and get 10.0.2/24 addresses "in the air", and 192.168.2/24 addresses on an internal wire.

I also can't figure out why the IP address for
the default interface is not at the top of the list I get.

There's a difference between what the low-level APIs give you and what the "high-level" APIs give you. The BSD stuff, like SIOCGIFCONF (why are you using the "O" version?), gives you interface information more-or-less as it comes across it while pawing through kernel data structures. You might also try looking at the NET_RT_IFLIST command in sysctl(2). W. Richard Stevens's "Unix Network Programming, V1, 2nd Ed" is an invaluable aid (if you haven't already seen it).

Under OpenTransport/CFM, I get the following list:

24.95.76.171
127.0.0.1

Upon further research, it looks like I'm only querying 1 interface, and
its secondary addresses. I'll add the code to loop over all interfaces
shortly.

I'm no expert, but can OT do that? I know that OT has an implicit "active interface" point of view, since it only supports one such, so I don't know whether there's a way to get at all active interfaces.

So, I have 2 real questions:

Where is 10.0.2.1 coming from? I assume it's related to the
Internet Sharing feature, but how?

As above, it's the subnet used, and is automatically chosen.

How do I get the IPs in the order the user sees them within
the Network preferences dialog?

I think you will have to use the SystemConfiguration APIs, and do some work to determine what the proper order is.

Hope that helps.

Regards,

Justin

--
Justin C. Walker, Curmudgeon-At-Large *
Institute for General Semantics | When LuteFisk is outlawed
| Only outlaws will have
| LuteFisk
*--------------------------------------*-------------------------------*
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Getting own IP address
      • From: "Matt Slot" <email@hidden>
    • Re: Getting own IP address
      • From: "Peter Sichel" <email@hidden>
References: 
 >Getting own IP address (From: "Matt Slot" <email@hidden>)

  • Prev by Date: Getting own IP address
  • Next by Date: Re: Getting own IP address
  • Previous by thread: Getting own IP address
  • Next by thread: Re: Getting own IP address
  • Index(es):
    • Date
    • Thread