FreeBSD 11 not showing RX,TX packets and counts

freebsdifconfig

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 :

  1. 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).
  2. 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 from iftop 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;
}

Best Answer

To answer your question, I should say that as far as I recall, FreeBSD - and also macOS - has never displayed RX/TX Packets as an output of ifconfig command. But if you say it was available in 7.x and 8.x, I should say at least in 10 and 11 it is not, maybe I didn't notice that time for 7.x 8.x . Indeed Linux Distributions including RHEL derivatives (RHEL, Fedora, CentOS, Scientific, etc.), Debian-Based operating systems (Ubuntu, Debian Jessie, etc.) and most of other distros show RX/TX Packets via ifconfig, But FreeBSD and macOS do not so. Many of FreeBSD's commands have nothing to do with commands in Linux, many of them are just called in the same way but in fact, act differently in many cases. In the meanwhile, your struct if_data doesn't look pretty familiar - and correct - to me, I recommend you take a look at <net/if.h>. In other words, delete your if_data and try to include the accurate header.

Anyway, to display number of bytes in/out in FreeBSD, you should use netstat. The following command works fine on both FreeBSD and macOS :

netstat -idb [interface]

-i : interface
-d : show the number of dropped packets
-b : show the number of packets in and out

You can also use -B if you need so. It shows statistics about bpf() peer. This includes information like how many packets have been matched, dropped and received by he bpf device, also information about current buffer size and device stats.

By the way, for monitoring network traffic, you have another option which I highly recommend. You can use systat with the -ifstat option to get Traffic throughput, Peak and Total of your interfaces :

systat -ifstat