I am having a FreeBSD 11 system in which I get the following output for ifconfig
command
# ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
groups: lo
xn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=503<RXCSUM,TXCSUM,TSO4,LRO>
ether 0e:c2:a2:36:c1:b4
inet 10.0.0.71 netmask 0xffffff00 broadcast 10.0.0.255
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
media: Ethernet manual
status: active
Two doubts here :
- Why I am not getting RX, TX bytes and packet count like I get for older FreeBSD / ubuntu systems ? I am using a utility which parses this response to get network usage and it is failing (can't modify, it's a third party binary).
- Any changes in FreeBSD 11 because it worked fine in older versions ? I am more interested to fix this or do a config change (if this is being controlled by some
.conf
file) rather than changing my method of monitoring (eg. parsing response fromiftop
or some other command)
Thanks in advance !
Edit
Specifically, a C library is being used in that binary to get stats which are coming out to be zero. I am attaching a sample code which is also returning zero values for rx/tx bytes because that information is not available. It uses getifaddrs
function from sys/sockets
library
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <ifaddrs.h>
struct if_data {
unsigned char ifi_type;
unsigned char ifi_physical;
unsigned char ifi_addrlen;
unsigned char ifi_hdrlen;
unsigned char ifi_recvquota;
unsigned char ifi_xmitquota;
unsigned long ifi_mtu;
unsigned long ifi_metric;
unsigned long ifi_baudrate;
unsigned long ifi_ipackets;
unsigned long ifi_ierrors;
unsigned long ifi_opackets;
unsigned long ifi_oerrors;
unsigned long ifi_collisions;
unsigned long ifi_ibytes;
unsigned long ifi_obytes;
unsigned long ifi_imcasts;
unsigned long ifi_omcasts;
unsigned long ifi_iqdrops;
unsigned long ifi_noproto;
unsigned long ifi_recvtiming;
unsigned long ifi_xmittiming;
struct timeval ifi_lastchange;
};
int main()
{
struct ifaddrs *ifap, *ifa;
struct if_data *ifadata = NULL;
char *dev_name;
if (getifaddrs(&ifap) < 0) {
printf ("returning for null");
return 1;
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_flags & 0x01) {
if ( ifa->ifa_addr->sa_family == AF_LINK) {
if (ifa->ifa_data) {
ifadata = (struct if_data *)ifa->ifa_data;
dev_name = ifa->ifa_name;
if (ifadata->ifi_ipackets == 0 && ifadata->ifi_opackets == 0)
{
printf("returning as zero for %s", dev_name);
continue;
}
printf("name=%s ipkts=%ld opkts=%ld\n", dev_name,
ifadata->ifi_ipackets, ifadata->ifi_opackets);
printf("%lu", ifadata->ifi_ibytes);
printf("%lu", ifadata->ifi_ipackets);
printf("%lu", ifadata->ifi_ierrors);
printf("%lu", ifadata->ifi_iqdrops);
printf("%lu", ifadata->ifi_imcasts);
printf("%lu", ifadata->ifi_obytes);
printf("%lu", ifadata->ifi_opackets);
printf("%lu", ifadata->ifi_oerrors);
}
}
}
}
freeifaddrs(ifap);
return 0;
}