summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorguido <guido@FreeBSD.org>2000-10-30 11:53:19 +0000
committerguido <guido@FreeBSD.org>2000-10-30 11:53:19 +0000
commit4c8593424da973794cbb6b416c87a0314c30339e (patch)
treebd465d6b1e6c53d0dc7a41a3280da7f545d62595
parentb6750dacb95829de49f401f273ac0f357333277a (diff)
downloadFreeBSD-src-4c8593424da973794cbb6b416c87a0314c30339e.zip
FreeBSD-src-4c8593424da973794cbb6b416c87a0314c30339e.tar.gz
Now that the amount of (pseudo) interfaces is growing with IPv6,
get rid of stupid upperbound on the amount of interfaces (was 8).
-rw-r--r--usr.bin/netstat/if.c52
1 files changed, 30 insertions, 22 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index 392fd5f..ef33a7b 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -67,6 +67,7 @@ static const char rcsid[] =
#include <signal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -441,8 +442,8 @@ intpr(interval, ifnetaddr, pfunc)
}
}
-#define MAXIF 10
struct iftot {
+ struct iftot *ift_next; /* next element list*/
char ift_name[16]; /* interface name */
u_long ift_ip; /* input packets */
u_long ift_ie; /* input errors */
@@ -452,7 +453,7 @@ struct iftot {
u_int ift_dr; /* drops */
u_long ift_ib; /* input bytes */
u_long ift_ob; /* output bytes */
-} iftot[MAXIF];
+};
u_char signalled; /* set if alarm goes off "early" */
@@ -471,9 +472,8 @@ sidewaysintpr(interval, off)
struct ifnet ifnet;
u_long firstifnet;
struct ifnethead ifnethead;
- register struct iftot *ip, *total;
+ struct iftot *iftot, *ip, *ipn, *total, *sum, *interesting;
register int line;
- struct iftot *lastif, *sum, *interesting;
int oldmask, first;
u_long interesting_off;
@@ -481,9 +481,12 @@ sidewaysintpr(interval, off)
return;
firstifnet = (u_long)ifnethead.tqh_first;
- lastif = iftot;
- sum = iftot + MAXIF - 1;
- total = sum - 1;
+ if ((iftot = malloc(sizeof(struct iftot))) == NULL) {
+ printf("malloc failed\n");
+ exit(1);
+ }
+ memset(iftot, 0, sizeof(struct iftot));
+
interesting = NULL;
interesting_off = 0;
for (off = firstifnet, ip = iftot; off;) {
@@ -500,26 +503,30 @@ sidewaysintpr(interval, off)
interesting_off = off;
}
snprintf(ip->ift_name, 16, "(%s)", name);;
- ip++;
- if (ip >= iftot + MAXIF - 2)
- break;
+ if ((ipn = malloc(sizeof(struct iftot))) == NULL) {
+ printf("malloc failed\n");
+ exit(1);
+ }
+ memset(ipn, 0, sizeof(struct iftot));
+ ip->ift_next = ipn;
+ ip = ipn;
off = (u_long) ifnet.if_link.tqe_next;
}
- lastif = ip;
+ if ((total = malloc(sizeof(struct iftot))) == NULL) {
+ printf("malloc failed\n");
+ exit(1);
+ }
+ memset(total, 0, sizeof(struct iftot));
+ if ((sum = malloc(sizeof(struct iftot))) == NULL) {
+ printf("malloc failed\n");
+ exit(1);
+ }
+ memset(sum, 0, sizeof(struct iftot));
+
(void)signal(SIGALRM, catchalarm);
signalled = NO;
(void)alarm(interval);
- for (ip = iftot; ip < iftot + MAXIF; ip++) {
- ip->ift_ip = 0;
- ip->ift_ie = 0;
- ip->ift_ib = 0;
- ip->ift_op = 0;
- ip->ift_oe = 0;
- ip->ift_ob = 0;
- ip->ift_co = 0;
- ip->ift_dr = 0;
- }
first = 1;
banner:
printf("%17s %14s %16s", "input",
@@ -568,7 +575,8 @@ loop:
sum->ift_ob = 0;
sum->ift_co = 0;
sum->ift_dr = 0;
- for (off = firstifnet, ip = iftot; off && ip < lastif; ip++) {
+ for (off = firstifnet, ip = iftot; off && ip->ift_next != NULL;
+ ip = ip->ift_next) {
if (kread(off, (char *)&ifnet, sizeof ifnet)) {
off = 0;
continue;
OpenPOWER on IntegriCloud