Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F106284342
D45723.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.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,7 +122,7 @@
{
char *cp, *tmpstr, *tmpstr1;
struct servent *sp;
- struct hostent *hp;
+ struct addrinfo *res;
struct in_addr in;
tmpstr = tmpstr1 = strdup(args);
@@ -145,15 +145,20 @@
selectport(sp->s_port, onoff);
continue;
}
- hp = gethostbyname(tmpstr1);
- if (hp == NULL) {
+
+ if (getaddrinfo(tmpstr1, NULL, &(struct addrinfo){
+ .ai_family = AF_INET
+ }, &res) != 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 +297,20 @@
static void
showhosts(void)
{
+ struct sockaddr_in sa = {
+ .sin_len = sizeof(struct sockaddr_in),
+ .sin_family = AF_INET
+ };
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_addr = p->addr;
+ 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,7 +566,6 @@
{
char *cp = 0;
static char line[NI_MAXHOST];
- struct hostent *hp;
struct in_addr in;
#ifdef INET6
@@ -583,9 +582,8 @@
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;
+ if (getnameinfo(sa, sa->sa_len, line, sizeof(line), NULL, 0, NI_NAMEREQD) == 0)
+ cp = line;
}
if (in.s_addr == INADDR_ANY)
strcpy(line, "*");
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 29, 10:39 AM (8 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15630340
Default Alt Text
D45723.diff (2 KB)
Attached To
Mode
D45723: systat: remove gethostby*() calls
Attached
Detach File
Event Timeline
Log In to Comment