| 1 |
#include <sys/socket.h> |
| 2 |
#include <sys/types.h> |
| 3 |
#include <sys/ioctl.h> |
| 4 |
#include <net/if.h> |
| 5 |
#include <linux/sockios.h> |
| 6 |
#include <ifaddrs.h> |
| 7 |
|
| 8 |
/* use kernel's ethtool.h */ |
| 9 |
|
| 10 |
#ifdef HAVE_LINUX_ETHTOOL_NEEDS_U64 |
| 11 |
#include <linux/types.h> |
| 12 |
typedef __u64 u64; |
| 13 |
typedef __u32 u32; |
| 14 |
typedef __u16 u16; |
| 15 |
typedef __u8 u8; |
| 16 |
#endif |
| 17 |
#include <linux/ethtool.h> |
| 18 |
|
| 19 |
/* structure for storing the interface names in the system */ |
| 20 |
|
| 21 |
struct ifname { |
| 22 |
struct ifname *ifn_next; |
| 23 |
char name [IF_NAMESIZE]; |
| 24 |
}; |
| 25 |
|
| 26 |
struct ifname *etherstats_interface_name_list_get (struct ifname *, int *); |
| 27 |
int etherstats_interface_name_list_free (struct ifname *list_head); |
| 28 |
int etherstats_interface_ioctl_ifindex_get (int fd, const char *name); |
| 29 |
int _etherStats_ioctl_get(int fd, int which, struct ifreq *ifrq, const char* name); |
| 30 |
int interface_ioctl_etherstats_get(etherStatsTable_rowreq_ctx *rowreq_ctx, int fd, const char* name); |
| 31 |
|
| 32 |
/* for maintainability */ |
| 33 |
|
| 34 |
#define GENERIC_INCOMING_OCTETS "rx_octets" |
| 35 |
#define GENERIC_INCOMING_PACKETS "rx_packets" |
| 36 |
#define DSA_INCOMING_GOOD_OCTETS "in_good_octets" |
| 37 |
#define DSA_INCOMING_BAD_OCTETS "in_bad_octets" |
| 38 |
#define GENERIC_INCOMING_UNICAST "rx_unicast" |
| 39 |
#define DSA_INCOMING_UNICAST "in_unicast" |
| 40 |
#define GENERIC_INCOMING_BROADCAST "rx_broadcast" |
| 41 |
#define DSA_INCOMING_BROADCAST "in_broadcast" |
| 42 |
#define GENERIC_INCOMING_MULTICAST "rx_multicast" |
| 43 |
#define DSA_INCOMING_MULTICAST "in_multicast" |
| 44 |
#define DSA_INCOMING_FCS_ERROR "in_fcs_error" |
| 45 |
#define FEC_INCOMING_CRC_ERROR "rx_crc_errors" |
| 46 |
#define DSA_INCOMING_UNDERSIZE "in_undersize" |
| 47 |
#define FEC_INCOMING_UNDERSIZE "rx_undersize" |
| 48 |
#define DSA_INCOMING_OVERSIZE "in_oversize" |
| 49 |
#define FEC_INCOMING_OVERSIZE "rx_oversize" |
| 50 |
#define DSA_INCOMING_FRAGMENTS "in_fragments" |
| 51 |
#define FEC_INCOMING_FRAGMENT "rx_fragment" |
| 52 |
#define DSA_INCOMING_JABBER "in_jabber" |
| 53 |
#define FEC_INCOMING_JABBER "rx_jabber" |
| 54 |
#define BROADCOM_RECEIVE_JABBERS "rx_jabbers" |
| 55 |
#define DSA_COLLISIONS "collisions" |
| 56 |
#define FEC_OUTGOING_COLLISION "tx_collision" |
| 57 |
#define DSA_64BYTES "hist_64bytes" |
| 58 |
#define FEC_64BYTES "rx_64byte" |
| 59 |
#define DSA_65_127BYTES "hist_65_127bytes" |
| 60 |
#define FEC_65_127BYTES "rx_65to127byte" |
| 61 |
#define DSA_128_255BYTES "hist_128_255bytes" |
| 62 |
#define FEC_128_255BYTES "rx_128to255byte" |
| 63 |
#define DSA_256_511BYTES "hist_256_511bytes" |
| 64 |
#define FEC_256_511BYTES "rx_256to511byte" |
| 65 |
#define DSA_512_1023BYTES "hist_512_1023bytes" |
| 66 |
#define FEC_512_1023BYTES "rx_512to1023byte" |
| 67 |
#define DSA_1024_MAXBYTES "hist_1024_max_bytes" |
| 68 |
#define FEC_1024_2047BYTES "rx_1024to2047byte" |
| 69 |
#define FEC_GTE2048BYTES "rx_GTE2048byte" |
| 70 |
|
| 71 |
#define ETHERSTATSOCTETS(x) (!strcmp(x, DSA_INCOMING_GOOD_OCTETS) || \ |
| 72 |
!strcmp(x, DSA_INCOMING_BAD_OCTETS) || \ |
| 73 |
!strcmp(x, GENERIC_INCOMING_OCTETS)) |
| 74 |
#define ETHERSTATSPKTS(x) (!strcmp(x, DSA_INCOMING_UNICAST) || \ |
| 75 |
!strcmp(x, DSA_INCOMING_BROADCAST) || \ |
| 76 |
!strcmp(x, DSA_INCOMING_MULTICAST) || \ |
| 77 |
!strcmp(x, GENERIC_INCOMING_PACKETS)) |
| 78 |
#define ETHERSTATSBROADCASTPKTS(x) (!strcmp(x, DSA_INCOMING_BROADCAST) || \ |
| 79 |
!strcmp(x, GENERIC_INCOMING_BROADCAST)) |
| 80 |
#define ETHERSTATSMULTICASTPKTS(x) (!strcmp(x, DSA_INCOMING_MULTICAST) || \ |
| 81 |
!strcmp(x, GENERIC_INCOMING_MULTICAST)) |
| 82 |
#define ETHERSTATSCRCALIGNERRORS(x) (!strcmp(x, DSA_INCOMING_FCS_ERROR) || \ |
| 83 |
!strcmp(x, FEC_INCOMING_CRC_ERROR)) |
| 84 |
#define ETHERSTATSUNDERSIZEPKTS(x) (!strcmp(x, DSA_INCOMING_UNDERSIZE) || \ |
| 85 |
!strcmp(x, FEC_INCOMING_UNDERSIZE)) |
| 86 |
#define ETHERSTATSOVERSIZEPKTS(x) (!strcmp(x, DSA_INCOMING_OVERSIZE) || \ |
| 87 |
!strcmp(x, FEC_INCOMING_OVERSIZE)) |
| 88 |
#define ETHERSTATSFRAGMENTS(x) (!strcmp(x, DSA_INCOMING_FRAGMENTS) || \ |
| 89 |
!strcmp(x, FEC_INCOMING_FRAGMENT)) |
| 90 |
#define ETHERSTATSJABBERS(x) (!strcmp(x, BROADCOM_RECEIVE_JABBERS) || \ |
| 91 |
!strcmp(x, FEC_INCOMING_JABBER) || \ |
| 92 |
!strcmp(x, DSA_INCOMING_JABBER)) |
| 93 |
#define ETHERSTATSCOLLISIONS(x) (!strcmp(x, DSA_COLLISIONS) || \ |
| 94 |
!strcmp(x, FEC_OUTGOING_COLLISION)) |
| 95 |
#define ETHERSTATSPKTS64OCTETS(x) (!strcmp(x, DSA_64BYTES) || \ |
| 96 |
!strcmp(x, FEC_64BYTES)) |
| 97 |
#define ETHERSTATSPKTS65TO127OCTETS(x) (!strcmp(x, DSA_65_127BYTES) || \ |
| 98 |
!strcmp(x, FEC_65_127BYTES)) |
| 99 |
#define ETHERSTATSPKTS128TO255OCTETS(x) (!strcmp(x, DSA_128_255BYTES) || \ |
| 100 |
!strcmp(x, FEC_128_255BYTES)) |
| 101 |
#define ETHERSTATSPKTS256TO511OCTETS(x) (!strcmp(x, DSA_256_511BYTES) || \ |
| 102 |
!strcmp(x, FEC_256_511BYTES)) |
| 103 |
#define ETHERSTATSPKTS512TO1023OCTETS(x) (!strcmp(x, DSA_512_1023BYTES) || \ |
| 104 |
!strcmp(x, FEC_512_1023BYTES)) |
| 105 |
#define ETHERSTATSPKTS1024TO1518OCTETS(x) (!strcmp(x, DSA_1024_MAXBYTES) || \ |
| 106 |
!strcmp(x, FEC_1024_2047BYTES) || \ |
| 107 |
!strcmp(x, FEC_GTE2048BYTES)) |