Source
if (SYSINFO_RET_OK != get_ifdata(if_name, &ibytes, &ipackets, &ierrors, &idropped, NULL, NULL, NULL, NULL, NULL,
/*
** Copyright (C) 2001-2024 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/>.
**/
static void get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
{
int i;
for (i = 0; i < RTAX_MAX; i++)
{
if (addrs & (1 << i))
{
rti_info[i] = sa;
sa = (struct sockaddr *)((char *)(sa) + RT_ROUNDUP(sa->sa_len));
}
else
rti_info[i] = NULL;
}
}
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)
{
static size_t olen;
static char *buf = NULL;
int ret = SYSINFO_RET_FAIL;
int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
size_t len;
char name[IFNAMSIZ + 1];
char *next, *end, *cp;
struct if_msghdr *ifm;
struct rt_msghdr *rtm;
struct if_data *ifd = NULL;
struct sockaddr *sa, *rti_info[RTAX_MAX];
struct sockaddr_dl *sdl;
if (NULL == if_name || '\0' == *if_name)
{