• 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: gethostname returns loginname on "Pather Server" version
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gethostname returns loginname on "Pather Server" version


  • Subject: Re: gethostname returns loginname on "Pather Server" version
  • From: Zack Morris <email@hidden>
  • Date: Mon, 09 Feb 2004 13:04:47 -0700

>> But, to answer your question... Using BSD calls the recommended API
>> would be getifaddrs(3) to get the addresses (yes, plural) and then
>> "pick one". If you want to step up a layer you can use the
>> SystemConfiguration.framework APIs to capture what we believe to be the
>> "primary" IP address. ... and many other APIs exist.
>
> Here is the code I use. The routines of interest are:
>
> GetHostIPAddresses();
> main();

Allen at Apple was kind enough to correct my code, here is the improved way
to get the list of ip addresses:

int GetHostIPAddresses( in_addr_t *addr )
{
ifaddrs *addrs, *orig
int total = 0;

if( getifaddrs( &orig ) == noErr )
{
addrs = orig;

while( addrs && total < kMaxGetHostIPAddresses )
{
if( (addrs->ifa_flags & IFF_UP) &&
!(addrs->ifa_flags & IFF_LOOPBACK) &&
addrs->ifa_addr->sa_family == AF_INET &&
addrs->ifa_addr != nil )
{
addr[total] = ((sockaddr_in*)
addrs->ifa_addr)->sin_addr.s_addr;
total++;
}

addrs = addrs->ifa_next;
}

freeifaddrs( orig );
}

return( total );
}

I have also updated the file on my iDisk at:

http://homepage.mac.com/zmorris

GetIPs.c

Hope this helps,

----------------------------------------------------------------------------
Zack Morris Z Sculpt Entertainment This Space
email@hidden http://www.zsculpt.com For Rent
----------------------------------------------------------------------------
If the doors of perception were cleansed, everything would appear to man as
it is, infinite. -William Blake, The Marriage of Heaven and Hell
_______________________________________________
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.

References: 
 >Re: gethostname returns loginname on "Pather Server" version (From: Zack Morris <email@hidden>)

  • Prev by Date: RE: OTMP with an Async Notifier Model
  • Next by Date: Re: URLManager progress window
  • Previous by thread: Re: gethostname returns loginname on "Pather Server" version
  • Next by thread: Re: gethostname returns loginname on "Pather Server" version
  • Index(es):
    • Date
    • Thread