Click to See Complete Forum and Search --> : Simplest way to get local machine Ip Address (not 0x7f000001)


delphieng
November 7th, 2003, 01:29 PM
title says it all, what's the absolutely simplest and cleanest way of getting the IP address of the local machine. as it appears in IPCONFIG. I know a lot of ways, but they are all rather... untidy.

thanks a bunch.

Lee Peart
November 7th, 2003, 06:15 PM
This might be what you're after...


struct hostent *hostinfo;
char name[255];
char *SvrAddr;

if (gethostname (name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
SvrAddr = strdup (inet_ntoa (*(struct in_addr *)*hostinfo->h_addr_list));
}
else
{
// gethostbyname failed
}
}
else
{
// gethostname failed
}

delphieng
November 10th, 2003, 01:32 PM
thanks mate, i wasn't sure if this was the simplest way to do it... so i take it there's no simpler way than that?