Getting IP address for a network interface through the filesystem, not ifconfig
I'm using an embedded system that is running a cut-down version of linux. We're running a Java app on top of it.
I need to find the IP address for a network interface, so I can use it in my program. The only problem is I can't make a call to ifconfig to read the ip address information because on this platform, running external processes from Java is broken, unfortunately (and there's no fix in sight either). So I figure there must be a way to get this information from the filesystem, somewhere. Like from /proc or /sys or something. I've had a pretty good look but couldn't see anything. Can anyone tell me how I can get the IP address for a network interface without having to run a command (like ifconfig)??? Thanks in advance |
have you considered doing an strace to see where ifconfig gets the info??
Code:
strace ifconfig |
system call: ioctl
Thanks mate. That was a very helpful little piece of information. I found out it is done through a system call:
Code:
ioctl(4, SIOCGIFCONF, {64, {{"lo", {AF_INET, inet_addr("127.0.0.1")}}, {"eth0", {AF_INET, inet_addr("192.168.1.5")}}}}) = 0 |
All times are GMT -5. The time now is 10:50 PM. |