if (SYSINFO_RET_OK != get_ifdata(if_name, &ibytes, &ipackets, &ierrors, &idropped, NULL, NULL, NULL, NULL, NULL,
static struct nlist kernel_symbols[] =
{"_ifnet", N_UNDF, 0, 0, 0},
{"_tcbtable", N_UNDF, 0, 0, 0},
static int get_ifdata(const char *if_name,
zbx_uint64_t *ibytes, zbx_uint64_t *ipackets, zbx_uint64_t *ierrors, zbx_uint64_t *idropped,
zbx_uint64_t *obytes, zbx_uint64_t *opackets, zbx_uint64_t *oerrors,
zbx_uint64_t *tbytes, zbx_uint64_t *tpackets, zbx_uint64_t *terrors,
zbx_uint64_t *icollisions, char **error)
int ret = SYSINFO_RET_FAIL;
if (NULL == if_name || '\0' == *if_name)
*error = zbx_strdup(NULL, "Network interface name cannot be empty.");
if (NULL == (kp = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)))
*error = zbx_strdup(NULL, "Cannot obtain a descriptor to access kernel virtual memory.");
if (N_UNDF == kernel_symbols[IFNET_ID].n_type)
if (0 != kvm_nlist(kp, &kernel_symbols[0]))
kernel_symbols[IFNET_ID].n_type = N_UNDF;
if (N_UNDF != kernel_symbols[IFNET_ID].n_type)
int len = sizeof(struct ifnet_head);
if (kvm_read(kp, kernel_symbols[IFNET_ID].n_value, &head, len) >= len)
len = sizeof(struct ifnet);