LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Getting IP address for a network interface through the filesystem, not ifconfig (https://www.linuxquestions.org/questions/linux-networking-3/getting-ip-address-for-a-network-interface-through-the-filesystem-not-ifconfig-532439/)

nachosmith 02-26-2007 12:53 AM

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

win32sux 02-26-2007 01:51 AM

have you considered doing an strace to see where ifconfig gets the info??
Code:

strace ifconfig

nachosmith 02-26-2007 02:55 AM

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
Thanks for your help.


All times are GMT -5. The time now is 10:50 PM.