On Thu, Aug 26, 2010 at 05:18:10PM -0800, Christopher Howard wrote:
> I was looking at an old (2003) embedded Red Hat system the other day.
> There was no "ifconfig" on the system (or "arp", for that matter). There
> was an "ifcfg" program, but it could only change settings, not display
> them. I tried looking through /proc/net directory, but I couldn't seem
> to find the standard network configuration info (or didn't know how to
> interpret it...)
There are several options for interfaces:
netstat -i
cat /proc/net/if_inet6
cat /proc/net/if_inet4 # not sure of this one, it isn't on my system
cat /proc/net/dev
cat /proc/net/arp
You could also derive interfaces from the routing table:
netstat -r
cat /proc/net/route
It depends on what you want; MAC address may be difficult to determine
without ifconfig. You can write a quick C program, provided you have a
compiler; the ioctls are:
SIOCGIFNAME 0x8910 interface name
SIOCGIFFLAGS 0x8913 flags (UP, DOWN, BROADCAST, RUNNING, MULTICAST, etc.)
SIOCGIFHWADDR 0x8927 MAC address
SIOCGIFMETRIC 0x891d metric
SIOCGIFMTU 0x8921 MTU
SIOCGIFMAP 0x8970 hardware info (IRQ, address, DMA, etc.)
SIOCGIFTXQLEN 0x8942 transmit queue length
SIOCGIFADDR 0x8915 address
SIOCGIFDSTADDR 0x8917 endpoint address for point-to-point links
SIOCGIFBRDADDR 0x8919 broadcast address
SIOCGIFNETMASK 0x891b netmask
The number is the constant's value on my system; it should be the same
on yours, but if you can, double-check in /usr/include/bits/ioctls.h
echo -e "#include <bits/ioctls.h>\nSIOCGIFNAME" | cpp
If you don't have a compiler, you can do it via Perl:
perl -MSocket -wle '
my $proto = getprotobyname("ip");
socket(SOCK, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!";
foreach my $if (@ARGV) {
my $buf = pack "Z16", $if;
ioctl(SOCK, 0x8927, $buf) || die "ioctl $if: $!";
my($name, @address) = unpack "Z16 x2 C6", $buf;
print "$name: ", join ":", map { sprintf "%02x", $_ } @address;
}
' eth0 lo
This will display the MAC addresses of each interface given as argument.
I'm playing fast and loose with constants and data structure unpacking,
so I wouldn't recommend this for anything but a quick (temporary) hack.
You can also step through all interfaces with SIOCGIFCONF, but messing
with pointers in Perl is painful.
-- Michael Fowler www.shoebox.net --------- To unsubscribe, send email to <aklug-request@aklug.org> with 'unsubscribe' in the message body.Received on Thu Aug 26 13:25:47 2010
This archive was generated by hypermail 2.1.8 : Thu Aug 26 2010 - 13:25:47 AKDT