Re: Is there a clean way to get my default IP address.
Re: Is there a clean way to get my default IP address.
- Subject: Re: Is there a clean way to get my default IP address.
- From: "Justin C. Walker" <email@hidden>
- Date: Mon, 5 Dec 2005 17:18:09 -0800
On Dec 5, 2005, at 13:28 , John Draper wrote:
Hi,
I'm trying to get my IP address under program control...
I cannot use the "gethostname/gethostbyname" combination
because I could have many devices. Is there a Mac Carbon
call that can give me my IP address in dotted form?
I don't think there is such a thing as a "default" IP address for a
box. You might investigate the SystemConfiguration framework. Quinn
has some source on the developer site that is called something like
'MoreSCF'; that may help. Also, see Jeff Frey's 'ncutil' command
(google is your friend); it is a command-line utility that does what
the Network Preference panel does with the SystemConfiguration database.
As for your issue here:
For some reason, my earlier implementation shown
below seems to "break" another call to it later on...
[snip]
Can someone please shed some light on this very confusing issue?
As Scott noted, inet_ntoa() doesn't allocate a buffer; it uses its
own static. I don't know that that's the issue, but it might be
worth trying to see what values are being tossed around in that
neighborhood, to make sure you have a handle on what is really
happening (for example, are you sure that the item in the hostent
that you copy to &dstAddr is really a 32-bit IPv4 address, and not,
say, a 128-bit IPv6 address?)
You may be already aware of this, but:
- gethostname() returns a string that has next to nothing to do
with the DNS name for your host (if any); if it matches one of
your addresses, you are lucky.
- gethostby*() are deprecated; you want to look at getaddrinfo(3),
or possibly getifaddrs(3).
Hope that helps.
Regards,
Justin
--
Justin C. Walker, Curmudgeon-at-Large
() The ASCII Ribbon Campaign
/\ Help Cure HTML Email
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden