On Thu, 2002-08-01 at 17:00, Nicholas Kidd wrote: > This is probably not what you want but I think you can get the info you are > looking for by jumping through these hoops: > > strace ifconfig > - shows ifconfig reads the info from /proc/net > - which means that the ip address is in the kernel > > look at ifconfig source to see how it figures out the ipaddress from /proc > > then look at the procfs code in the kernel and find out how it gets the > information it displays. > I spent a couple of days this week researching this problem for my own project. Using the ifconfig source as my guide, I eventually traced the IP retrieval through an ioctl call (using cmd=SIOCGIFADDR) all the way to devinet_ioctl() in $LINUX_SOURCE/net/ipv4/devinet.c. These are the steps devinet_ioctl() uses to fetch the IP address: 1. Using the interface name (like "eth0"), fetches the "struct net_device" for the interface using dev_get_by_name(). 2. Fetches a "struct in_device" structure from net_device using in_dev_get(). 3. Searches through a linked list of "struct in_ifaddr"'s contained in in_device for one with a label matching the interface name. 4. The IP address is stored (network-byte order) in the ifa_local field of struct in_ifaddr. So far, this is the easiest and most direct method that I've found for retrieving the IP address from within the kernel. -- Trevor Hamm -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/