Call inet_sockaddr2str() instead of inet_ntop(3)
To simplify. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
parent
bb3a89577c
commit
609c641323
@ -52,7 +52,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/param.h>
|
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h> /* for inet_ntoa() */
|
#include <arpa/inet.h> /* for inet_ntoa() */
|
||||||
|
|
||||||
@ -69,7 +68,6 @@
|
|||||||
/* Delimiters for fields and for lists of users, ttys or hosts. */
|
/* Delimiters for fields and for lists of users, ttys or hosts. */
|
||||||
static char fs[] = ":"; /* field separator */
|
static char fs[] = ":"; /* field separator */
|
||||||
static char sep[] = ", \t"; /* list-element separator */
|
static char sep[] = ", \t"; /* list-element separator */
|
||||||
static char inet_ntop_buffer[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)];
|
|
||||||
|
|
||||||
static bool list_match (char *list, const char *item, bool (*match_fn) (const char *, const char *));
|
static bool list_match (char *list, const char *item, bool (*match_fn) (const char *, const char *));
|
||||||
static bool user_match (const char *tok, const char *string);
|
static bool user_match (const char *tok, const char *string);
|
||||||
@ -265,41 +263,25 @@ static bool user_match (const char *tok, const char *string)
|
|||||||
|
|
||||||
static const char *resolve_hostname (const char *string)
|
static const char *resolve_hostname (const char *string)
|
||||||
{
|
{
|
||||||
int gai;
|
int gai_err;
|
||||||
char *p;
|
char *addr_str;
|
||||||
struct addrinfo *addrs;
|
struct addrinfo *addrs;
|
||||||
struct sockaddr *sa;
|
|
||||||
struct sockaddr_in *sin;
|
|
||||||
struct sockaddr_in6 *sin6;
|
|
||||||
|
|
||||||
gai = getaddrinfo(string, NULL, NULL, &addrs);
|
gai_err = getaddrinfo(string, NULL, NULL, &addrs);
|
||||||
if (gai != 0)
|
if (gai_err != 0)
|
||||||
goto notfound;
|
goto notfound;
|
||||||
|
|
||||||
sa = addrs[0].ai_addr;
|
addr_str = inet_sockaddr2str(addrs[0].ai_addr);
|
||||||
switch (sa->sa_family) {
|
if (addr_str == NULL) {
|
||||||
case AF_INET:
|
SYSLOG ((LOG_ERR, "inet_sockaddr2str(): %s", strerror(errno)));
|
||||||
sin = (struct sockaddr_in *) sa;
|
|
||||||
inet_ntop(AF_INET, &sin->sin_addr,
|
|
||||||
inet_ntop_buffer, NITEMS(inet_ntop_buffer));
|
|
||||||
p = inet_ntop_buffer;
|
|
||||||
break;
|
|
||||||
case AF_INET6:
|
|
||||||
sin6 = (struct sockaddr_in6 *) sa;
|
|
||||||
inet_ntop(AF_INET6, &sin6->sin6_addr,
|
|
||||||
inet_ntop_buffer, NITEMS(inet_ntop_buffer));
|
|
||||||
p = inet_ntop_buffer;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SYSLOG ((LOG_ERR, "Hypothetical future IPv7?"));
|
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(addrs);
|
freeaddrinfo(addrs);
|
||||||
return p;
|
return addr_str;
|
||||||
|
|
||||||
notfound:
|
notfound:
|
||||||
SYSLOG ((LOG_ERR, "getaddrinfo(%s): %s", string, gai_strerror(gai)));
|
SYSLOG ((LOG_ERR, "getaddrinfo(%s): %s", string, gai_strerror(gai_err)));
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user