ok, this code gets the nics ip (in linux eth0) using the system hostname.
On linux it is important to have the network setup correctly or you will get localhost (/etc/hosts for example).
this will not work if dhcp is being used.
not all error checking has been included
Code:
struct hostent *hostinfo;
char *host,**addrs;
char myname[256];
gethostname(myname, 255);
host = myname;
hostinfo = gethostbyname(host);
if(!hostinfo)
{
fprintf(stderr, "cannot get info for host: %s\n", host);
exit(1);
}
addrs = hostinfo -> h_addr_list;
while(*addrs)
{
printf(" %s", inet_ntoa(*(struct in_addr *)*addrs));
addrs++;
}
printf("\n");