- use iproute2 and see how one dumps netdevice stats
-  Continue by looking at iproute2/ip/
files iplink.c and ipaddress.c
and note that: stats are stored in a TLV IFLA_STATS and are printed in
print_linkinfo()
The code is not much to study if you are serious about performance.

Thomas Graf as well has been trying to make it simpler to do this kind
stuff. I havent looked at it lately but should make it simpler.

Pointers to his work below.

If you can beat the performance of that with your half-assed tool
then i will be interested in showing up. For now you are on your own on
or maybe someone else has time.

Looks about as complex as last time I looked..lots of MACROs, constants,
and powerful options that might make good sense for 'ip', but make using
it in a stand-alone application difficult.

Using Thomas' libnl library should not be such a hassle anymore. I'm actually in the process of rewriting a largish application using his library.

http://people.suug.ch/~tgr/libnl/

The example you would be needing is in his examples (src) directory:

https://svn.suug.ch/repos/tgr/libnl/src/nl-link-stats.c

Granted, it could still be simplified more (for example the error handling regarding cache and netlink handle should be one function and stuff like the link cache should be hidden from the user) but it's rather efficient and straightforward, and works:

[EMAIL PROTECTED]:../libnl-1.0-pre5/src> /sbin/ip -s -s link show dev eth0 | head -4
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:50:04:50:64:58 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    1264755    2292     0       0       0       0
               0        0       0       0
[EMAIL PROTECTED]:../libnl-1.0-pre5/src> ./nl-link-stats 2 rx_bytes
eth0.rx_bytes 1264755

I also notice that the lib/libnetlink.c file is GPL instead of LGPL,
so I can't use it in my application anyway...

https://svn.suug.ch/repos/tgr/libnl/COPYING

Best regards,
Roberto Nibali, ratz
--
echo '[q]sa[ln0=aln256%Pln256/snlbx]sb3135071790101768542287578439snlbxq' | dc
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to