diff options
author | dg <dg@FreeBSD.org> | 1995-09-23 15:04:28 +0000 |
---|---|---|
committer | dg <dg@FreeBSD.org> | 1995-09-23 15:04:28 +0000 |
commit | 17596c2d332ec25a4ca1df70171b5b512a0420fb (patch) | |
tree | 7c810117d26a5aae71f27ceb59768118105ea169 /usr.bin/netstat | |
parent | fedd317dfd528248b646848a09356bb7665a601a (diff) | |
download | FreeBSD-src-17596c2d332ec25a4ca1df70171b5b512a0420fb.zip FreeBSD-src-17596c2d332ec25a4ca1df70171b5b512a0420fb.tar.gz |
Fixed netstat to not bogusly mangle the argv[] command args by rewriting
the way it stores and handles "interface". The previous behavior resulted
in strange output from 'w' and 'ps' when an interface specification was
given to netstat.
Diffstat (limited to 'usr.bin/netstat')
-rw-r--r-- | usr.bin/netstat/if.c | 26 | ||||
-rw-r--r-- | usr.bin/netstat/main.c | 1 |
2 files changed, 12 insertions, 15 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c index f625740..adcc076 100644 --- a/usr.bin/netstat/if.c +++ b/usr.bin/netstat/if.c @@ -79,7 +79,7 @@ intpr(interval, ifnetaddr) } ifaddr; u_long ifaddraddr; struct sockaddr *sa; - char name[16]; + char name[32], tname[16]; if (ifnetaddr == 0) { printf("ifnet: symbol not defined\n"); @@ -112,15 +112,14 @@ intpr(interval, ifnetaddr) if (ifaddraddr == 0) { if (kread(ifnetaddr, (char *)&ifnet, sizeof ifnet) || - kread((u_long)ifnet.if_name, name, 16)) + kread((u_long)ifnet.if_name, tname, 16)) return; - name[15] = '\0'; + tname[15] = '\0'; ifnetaddr = (u_long)ifnet.if_next; - if (interface != 0 && (strcmp(name, interface) != 0 || - unit != ifnet.if_unit)) + snprintf(name, 32, "%s%d", tname, ifnet.if_unit); + if (interface != 0 && (strcmp(name, interface) != 0)) continue; cp = index(name, '\0'); - cp += sprintf(cp, "%d", ifnet.if_unit); if ((ifnet.if_flags&IFF_UP) == 0) *cp++ = '*'; *cp = '\0'; @@ -169,7 +168,7 @@ intpr(interval, ifnetaddr) char netnum[8]; *(union ns_net *) &net = sns->sns_addr.x_net; - sprintf(netnum, "%lxH", ntohl(net)); + sprintf(netnum, "%lxH", ntohl(net)); upHex(netnum); printf("ns:%-8s ", netnum); printf("%-15s ", @@ -260,18 +259,17 @@ sidewaysintpr(interval, off) interesting = iftot; for (off = firstifnet, ip = iftot; off;) { char *cp; + char name[16], tname[16]; if (kread(off, (char *)&ifnet, sizeof ifnet)) break; - ip->ift_name[0] = '('; - if (kread((u_long)ifnet.if_name, ip->ift_name + 1, 15)) + if (kread((u_long)ifnet.if_name, tname, 16)) break; - if (interface && strcmp(ip->ift_name + 1, interface) == 0 && - unit == ifnet.if_unit) + tname[15] = '\0'; + snprintf(name, 16, "%s%d", tname, ifnet.if_unit); + if (interface && strcmp(name, interface) == 0) interesting = ip; - ip->ift_name[15] = '\0'; - cp = index(ip->ift_name, '\0'); - sprintf(cp, "%d)", ifnet.if_unit); + snprintf(ip->ift_name, 16, "(%s)", name);; ip++; if (ip >= iftot + MAXIF - 2) break; diff --git a/usr.bin/netstat/main.c b/usr.bin/netstat/main.c index fbff429..c8f2a98 100644 --- a/usr.bin/netstat/main.c +++ b/usr.bin/netstat/main.c @@ -241,7 +241,6 @@ main(argc, argv) for (cp = interface = optarg; isalpha(*cp); cp++) continue; unit = atoi(cp); - *cp = '\0'; break; } case 'i': |