diff options
author | David King <amigadave@amigadave.com> | 2022-06-06 17:30:40 +0100 |
---|---|---|
committer | Robert Roth <robert.roth.off@gmail.com> | 2023-01-09 09:50:10 +0000 |
commit | 5e97014fea8153f42e21062f2f2f32bfcf6a29e9 (patch) | |
tree | be8681d0106f2af4ceb4c2bd977fe1f8ae2cc8f0 /sysdeps/common | |
parent | 66721198b640a241c2c666e0f628a665b4bf8c23 (diff) | |
download | libgtop-5e97014fea8153f42e21062f2f2f32bfcf6a29e9.tar.gz |
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
Diffstat (limited to 'sysdeps/common')
-rw-r--r-- | sysdeps/common/gnuslib.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/sysdeps/common/gnuslib.c b/sysdeps/common/gnuslib.c index 79295485..3f994f2c 100644 --- a/sysdeps/common/gnuslib.c +++ b/sysdeps/common/gnuslib.c @@ -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; } |