Source
xxxxxxxxxx
SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
/*
** 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 char buf_ctl[1024];
/* Low Level Discovery needs a way to get the list of network interfaces available */
/* on the monitored system. HP-UX versions starting from 11.31 have if_nameindex() */
/* available in libc, older versions have it in libipv6 which we do not want to */
/* depend on. So for older versions we use different code to get that list. */
/* More information: */
/* h20000.www2.hp.com/bc/docs/support/SupportManual/c02258083/c02258083.pdf */
static struct strbuf ctlbuf =
{
sizeof(buf_ctl),
0,
buf_ctl
};
static void add_if_name(char **if_list, size_t *if_list_alloc, size_t *if_list_offset, const char *name)
{
if (FAIL == zbx_str_in_list(*if_list, name, ZBX_IF_SEP))
{
if ('\0' != **if_list)
zbx_chrcpy_alloc(if_list, if_list_alloc, if_list_offset, ZBX_IF_SEP);
zbx_strcpy_alloc(if_list, if_list_alloc, if_list_offset, name);
}
}
static int get_if_names(char **if_list, size_t *if_list_alloc, size_t *if_list_offset)
{
int s, ifreq_size, numifs, i, family = AF_INET;
struct sockaddr *from;
u_char *buffer = NULL;
struct ifconf ifc;
struct ifreq *ifr;
struct if_laddrconf lifc;
struct if_laddrreq *lifr;
if (-1 == (s = socket(family, SOCK_DGRAM, 0)))
return FAIL;
ifc.ifc_buf = 0;
ifc.ifc_len = 0;
if (0 == ioctl(s, SIOCGIFCONF, (caddr_t)&ifc) && 0 != ifc.ifc_len)
ifreq_size = 2 * ifc.ifc_len;
else
ifreq_size = 2 * 512;
buffer = zbx_malloc(buffer, ifreq_size);
memset(buffer, 0, ifreq_size);
ifc.ifc_buf = (caddr_t)buffer;
ifc.ifc_len = ifreq_size;
if (-1 == ioctl(s, SIOCGIFCONF, &ifc))
goto next;
/* check all IPv4 interfaces */
ifr = (struct ifreq *)ifc.ifc_req;
while ((u_char *)ifr < (u_char *)(buffer + ifc.ifc_len))
{