Source
if (SYSINFO_RET_OK != get_ifdata(if_name, &ibytes, &ipackets, &ierrors, &idropped, NULL, NULL, NULL, NULL, NULL,
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/* if OpenBSD 5.5 or newer */
/* if Openbsd 5.8 or newer */
/* Workaround: include malloc.h here without _KERNEL to prevent its */
/* inclusion later from if_var.h to avoid malloc() and free() redefinition. */
/* define _KERNEL to enable 'ifnet' and 'ifnet_head' definitions in if_var.h */
/* structs ifnet and ifnet_head are defined in this header since OpenBSD 5.5 */
static struct nlist kernel_symbols[] =
{
{"_ifnet", N_UNDF, 0, 0, 0},
{"_tcbtable", N_UNDF, 0, 0, 0},
{NULL, 0, 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)
{
struct ifnet_head head;
struct ifnet *ifp;
kvm_t *kp;
int len = 0, ret = SYSINFO_RET_FAIL;
if (NULL == if_name || '\0' == *if_name)
{
*error = zbx_strdup(NULL, "Network interface name cannot be empty.");
return SYSINFO_RET_FAIL;
}
/* if(i)_ibytes; total number of octets received */
/* if(i)_ipackets; packets received on interface */
/* if(i)_ierrors; input errors on interface */
/* if(i)_iqdrops; dropped on input, this interface */
/* if(i)_obytes; total number of octets sent */