K_T
K_T

Reputation: 591

Possible to get the hostname of an IP using SystemConfiguration?

I'm using the SystemConfiguration framework to get the current IP from the dynamic store in my app.

Is it possible to get the hostname from the dynamic store as well? The current IP could be local, so I'm trying to get the returned value to be something like "mymac.local" or "2adg3.dsl.lgtpmi.sbcglobal.net", depending on how I'm connected to the net.

I tried SCDynamicStoreCopyLocalHostName(NULL), but it only returns the computer name itself (and not with the .local part), even if the IP resolves to a hostname that's accessible to everyone on the internet.

Upvotes: 1

Views: 1767

Answers (1)

Thomas Zoechling
Thomas Zoechling

Reputation: 34263

You could try

[[NSHost currentHost] names]

I just tried it and it returns all local hostnames of my machine.

Update:
This is a good blog post that fixes some NSHost issues:
http://cocoawithlove.com/2009/11/drop-in-fix-for-problems-with-nshost.html

Upvotes: 3

Related Questions