=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/netstat/inet.c,v retrieving revision 1.102 retrieving revision 1.103 diff -c -r1.102 -r1.103 *** src/usr.bin/netstat/inet.c 2007/12/13 20:00:53 1.102 --- src/usr.bin/netstat/inet.c 2007/12/14 18:35:46 1.103 *************** *** 1,4 **** ! /* $OpenBSD: inet.c,v 1.102 2007/12/13 20:00:53 reyk Exp $ */ /* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: inet.c,v 1.103 2007/12/14 18:35:46 deraadt Exp $ */ /* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */ /* *************** *** 34,40 **** #if 0 static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94"; #else ! static const char *rcsid = "$OpenBSD: inet.c,v 1.102 2007/12/13 20:00:53 reyk Exp $"; #endif #endif /* not lint */ --- 34,40 ---- #if 0 static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94"; #else ! static const char *rcsid = "$OpenBSD: inet.c,v 1.103 2007/12/14 18:35:46 deraadt Exp $"; #endif #endif /* not lint */ *************** *** 77,82 **** --- 77,86 ---- #include #include + #include + #include + #include + #include #include #include *************** *** 84,95 **** #include #include #include #include "netstat.h" - #include - #include - #include - struct inpcb inpcb; struct tcpcb tcpcb; struct socket sockb; --- 88,96 ---- #include #include #include + #include #include "netstat.h" struct inpcb inpcb; struct tcpcb tcpcb; struct socket sockb; *************** *** 98,107 **** char *inetname(struct in_addr *); void inetprint(struct in_addr *, in_port_t, char *, int); - #ifdef INET6 char *inet6name(struct in6_addr *); void inet6print(struct in6_addr *, int, char *, int); - #endif /* * Print a summary of connections related to an Internet --- 99,106 ---- *************** *** 115,127 **** protopr0(off, name, AF_INET); } - #ifdef INET6 void ip6protopr(u_long off, char *name) { protopr0(off, name, AF_INET6); } - #endif static void protopr0(u_long off, char *name, int af) --- 114,124 ---- *************** *** 196,220 **** else printf("%*p ", PLEN, prev); } - #ifdef INET6 if (inpcb.inp_flags & INP_IPV6 && !israw) { strlcpy(namebuf, name0, sizeof namebuf); strlcat(namebuf, "6", sizeof namebuf); name = namebuf; } else name = name0; - #endif printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc); - #ifdef INET6 if (inpcb.inp_flags & INP_IPV6) { inet6print(&inpcb.inp_laddr6, (int)inpcb.inp_lport, name, 1); inet6print(&inpcb.inp_faddr6, (int)inpcb.inp_fport, name, 0); ! } else ! #endif ! { inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport, name, 1); inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport, --- 193,212 ---- else printf("%*p ", PLEN, prev); } if (inpcb.inp_flags & INP_IPV6 && !israw) { strlcpy(namebuf, name0, sizeof namebuf); strlcat(namebuf, "6", sizeof namebuf); name = namebuf; } else name = name0; printf("%-5.5s %6ld %6ld ", name, sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc); if (inpcb.inp_flags & INP_IPV6) { inet6print(&inpcb.inp_laddr6, (int)inpcb.inp_lport, name, 1); inet6print(&inpcb.inp_faddr6, (int)inpcb.inp_fport, name, 0); ! } else { inetprint(&inpcb.inp_laddr, (int)inpcb.inp_lport, name, 1); inetprint(&inpcb.inp_faddr, (int)inpcb.inp_fport, *************** *** 227,237 **** printf(" %s", tcpstates[tcpcb.t_state]); } else if (israw) { u_int8_t proto; ! #ifdef INET6 if (inpcb.inp_flags & INP_IPV6) proto = inpcb.inp_ipv6.ip6_nxt; else - #endif proto = inpcb.inp_ip.ip_p; printf(" %u", proto); } --- 219,228 ---- printf(" %s", tcpstates[tcpcb.t_state]); } else if (israw) { u_int8_t proto; ! if (inpcb.inp_flags & INP_IPV6) proto = inpcb.inp_ipv6.ip6_nxt; else proto = inpcb.inp_ip.ip_p; printf(" %u", proto); } *************** *** 243,261 **** * Dump TCP statistics structure. */ void ! tcp_stats(u_long off, char *name) { struct tcpstat tcpstat; - size_t len; int mib[] = { CTL_NET, AF_INET, IPPROTO_TCP, TCPCTL_STATS }; - if (off == 0) - return; - - len = sizeof(tcpstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &tcpstat, &len, NULL, 0) == -1) { ! warn(name); return; } --- 234,249 ---- * Dump TCP statistics structure. */ void ! tcp_stats(char *name) { struct tcpstat tcpstat; int mib[] = { CTL_NET, AF_INET, IPPROTO_TCP, TCPCTL_STATS }; + size_t len = sizeof(tcpstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &tcpstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; } *************** *** 376,395 **** * Dump UDP statistics structure. */ void ! udp_stats(u_long off, char *name) { struct udpstat udpstat; u_long delivered; - size_t len; int mib[] = { CTL_NET, AF_INET, IPPROTO_UDP, UDPCTL_STATS }; - if (off == 0) - return; - - len = sizeof(udpstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &udpstat, &len, NULL, 0) == -1) { ! warn(name); return; } --- 364,380 ---- * Dump UDP statistics structure. */ void ! udp_stats(char *name) { struct udpstat udpstat; u_long delivered; int mib[] = { CTL_NET, AF_INET, IPPROTO_UDP, UDPCTL_STATS }; + size_t len = sizeof(udpstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &udpstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; } *************** *** 426,444 **** * Dump IP statistics structure. */ void ! ip_stats(u_long off, char *name) { struct ipstat ipstat; - size_t len; int mib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_STATS }; - if (off == 0) - return; - - len = sizeof(ipstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &ipstat, &len, NULL, 0) == -1) { ! warn(name); return; } --- 411,426 ---- * Dump IP statistics structure. */ void ! ip_stats(char *name) { struct ipstat ipstat; int mib[] = { CTL_NET, AF_INET, IPPROTO_IP, IPCTL_STATS }; + size_t len = sizeof(ipstat);; if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &ipstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; } *************** *** 532,551 **** * Dump ICMP statistics. */ void ! icmp_stats(u_long off, char *name) { struct icmpstat icmpstat; int i, first; int mib[] = { CTL_NET, AF_INET, IPPROTO_ICMP, ICMPCTL_STATS }; ! size_t len; - if (off == 0) - return; - - len = sizeof(icmpstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &icmpstat, &len, NULL, 0) == -1) { ! warn(name); return; } --- 514,530 ---- * Dump ICMP statistics. */ void ! icmp_stats(char *name) { struct icmpstat icmpstat; int i, first; int mib[] = { CTL_NET, AF_INET, IPPROTO_ICMP, ICMPCTL_STATS }; ! size_t len = sizeof(icmpstat); if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), &icmpstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; } *************** *** 592,606 **** * Dump IGMP statistics structure. */ void ! igmp_stats(u_long off, char *name) { struct igmpstat igmpstat; ! if (off == 0) return; ! kread(off, &igmpstat, sizeof (igmpstat)); ! printf("%s:\n", name); #define p(f, m) if (igmpstat.f || sflag <= 1) \ printf(m, igmpstat.f, plural(igmpstat.f)) #define py(f, m) if (igmpstat.f || sflag <= 1) \ --- 571,590 ---- * Dump IGMP statistics structure. */ void ! igmp_stats(char *name) { struct igmpstat igmpstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_IGMP, IGMPCTL_STATS }; + size_t len = sizeof(igmpstat); ! if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), ! &igmpstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; ! } + printf("%s:\n", name); #define p(f, m) if (igmpstat.f || sflag <= 1) \ printf(m, igmpstat.f, plural(igmpstat.f)) #define py(f, m) if (igmpstat.f || sflag <= 1) \ *************** *** 623,641 **** * Dump PIM statistics structure. */ void ! pim_stats(u_long off, char *name) { struct pimstat pimstat; ! if (off == 0) return; - if (kread(off, &pimstat, sizeof (pimstat)) != 0) { - /* XXX: PIM is probably not enabled in the kernel */ - return; } printf("%s:\n", name); - #define p(f, m) if (pimstat.f || sflag <= 1) \ printf(m, pimstat.f, plural(pimstat.f)) #define py(f, m) if (pimstat.f || sflag <= 1) \ --- 607,626 ---- * Dump PIM statistics structure. */ void ! pim_stats(char *name) { struct pimstat pimstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_PIM, PIMCTL_STATS }; + size_t len = sizeof(pimstat); ! if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), ! &pimstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; } printf("%s:\n", name); #define p(f, m) if (pimstat.f || sflag <= 1) \ printf(m, pimstat.f, plural(pimstat.f)) #define py(f, m) if (pimstat.f || sflag <= 1) \ *************** *** 816,830 **** * Dump AH statistics structure. */ void ! ah_stats(u_long off, char *name) { struct ahstat ahstat; ! if (off == 0) return; ! kread(off, &ahstat, sizeof (ahstat)); ! printf("%s:\n", name); #define p(f, m) if (ahstat.f || sflag <= 1) \ printf(m, ahstat.f, plural(ahstat.f)) #define p1(f, m) if (ahstat.f || sflag <= 1) \ --- 801,820 ---- * Dump AH statistics structure. */ void ! ah_stats(char *name) { struct ahstat ahstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_AH, AHCTL_STATS }; + size_t len = sizeof(ahstat); ! if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), ! &ahstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; ! } + printf("%s:\n", name); #define p(f, m) if (ahstat.f || sflag <= 1) \ printf(m, ahstat.f, plural(ahstat.f)) #define p1(f, m) if (ahstat.f || sflag <= 1) \ *************** *** 857,871 **** * Dump etherip statistics structure. */ void ! etherip_stats(u_long off, char *name) { struct etheripstat etheripstat; ! if (off == 0) return; ! kread(off, ðeripstat, sizeof (etheripstat)); ! printf("%s:\n", name); #define p(f, m) if (etheripstat.f || sflag <= 1) \ printf(m, etheripstat.f, plural(etheripstat.f)) --- 847,866 ---- * Dump etherip statistics structure. */ void ! etherip_stats(char *name) { struct etheripstat etheripstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_ETHERIP, ETHERIPCTL_STATS }; + size_t len = sizeof(etheripstat); ! if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), ! ðeripstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; ! } + printf("%s:\n", name); #define p(f, m) if (etheripstat.f || sflag <= 1) \ printf(m, etheripstat.f, plural(etheripstat.f)) *************** *** 885,899 **** * Dump ESP statistics structure. */ void ! esp_stats(u_long off, char *name) { struct espstat espstat; ! if (off == 0) return; ! kread(off, &espstat, sizeof (espstat)); ! printf("%s:\n", name); #define p(f, m) if (espstat.f || sflag <= 1) \ printf(m, espstat.f, plural(espstat.f)) --- 880,899 ---- * Dump ESP statistics structure. */ void ! esp_stats(char *name) { struct espstat espstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_ESP, ESPCTL_STATS }; + size_t len = sizeof(espstat); ! if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), ! &espstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; ! } + printf("%s:\n", name); #define p(f, m) if (espstat.f || sflag <= 1) \ printf(m, espstat.f, plural(espstat.f)) *************** *** 927,941 **** * Dump IP-in-IP statistics structure. */ void ! ipip_stats(u_long off, char *name) { struct ipipstat ipipstat; ! if (off == 0) return; ! kread(off, &ipipstat, sizeof (ipipstat)); ! printf("%s:\n", name); #define p(f, m) if (ipipstat.f || sflag <= 1) \ printf(m, ipipstat.f, plural(ipipstat.f)) --- 927,946 ---- * Dump IP-in-IP statistics structure. */ void ! ipip_stats(char *name) { struct ipipstat ipipstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_IPIP, IPIPCTL_STATS }; + size_t len = sizeof(ipipstat); ! if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), ! &ipipstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; ! } + printf("%s:\n", name); #define p(f, m) if (ipipstat.f || sflag <= 1) \ printf(m, ipipstat.f, plural(ipipstat.f)) *************** *** 956,970 **** * Dump CARP statistics structure. */ void ! carp_stats(u_long off, char *name) { struct carpstats carpstat; ! if (off == 0) return; ! kread(off, &carpstat, sizeof(carpstat)); ! printf("%s:\n", name); #define p(f, m) if (carpstat.f || sflag <= 1) \ printf(m, carpstat.f, plural(carpstat.f)) #define p2(f, m) if (carpstat.f || sflag <= 1) \ --- 961,980 ---- * Dump CARP statistics structure. */ void ! carp_stats(char *name) { struct carpstats carpstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_CARP, CARPCTL_STATS }; + size_t len = sizeof(carpstat); ! if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), ! &carpstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; ! } + printf("%s:\n", name); #define p(f, m) if (carpstat.f || sflag <= 1) \ printf(m, carpstat.f, plural(carpstat.f)) #define p2(f, m) if (carpstat.f || sflag <= 1) \ *************** *** 993,1007 **** * Dump pfsync statistics structure. */ void ! pfsync_stats(u_long off, char *name) { struct pfsyncstats pfsyncstat; ! if (off == 0) return; ! kread(off, &pfsyncstat, sizeof(pfsyncstat)); ! printf("%s:\n", name); #define p(f, m) if (pfsyncstat.f || sflag <= 1) \ printf(m, pfsyncstat.f, plural(pfsyncstat.f)) #define p2(f, m) if (pfsyncstat.f || sflag <= 1) \ --- 1003,1022 ---- * Dump pfsync statistics structure. */ void ! pfsync_stats(char *name) { struct pfsyncstats pfsyncstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_PFSYNC, PFSYNCCTL_STATS }; + size_t len = sizeof(pfsyncstat); ! if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), ! &pfsyncstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; ! } + printf("%s:\n", name); #define p(f, m) if (pfsyncstat.f || sflag <= 1) \ printf(m, pfsyncstat.f, plural(pfsyncstat.f)) #define p2(f, m) if (pfsyncstat.f || sflag <= 1) \ *************** *** 1031,1045 **** * Dump IPCOMP statistics structure. */ void ! ipcomp_stats(u_long off, char *name) { struct ipcompstat ipcompstat; ! if (off == 0) return; ! kread(off, &ipcompstat, sizeof (ipcompstat)); ! printf("%s:\n", name); #define p(f, m) if (ipcompstat.f || sflag <= 1) \ printf(m, ipcompstat.f, plural(ipcompstat.f)) --- 1046,1065 ---- * Dump IPCOMP statistics structure. */ void ! ipcomp_stats(char *name) { struct ipcompstat ipcompstat; + int mib[] = { CTL_NET, AF_INET, IPPROTO_IPCOMP, IPCOMPCTL_STATS }; + size_t len = sizeof(ipcompstat); ! if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), ! &ipcompstat, &len, NULL, 0) == -1) { ! if (errno != ENOPROTOOPT) ! warn(name); return; ! } + printf("%s:\n", name); #define p(f, m) if (ipcompstat.f || sflag <= 1) \ printf(m, ipcompstat.f, plural(ipcompstat.f))