Source
xxxxxxxxxx
zabbix_log(LOG_LEVEL_DEBUG, "GetIpAddrTable failed with error: %s", zbx_strerror_from_system(dwRetVal));
/*
** 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/>.
**/
/* __stdcall calling convention is used for GetIfEntry2(). In order to declare a */
/* pointer to GetIfEntry2() we have to expand NETIOPAPI_API macro manually since */
/* part of it must be together with the pointer name in the parentheses. */
typedef NETIO_STATUS (NETIOAPI_API_ *pGetIfEntry2_t)(PMIB_IF_ROW2 Row);
/* GetIfEntry2() is available since Windows Vista and Windows Server 2008. In */
/* earlier Windows releases this pointer remains set to NULL and GetIfEntry() is */
/* used directly instead. */
static pGetIfEntry2_t pGetIfEntry2 = NULL;
/* GetIfEntry2() and GetIfEntry() work with different MIB interface structures. */
/* Use zbx_ifrow_t variables and zbx_ifrow_*() functions below instead of */
/* version specific MIB interface API. */
typedef struct
{
MIB_IFROW *ifRow; /* 32-bit counters */
MIB_IF_ROW2 *ifRow2; /* 64-bit counters, supported since Windows Vista, Server 2008 */
}
zbx_ifrow_t;
/******************************************************************************
* *
* Purpose: initializes zbx_ifrow_t variable *
* *
* Parameters: *
* pIfRow - [IN/OUT] pointer to zbx_ifrow_t variable with all *
* members set to NULL *
* *
* Comments: allocates memory, calls zbx_ifrow_clean() with pointer to free *
* it *
* *
******************************************************************************/
static void zbx_ifrow_init(zbx_ifrow_t *pIfRow)
{
HMODULE module;
static char check_done = FALSE;
/* check (once) if GetIfEntry2() is available on this system */
if (FALSE == check_done)
{
if (NULL != (module = GetModuleHandle(L"iphlpapi.dll")))
{
if (NULL == (pGetIfEntry2 = (pGetIfEntry2_t)GetProcAddress(module, "GetIfEntry2")))
{
zabbix_log(LOG_LEVEL_DEBUG, "GetProcAddress failed with error: %s",
zbx_strerror_from_system(GetLastError()));
}
}
else
{
zabbix_log(LOG_LEVEL_DEBUG, "GetModuleHandle failed with error: %s",
zbx_strerror_from_system(GetLastError()));
}
check_done = TRUE;
}
/* allocate the relevant MIB interface structure */
if (NULL != pGetIfEntry2)
pIfRow->ifRow2 = zbx_malloc(pIfRow->ifRow2, sizeof(MIB_IF_ROW2));
else
pIfRow->ifRow = zbx_malloc(pIfRow->ifRow, sizeof(MIB_IFROW));
}
/******************************************************************************
* *
* Purpose: cleans zbx_ifrow_t variable *
* *
* Parameters: *