network interface stats
Hello,
I'm currently in the process of porting some code to solaris, I'm looking for a way to get interface stats from user space.
I have found the structure ifnet in "/usr/include/net/if.h", but what call returns a ifnet struct? I've STFW but I cannot find something that works in userspace.
[314 byte] By [
ed_] at [2007-11-26 9:51:57]

# 1
if you want stats like input pkts drops etc, then you could use the kstat interface
man -s3KSTAT kstat
you can see the fields available using the kstat command thus
netstat -c net
you'll get lots of tcp and ip stats but you should also get a segment for your nic
module: iprbinstance: 0
name:iprb0class:net
align_errors0
blocked 0
brdcstrcv89385
brdcstxmt1041
carrier_errors0
collisions 0
crtime 315.208032312
defer_xmts 0
duplex full
ex_collisions0
fcs_errors 0
first_collisions0
ierrors 0
ifspeed 100000000
intr311789
ipackets311943
ipackets64 311943
macrcv_errors0
macxmt_errors0
mediaPHY/MII
missed 0
multi_collisions0
multircv0
multixmt7
norcvbuf0
noxmtbuf0
obytes 22133426
obytes6422133426
oerrors 2
oflo0
opackets196280
opackets64 196280
promisc off
rbytes 141462834
rbytes64141462834
...
# 3
if you just want the interface configurations
then you can use the if_nameindex() routine to get a list of nic names.
then you can use the ioctls from man -s7p if to get the
config info for each interface in turn.
I can see no easy way to get the kernel ifnet list into userland
without using kvm_read to walk the kernel memory and pull a copy into
a userland buffer.
a search of the opensolaris source for ifnet shows several thing that
do exactly that....
http://cvs.opensolaris.org/source/search?q=ifnet&defs=&refs=&path=& #38;hist=
tim