Source
/*
** 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/>.
**/
static void reverse_digits(short unsigned int a, char s2[8])
{
char s[8];
zbx_snprintf(s, 8, "%04x", a);
for (int i = 0; i <= 3; i++)
{
(s2)[i * 2] = s[3 - i];
(s2)[i * 2 + 1] = '.';
}
}
/******************************************************************************
* *
* Purpose: Creates a new IP, from the provided one, that is suitabe for the *
* reverse DNS lookup (PTR record type). IP needs to be reversed and *
* supplied in the special format for such queries. If the IP *
* already is in the acceptable format - this will be detected, and *
* new IP copy will not be changed, the returned IP will be *
* identical to the supplied one. Otherwise, this functions attempts *
* to reverse and format it. *
* *
* Parameters: *
* src_ip - [IN] *
* dst_ip - [OUT] newly allocated string IP that is suitable to be *
* supplied to reverse DNS lookup *
* error - [OUT] *
* *
* Return value: SUCCEED or FAIL *
* *
* Comments: allocates memory *
* *
******************************************************************************/
int zbx_ip_reverse(const char *src_ip, char **dst_ip, char **error)
{
if (NULL != strstr(src_ip, ".ip6.arpa") || NULL != strstr(src_ip, ".in-addr.arpa"))
{
*dst_ip = zbx_strdup(*dst_ip, src_ip);
return SUCCEED;
}
if (SUCCEED == zbx_is_ip6(src_ip))