Avoid some deprecated networking functions

rpminspect trips up on some old networking functions in libgtop, which
are mentioned as deprecated in the Linux man pages.

inet_ntoa() only works on IPv4 addresses, whereas the newer inet_ntop()
works on both IPv4 and IPv6 addresses, so use inet_ntop() instead.
Similarly, use getaddrinfo() rather than gethostbyname(), and avoid
inet_addr() entirely.

https://bugzilla.redhat.com/show_bug.cgi?id=2050712
This commit is contained in:
David King
2022-06-06 17:30:40 +01:00
committed by Robert Roth
parent 66721198b6
commit 5e97014fea
3 changed files with 27 additions and 19 deletions

View File

@@ -202,16 +202,20 @@ connect_to_unix_server (void)
long
glibtop_internet_addr (const char *host)
{
struct hostent *hp; /* pointer to host info for remote host */
/* specify IPv4 and TCP */
struct addrinfo hints = { AF_INET, SOCK_STREAM, };
struct addrinfo *result;/* pointer to host info for remote host */
IN_ADDR numeric_addr; /* host address */
numeric_addr = inet_addr (host);
if (!NUMERIC_ADDR_ERROR)
if (getaddrinfo (NULL, host, &hints, &result) == 0) {
/* Take only the first address. */
struct sockaddr_in *res = (struct sockaddr_in *)result->ai_addr;
numeric_addr = res->sin_addr.s_addr;
freeaddrinfo (result);
return numeric_addr;
else if ((hp = gethostbyname (host)) != NULL)
return ((struct in_addr *) (hp->h_addr))->s_addr;
}
else {
glibtop_warn_io ("gethostbyname (%s)", host);
glibtop_warn_io ("getaddrinfo (%s)", host);
return -1;
}