• 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
Correct way to determine machine's IP address in Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Correct way to determine machine's IP address in Cocoa


  • Subject: Correct way to determine machine's IP address in Cocoa
  • From: Jamie Curmi <email@hidden>
  • Date: Sun, 21 Apr 2002 15:38:46 +1000

Hi All,

Does anyone know what the best/correct way to determine the IP address of a given machine is?

I've tried a number of things with different amounts of success:

1) NSHost
Doing something like:
[[NSHost currentHost] address]

Seems to work sometimes, but sometimes it just returns 127.0.0.1

2) Using the BSD command:

/sbin/ifconfig -a

And calling out to it from C code, for example:

/sbin/ifconfig -a | grep broadcast | awk '/inet/{ print $2 }'

Also doesn't always work, and if the user didn't install the BSD subsystem when they installed OSX it definitely doesn't work.

3) An Apple employee hinted at something to do with the SystemConfiguration framework and using the DynamicStore API's. I've tried to find out about this framework, but I can find much documentation, and what little I did find was not really helpful for doing what I want to do.

So I'm wondering, does anyone out there have some idea how to do this?

Any help would be appreciated.

Thanks.

Jamie
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Correct way to determine machine's IP address in Cocoa
      • From: Malte Tancred <email@hidden>
    • Re: Correct way to determine machine's IP address in Cocoa
      • From: Chris Hanson <email@hidden>
    • Re: Correct way to determine machine's IP address in Cocoa
      • From: Jens Bauer <email@hidden>
  • Prev by Date: Using NSSocketPort
  • Next by Date: question about Compiler Directives
  • Previous by thread: Setting divider position of NSSplitView?
  • Next by thread: Re: Correct way to determine machine's IP address in Cocoa
  • Index(es):
    • Date
    • Thread