diff --git a/usr.bin/systat/netcmds.c b/usr.bin/systat/netcmds.c --- a/usr.bin/systat/netcmds.c +++ b/usr.bin/systat/netcmds.c @@ -122,8 +122,9 @@ { char *cp, *tmpstr, *tmpstr1; struct servent *sp; - struct hostent *hp; + struct addrinfo hints, *res; struct in_addr in; + int status; tmpstr = tmpstr1 = strdup(args); cp = strchr(tmpstr1, '\n'); @@ -145,15 +146,21 @@ selectport(sp->s_port, onoff); continue; } - hp = gethostbyname(tmpstr1); - if (hp == NULL) { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = 0; + status = getaddrinfo(tmpstr1, NULL, &hints, &res); + if (status != 0) { in.s_addr = inet_addr(tmpstr1); if (in.s_addr == INADDR_NONE) { error("%s: unknown host or port", tmpstr1); continue; } - } else - in = *(struct in_addr *)hp->h_addr; + } + else { + in = ((struct sockaddr_in *)res->ai_addr)->sin_addr; + freeaddrinfo(res); + } selecthost(&in, onoff); } free(tmpstr); @@ -292,13 +299,18 @@ static void showhosts(void) { + struct sockaddr_in sa; struct hitem *p; - struct hostent *hp; + char host[NI_MAXHOST]; + int status; for (p = hosts; p < hosts+nhosts; p++) { - hp = gethostbyaddr((char *)&p->addr, sizeof (p->addr), AF_INET); + sa.sin_family = AF_INET; + sa.sin_addr = p->addr; + sa.sin_port = 0; + status = getnameinfo((struct sockaddr *)&sa, sa.sin_len, host, sizeof(host), NULL, 0, NI_NAMEREQD); if (!p->onoff) addch('!'); - printw("%s ", hp ? hp->h_name : (char *)inet_ntoa(p->addr)); + printw("%s ", status ? (char *)inet_ntoa(p->addr) : host); } } diff --git a/usr.bin/systat/netstat.c b/usr.bin/systat/netstat.c --- a/usr.bin/systat/netstat.c +++ b/usr.bin/systat/netstat.c @@ -566,8 +566,9 @@ { char *cp = 0; static char line[NI_MAXHOST]; - struct hostent *hp; + char host[NI_MAXHOST]; struct in_addr in; + int status; #ifdef INET6 if (sa->sa_family == AF_INET6) { @@ -583,9 +584,9 @@ in = ((struct sockaddr_in *)sa)->sin_addr; if (!nflag && in.s_addr != INADDR_ANY) { - hp = gethostbyaddr((char *)&in, sizeof (in), AF_INET); - if (hp) - cp = hp->h_name; + status = getnameinfo(sa, sa->sa_len, host, sizeof(host), NULL, 0, NI_NAMEREQD); + if (status == 0) + cp = host; } if (in.s_addr == INADDR_ANY) strcpy(line, "*");