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: Localhost IP



On Thursday, March 28, 2002, at 10:56 AM, Julien Guimont wrote:

Hi there!

I have a little question for you all. I try to get the local IP of my
system. I came to this solution:

char name[32];
hostent* host;

gethostname(name, 32);
host = gethostbyname(name);

while(host->h_addr_list[i] != NULL) //display IPs here.

Works great but only for 127.0.0.1, not my other 192.168.0.10 IP.

Is there a way to bypass that? Find the IP and go to sleep?;)

Unless you add the name and address to the resolver database ("/machines" in netinfo, DNS, or a line in "/etc/hosts", there is no automatic connection between the string you get from gethostname(2) and any of the IP addresses assigned to network interfaces on your system. Also, just because you have an IP address does not automatically give you a DNS name.

I hope that's clear. If not, let me know.

Regards,

Justin

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

References: 
 >Localhost IP (From: "Julien Guimont" <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.