Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F165173355
D45723.id140649.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D45723.id140649.diff
View Options
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 *res;
struct in_addr in;
+ int result;
tmpstr = tmpstr1 = strdup(args);
cp = strchr(tmpstr1, '\n');
@@ -145,15 +146,20 @@
selectport(sp->s_port, onoff);
continue;
}
- hp = gethostbyname(tmpstr1);
- if (hp == NULL) {
+ result = getaddrinfo(tmpstr1, NULL, &(struct addrinfo){
+ .ai_family = AF_INET
+ }, &res);
+ if (result != 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 +298,19 @@
static void
showhosts(void)
{
+ struct sockaddr_in sa;
struct hitem *p;
- struct hostent *hp;
+ char host[NI_MAXHOST];
+ int result;
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;
+ result = 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 ", result ? (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,8 @@
{
char *cp = 0;
static char line[NI_MAXHOST];
- struct hostent *hp;
struct in_addr in;
+ int result;
#ifdef INET6
if (sa->sa_family == AF_INET6) {
@@ -583,9 +583,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;
+ result = getnameinfo(sa, sa->sa_len, line, sizeof(line), NULL, 0, NI_NAMEREQD);
+ if (result == 0)
+ cp = line;
}
if (in.s_addr == INADDR_ANY)
strcpy(line, "*");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Aug 7, 1:41 PM (9 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36176979
Default Alt Text
D45723.id140649.diff (2 KB)
Attached To
Mode
D45723: systat: remove gethostby*() calls
Attached
Detach File
Event Timeline
Log In to Comment