gabriel rosenkoetter on Tue, 24 Dec 2002 13:30:35 -0500


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] proc filesystem


On Mon, Dec 23, 2002 at 11:57:26PM -0500, Naresh wrote:
> How can I obtain my ipaddress from the proc filesystem. I was thinking of
> doing it like that:
> 
> cat /proc/net/arp | awk '{print $1}'
> 
> which works on my computer, but not on most.

And well it shouldn't; that's the arp (address routing protocol)
table, which is an IP address to MAC address mapping. It may include
an IP address your computer is using right now, but it'll also
include the IP address of every other system on your local ethernet
segment from whom your system's seen traffic.

I don't see a good way to get this information out of Linux's /proc
file system... and even if you could, it'd be far from portable.
The canonical way to grab this for a shell script is to parse the
output of ifconfig(8) or netstat(8). Not that that's much more
portable.

Part of the problem here is that you're assuming that a given system
has a one-to-one mapping with an IP address. That's far from true.

What's the underlying problem you're trying to solve here? What
address you've received from DHCP? Your DHCP client is the best
place to grab that information (it's got it as a separate, unique
token marked as being exactly what it is), from which you can write
it out to a file.

-- 
gabriel rosenkoetter
gr@eclipsed.net

Attachment: pgpUhrVAur2t6.pgp
Description: PGP signature