[ale] Pulling IP address from server.
Chris Fowler
cfowler at outpostsentinel.com
Mon Jul 27 14:11:14 EDT 2009
// Open a socket to the kernel
if((skfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
{
free(tmp);
return NULL;
}
// copy the iface name into the
// interface structure
strcpy(ifr.ifr_name, i);
// Get the IP
if(ioctl(skfd,SIOCGIFADDR, &ifr) == -1)
{
close(skfd);
free(tmp);
return NULL;
}
// Convert IP to string
addr = ifr.ifr_addr;
printIP(tmp, (struct sockaddr_in *)&addr);
On Mon, 2009-07-27 at 12:29 -0400, Brandon Checketts wrote:
> Atlanta Geek wrote:
> > What is the best way to identify the server's IP address from
> > ruby/perl/python/C.
> > I found a chunk of code parsing the results of ifconfig and I'm always
> > concerned when I see this type of thing.
> >
> > Also does changing the default language of a server affect the output
> > of these commands at all.
> >
>
> Seems like it should be contained somewhere in /proc, but I'm unable to
> locate it there in a reliable way. I can see it in reverse hex in some
> of the tables, but not in anything that authoritatively lists the IP
> addresses on a machine.
>
> I looked through the output of 'strace ifconifg' to see where ifconfig
> is getting it from, and it looks like it may come from
> /proc/net/if_inet6 or /proc/net/dev or possibly /proc/net/unix.
>
> Thanks,
> Brandon Checketts
>
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list