version 1.70, 2007/12/11 20:14:45 |
version 1.71, 2007/12/14 18:35:46 |
|
|
#include "netstat.h" |
#include "netstat.h" |
|
|
struct nlist nl[] = { |
struct nlist nl[] = { |
#define N_IPSTAT 0 |
#define N_TCBTABLE 0 |
{ "_ipstat" }, |
|
#define N_TCBTABLE 1 |
|
{ "_tcbtable" }, |
{ "_tcbtable" }, |
#define N_TCPSTAT 2 |
#define N_UDBTABLE 1 |
{ "_tcpstat" }, |
|
#define N_UDBTABLE 3 |
|
{ "_udbtable" }, |
{ "_udbtable" }, |
#define N_UDPSTAT 4 |
#define N_DDPCB 2 |
{ "_udpstat" }, |
{ "_ddpcb"}, |
#define N_IFNET 5 |
#define N_IFNET 3 |
{ "_ifnet" }, |
{ "_ifnet" }, |
#define N_ICMPSTAT 6 |
#define N_UNIXSW 4 |
{ "_icmpstat" }, |
|
#define N_RTSTAT 7 |
|
{ "_rtstat" }, |
|
#define N_UNIXSW 8 |
|
{ "_unixsw" }, |
{ "_unixsw" }, |
#define N_RTREE 9 |
|
{ "_rt_tables"}, |
#define N_MFCHASHTBL 5 |
#define N_FILE 10 |
|
{ "_file" }, |
|
#define N_IGMPSTAT 11 |
|
{ "_igmpstat" }, |
|
#define N_MRTPROTO 12 |
|
{ "_ip_mrtproto" }, |
|
#define N_MRTSTAT 13 |
|
{ "_mrtstat" }, |
|
#define N_MFCHASHTBL 14 |
|
{ "_mfchashtbl" }, |
{ "_mfchashtbl" }, |
#define N_MFCHASH 15 |
#define N_MFCHASH 6 |
{ "_mfchash" }, |
{ "_mfchash" }, |
#define N_VIFTABLE 16 |
#define N_VIFTABLE 7 |
{ "_viftable" }, |
{ "_viftable" }, |
#define N_AHSTAT 17 |
|
{ "_ahstat"}, |
#define N_MF6CTABLE 8 |
#define N_ESPSTAT 18 |
|
{ "_espstat"}, |
|
#define N_IP4STAT 19 |
|
{ "_ipipstat"}, |
|
#define N_DDPSTAT 20 |
|
{ "_ddpstat"}, |
|
#define N_DDPCB 21 |
|
{ "_ddpcb"}, |
|
#define N_ETHERIPSTAT 22 |
|
{ "_etheripstat"}, |
|
#define N_IP6STAT 23 |
|
{ "_ip6stat" }, |
|
#define N_ICMP6STAT 24 |
|
{ "_icmp6stat" }, |
|
#define N_PIM6STAT 25 |
|
{ "_pim6stat" }, |
|
#define N_MRT6PROTO 26 |
|
{ "_ip6_mrtproto" }, |
|
#define N_MRT6STAT 27 |
|
{ "_mrt6stat" }, |
|
#define N_MF6CTABLE 28 |
|
{ "_mf6ctable" }, |
{ "_mf6ctable" }, |
#define N_MIF6TABLE 29 |
#define N_MIF6TABLE 9 |
{ "_mif6table" }, |
{ "_mif6table" }, |
#define N_IPCOMPSTAT 30 |
|
{ "_ipcompstat" }, |
#define N_RTREE 10 |
#define N_RIP6STAT 31 |
{ "_rt_tables"}, |
{ "_rip6stat" }, |
#define N_RTMASK 11 |
#define N_CARPSTAT 32 |
{ "_mask_rnhead" }, |
{ "_carpstats" }, |
#define N_AF2RTAFIDX 12 |
#define N_RAWIPTABLE 33 |
|
{ "_rawcbtable" }, |
|
#define N_RAWIP6TABLE 34 |
|
{ "_rawin6pcbtable" }, |
|
#define N_PFSYNCSTAT 35 |
|
{ "_pfsyncstats" }, |
|
#define N_PIMSTAT 36 |
|
{ "_pimstat" }, |
|
#define N_AF2RTAFIDX 37 |
|
{ "_af2rtafidx" }, |
{ "_af2rtafidx" }, |
#define N_RTBLIDMAX 38 |
#define N_RTBLIDMAX 13 |
{ "_rtbl_id_max" }, |
{ "_rtbl_id_max" }, |
#define N_RTMASK 39 |
|
{ "_mask_rnhead" }, |
#define N_RAWIPTABLE 14 |
|
{ "_rawcbtable" }, |
|
#define N_RAWIP6TABLE 15 |
|
{ "_rawin6pcbtable" }, |
|
|
|
#define N_RTSTAT 16 |
|
{ "_rtstat" }, |
|
|
{ ""} |
{ ""} |
}; |
}; |
|
|
struct protox { |
struct protox { |
u_char pr_index; /* index into nlist of cb head */ |
u_char pr_index; /* index into nlist of cb head */ |
u_char pr_sindex; /* index into nlist of stat block */ |
|
u_char pr_wanted; /* 1 if wanted, 0 otherwise */ |
|
void (*pr_cblocks)(u_long, char *); /* control blocks printing routine */ |
void (*pr_cblocks)(u_long, char *); /* control blocks printing routine */ |
void (*pr_stats)(u_long, char *); /* statistics printing routine */ |
void (*pr_stats)(char *); /* statistics printing routine */ |
void (*pr_dump)(u_long); /* pcb printing routine */ |
void (*pr_dump)(u_long); /* pcb printing routine */ |
char *pr_name; /* well-known name */ |
char *pr_name; /* well-known name */ |
} protox[] = { |
} protox[] = { |
{ N_TCBTABLE, N_TCPSTAT, 1, protopr, |
{ N_TCBTABLE, protopr, tcp_stats, tcp_dump, "tcp" }, |
tcp_stats, tcp_dump, "tcp" }, |
{ N_UDBTABLE, protopr, udp_stats, NULL, "udp" }, |
{ N_UDBTABLE, N_UDPSTAT, 1, protopr, |
{ N_RAWIPTABLE, protopr, ip_stats, NULL, "ip" }, |
udp_stats, 0, "udp" }, |
{ -1, NULL, icmp_stats, NULL, "icmp" }, |
{ N_RAWIPTABLE, N_IPSTAT, 1, protopr, |
{ -1, NULL, igmp_stats, NULL, "igmp" }, |
ip_stats, 0, "ip" }, |
{ -1, NULL, ah_stats, NULL, "ah" }, |
{ -1, N_ICMPSTAT, 1, 0, |
{ -1, NULL, esp_stats, NULL, "esp" }, |
icmp_stats, 0, "icmp" }, |
{ -1, NULL, ipip_stats, NULL, "ipencap" }, |
{ -1, N_IGMPSTAT, 1, 0, |
{ -1, NULL, etherip_stats, NULL, "etherip" }, |
igmp_stats, 0, "igmp" }, |
{ -1, NULL, ipcomp_stats, NULL, "ipcomp" }, |
{ -1, N_AHSTAT, 1, 0, |
{ -1, NULL, carp_stats, NULL, "carp" }, |
ah_stats, 0, "ah" }, |
{ -1, NULL, pfsync_stats, NULL, "pfsync" }, |
{ -1, N_ESPSTAT, 1, 0, |
{ -1, NULL, pim_stats, NULL, "pim" }, |
esp_stats, 0, "esp" }, |
{ -1, NULL, NULL, NULL, NULL } |
{ -1, N_IP4STAT, 1, 0, |
|
ipip_stats, 0, "ipencap" }, |
|
{ -1, N_ETHERIPSTAT, 1, 0, |
|
etherip_stats,0, "etherip" }, |
|
{ -1, N_IPCOMPSTAT, 1, 0, |
|
ipcomp_stats, 0, "ipcomp" }, |
|
{ -1, N_CARPSTAT, 1, 0, |
|
carp_stats, 0, "carp" }, |
|
{ -1, N_PFSYNCSTAT, 1, 0, |
|
pfsync_stats, 0, "pfsync" }, |
|
{ -1, N_PIMSTAT, 1, 0, |
|
pim_stats, 0, "pim" }, |
|
{ -1, -1, 0, 0, |
|
0, 0, 0 } |
|
}; |
}; |
|
|
#ifdef INET6 |
|
struct protox ip6protox[] = { |
struct protox ip6protox[] = { |
{ N_TCBTABLE, N_TCPSTAT, 1, ip6protopr, |
{ N_TCBTABLE, ip6protopr, NULL, tcp_dump, "tcp" }, |
0, tcp_dump, "tcp" }, |
{ N_UDBTABLE, ip6protopr, NULL, NULL, "udp" }, |
{ N_UDBTABLE, N_UDPSTAT, 1, ip6protopr, |
{ N_RAWIP6TABLE,ip6protopr, ip6_stats, NULL, "ip6" }, |
0, 0, "udp" }, |
{ -1, NULL, icmp6_stats, NULL, "icmp6" }, |
{ N_RAWIP6TABLE,N_IP6STAT, 1, ip6protopr, |
{ -1, NULL, pim6_stats, NULL, "pim6" }, |
ip6_stats, 0, "ip6" }, |
{ -1, NULL, rip6_stats, NULL, "rip6" }, |
{ -1, N_ICMP6STAT, 1, 0, |
{ -1, NULL, NULL, NULL, NULL } |
icmp6_stats, 0, "icmp6" }, |
|
{ -1, N_PIM6STAT, 1, 0, |
|
pim6_stats, 0, "pim6" }, |
|
{ -1, N_RIP6STAT, 1, 0, |
|
rip6_stats, 0, "rip6" }, |
|
{ -1, -1, 0, 0, |
|
0, 0, 0 } |
|
}; |
}; |
#endif |
|
|
|
struct protox atalkprotox[] = { |
struct protox atalkprotox[] = { |
{ N_DDPCB, N_DDPSTAT, 1, atalkprotopr, |
{ N_DDPCB, atalkprotopr, ddp_stats, NULL, "ddp" }, |
ddp_stats, 0, "ddp" }, |
{ -1, NULL, NULL, NULL, NULL } |
{ -1, -1, 0, 0, |
|
0, 0, 0 } |
|
}; |
}; |
|
|
#ifndef INET6 |
|
struct protox *protoprotox[] = { |
struct protox *protoprotox[] = { |
protox, atalkprotox, NULL |
|
}; |
|
#else |
|
struct protox *protoprotox[] = { |
|
protox, ip6protox, atalkprotox, NULL |
protox, ip6protox, atalkprotox, NULL |
}; |
}; |
#endif |
|
|
|
static void printproto(struct protox *, char *); |
static void printproto(struct protox *, char *); |
static void usage(void); |
static void usage(void); |
|
|
*/ |
*/ |
sethostent(1); |
sethostent(1); |
setnetent(1); |
setnetent(1); |
|
|
if (iflag) { |
if (iflag) { |
intpr(interval, nl[N_IFNET].n_value); |
intpr(interval, nl[N_IFNET].n_value); |
exit(0); |
exit(0); |
|
|
if (gflag) { |
if (gflag) { |
if (sflag) { |
if (sflag) { |
if (af == AF_INET || af == AF_UNSPEC) |
if (af == AF_INET || af == AF_UNSPEC) |
mrt_stats(nl[N_MRTPROTO].n_value, |
mrt_stats(); |
nl[N_MRTSTAT].n_value); |
|
#ifdef INET6 |
|
if (af == AF_INET6 || af == AF_UNSPEC) |
if (af == AF_INET6 || af == AF_UNSPEC) |
mrt6_stats(nl[N_MRT6PROTO].n_value, |
mrt6_stats(); |
nl[N_MRT6STAT].n_value); |
|
#endif |
|
} else { |
} else { |
if (af == AF_INET || af == AF_UNSPEC) |
if (af == AF_INET || af == AF_UNSPEC) |
mroutepr(nl[N_MRTPROTO].n_value, |
mroutepr(nl[N_MFCHASHTBL].n_value, |
nl[N_MFCHASHTBL].n_value, |
|
nl[N_MFCHASH].n_value, |
nl[N_MFCHASH].n_value, |
nl[N_VIFTABLE].n_value); |
nl[N_VIFTABLE].n_value); |
#ifdef INET6 |
|
if (af == AF_INET6 || af == AF_UNSPEC) |
if (af == AF_INET6 || af == AF_UNSPEC) |
mroute6pr(nl[N_MRT6PROTO].n_value, |
mroute6pr(nl[N_MF6CTABLE].n_value, |
nl[N_MF6CTABLE].n_value, |
|
nl[N_MIF6TABLE].n_value); |
nl[N_MIF6TABLE].n_value); |
#endif |
|
} |
} |
exit(0); |
exit(0); |
} |
} |
|
|
for (tp = protox; tp->pr_name; tp++) |
for (tp = protox; tp->pr_name; tp++) |
if (strcmp(tp->pr_name, p->p_name) == 0) |
if (strcmp(tp->pr_name, p->p_name) == 0) |
break; |
break; |
if (tp->pr_name == 0 || tp->pr_wanted == 0) |
if (tp->pr_name == 0) |
continue; |
continue; |
printproto(tp, p->p_name); |
printproto(tp, p->p_name); |
} |
} |
endprotoent(); |
endprotoent(); |
} |
} |
#ifdef INET6 |
|
if (af == AF_INET6 || af == AF_UNSPEC) |
if (af == AF_INET6 || af == AF_UNSPEC) |
for (tp = ip6protox; tp->pr_name; tp++) |
for (tp = ip6protox; tp->pr_name; tp++) |
printproto(tp, tp->pr_name); |
printproto(tp, tp->pr_name); |
#endif |
|
if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) |
if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag) |
unixpr(nl[N_UNIXSW].n_value); |
unixpr(nl[N_UNIXSW].n_value); |
if (af == AF_APPLETALK || af == AF_UNSPEC) |
if (af == AF_APPLETALK || af == AF_UNSPEC) |
|
|
static void |
static void |
printproto(struct protox *tp, char *name) |
printproto(struct protox *tp, char *name) |
{ |
{ |
void (*pr)(u_long, char *); |
|
u_char i; |
|
|
|
if (sflag) { |
if (sflag) { |
pr = tp->pr_stats; |
if (tp->pr_stats != NULL) |
i = tp->pr_sindex; |
(*tp->pr_stats)(name); |
} else { |
} else { |
pr = tp->pr_cblocks; |
u_char i = tp->pr_index; |
i = tp->pr_index; |
if (tp->pr_cblocks != NULL && |
|
i < sizeof(nl) / sizeof(nl[0]) && |
|
(nl[i].n_value || af != AF_UNSPEC)) |
|
(*tp->pr_cblocks)(nl[i].n_value, name); |
} |
} |
if (pr != NULL && i < sizeof(nl) / sizeof(nl[0]) && |
|
(nl[i].n_value || af != AF_UNSPEC)) |
|
(*pr)(nl[i].n_value, name); |
|
} |
} |
|
|
/* |
/* |