2008-01-02 23:26:11 +00:00
|
|
|
/*-
|
1994-05-27 12:33:43 +00:00
|
|
|
* Copyright (c) 1983, 1988, 1993
|
|
|
|
* Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-07-29 06:51:41 +00:00
|
|
|
char const copyright[] =
|
1994-05-27 12:33:43 +00:00
|
|
|
"@(#) Copyright (c) 1983, 1988, 1993\n\
|
|
|
|
Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
1997-07-29 06:51:41 +00:00
|
|
|
#if 0
|
2004-07-26 20:18:11 +00:00
|
|
|
#ifndef lint
|
1994-05-27 12:33:43 +00:00
|
|
|
static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 3/1/94";
|
|
|
|
#endif /* not lint */
|
2004-07-26 20:18:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
2007-07-16 17:15:55 +00:00
|
|
|
#include <sys/socketvar.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2008-09-21 22:02:26 +00:00
|
|
|
#ifdef NETGRAPH
|
1999-10-21 09:06:11 +00:00
|
|
|
#include <netgraph/ng_socket.h>
|
2008-09-21 22:02:26 +00:00
|
|
|
#endif
|
1999-10-21 09:06:11 +00:00
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <ctype.h>
|
1997-07-29 06:51:41 +00:00
|
|
|
#include <err.h>
|
2009-12-13 03:14:06 +00:00
|
|
|
#include <errno.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <nlist.h>
|
2009-12-13 03:14:06 +00:00
|
|
|
#include <paths.h>
|
2006-07-28 16:09:19 +00:00
|
|
|
#include <stdint.h>
|
1994-05-27 12:33:43 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "netstat.h"
|
|
|
|
|
1998-08-08 08:13:04 +00:00
|
|
|
static struct nlist nl[] = {
|
1998-05-15 20:19:21 +00:00
|
|
|
#define N_IFNET 0
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ifnet" },
|
2003-03-05 19:20:29 +00:00
|
|
|
#define N_RTSTAT 1
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_rtstat" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_RTREE 2
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_rt_tables"},
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_MRTSTAT 3
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_mrtstat" },
|
2009-03-19 01:43:03 +00:00
|
|
|
#define N_MFCHASHTBL 4
|
|
|
|
{ .n_name = "_mfchashtbl" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_VIFTABLE 5
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_viftable" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_IPX 6
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ipxpcb_list"},
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_IPXSTAT 7
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ipxstat"},
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_SPXSTAT 8
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_spx_istat"},
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_DDPSTAT 9
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ddpstat"},
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_DDPCB 10
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ddpcb"},
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_NGSOCKS 11
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ngsocklist"},
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_IP6STAT 12
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ip6stat" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_ICMP6STAT 13
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_icmp6stat" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_IPSECSTAT 14
|
2007-07-01 12:08:08 +00:00
|
|
|
{ .n_name = "_ipsec4stat" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_IPSEC6STAT 15
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ipsec6stat" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_PIM6STAT 16
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_pim6stat" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_MRT6STAT 17
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_mrt6stat" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_MF6CTABLE 18
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_mf6ctable" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_MIF6TABLE 19
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_mif6table" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_PFKEYSTAT 20
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_pfkeystat" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_MBSTAT 21
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_mbstat" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_MBTYPES 22
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_mbtypes" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_NMBCLUSTERS 23
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_nmbclusters" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_NMBUFS 24
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_nmbufs" },
|
2003-03-05 19:20:29 +00:00
|
|
|
#define N_MBHI 25
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_mbuf_hiwm" },
|
2003-03-05 19:20:29 +00:00
|
|
|
#define N_CLHI 26
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_clust_hiwm" },
|
2003-03-05 19:20:29 +00:00
|
|
|
#define N_NCPUS 27
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_smp_cpus" },
|
2003-03-05 19:20:29 +00:00
|
|
|
#define N_PAGESZ 28
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_pagesize" },
|
2003-03-05 19:20:29 +00:00
|
|
|
#define N_MBPSTAT 29
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_mb_statpcpu" },
|
2003-03-05 19:20:29 +00:00
|
|
|
#define N_RTTRASH 30
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_rttrash" },
|
2003-03-05 19:20:29 +00:00
|
|
|
#define N_MBLO 31
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_mbuf_lowm" },
|
2003-03-05 19:20:29 +00:00
|
|
|
#define N_CLLO 32
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_clust_lowm" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_CARPSTAT 33
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_carpstats" },
|
2008-01-02 23:26:11 +00:00
|
|
|
#define N_PFSYNCSTAT 34
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_pfsyncstats" },
|
2007-07-16 17:15:55 +00:00
|
|
|
#define N_AHSTAT 35
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ahstat" },
|
2007-07-16 17:15:55 +00:00
|
|
|
#define N_ESPSTAT 36
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_espstat" },
|
2007-07-16 17:15:55 +00:00
|
|
|
#define N_IPCOMPSTAT 37
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = "_ipcompstat" },
|
2007-07-16 17:15:55 +00:00
|
|
|
#define N_TCPSTAT 38
|
|
|
|
{ .n_name = "_tcpstat" },
|
|
|
|
#define N_UDPSTAT 39
|
|
|
|
{ .n_name = "_udpstat" },
|
|
|
|
#define N_IPSTAT 40
|
|
|
|
{ .n_name = "_ipstat" },
|
|
|
|
#define N_ICMPSTAT 41
|
|
|
|
{ .n_name = "_icmpstat" },
|
|
|
|
#define N_IGMPSTAT 42
|
|
|
|
{ .n_name = "_igmpstat" },
|
|
|
|
#define N_PIMSTAT 43
|
|
|
|
{ .n_name = "_pimstat" },
|
|
|
|
#define N_TCBINFO 44
|
|
|
|
{ .n_name = "_tcbinfo" },
|
|
|
|
#define N_UDBINFO 45
|
|
|
|
{ .n_name = "_udbinfo" },
|
|
|
|
#define N_DIVCBINFO 46
|
|
|
|
{ .n_name = "_divcbinfo" },
|
|
|
|
#define N_RIPCBINFO 47
|
|
|
|
{ .n_name = "_ripcbinfo" },
|
|
|
|
#define N_UNP_COUNT 48
|
|
|
|
{ .n_name = "_unp_count" },
|
|
|
|
#define N_UNP_GENCNT 49
|
|
|
|
{ .n_name = "_unp_gencnt" },
|
|
|
|
#define N_UNP_DHEAD 50
|
|
|
|
{ .n_name = "_unp_dhead" },
|
|
|
|
#define N_UNP_SHEAD 51
|
|
|
|
{ .n_name = "_unp_shead" },
|
|
|
|
#define N_RIP6STAT 52
|
|
|
|
{ .n_name = "_rip6stat" },
|
|
|
|
#define N_SCTPSTAT 53
|
|
|
|
{ .n_name = "_sctpstat" },
|
2009-03-19 01:43:03 +00:00
|
|
|
#define N_MFCTABLESIZE 54
|
|
|
|
{ .n_name = "_mfctablesize" },
|
2009-09-03 21:10:57 +00:00
|
|
|
#define N_ARPSTAT 55
|
|
|
|
{ .n_name = "_arpstat" },
|
2009-10-05 15:06:14 +00:00
|
|
|
#define N_UNP_SPHEAD 56
|
|
|
|
{ .n_name = "unp_sphead" },
|
2006-07-28 16:16:40 +00:00
|
|
|
{ .n_name = NULL },
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct protox {
|
2007-07-16 17:15:55 +00:00
|
|
|
int pr_index; /* index into nlist of cb head */
|
|
|
|
int pr_sindex; /* index into nlist of stat block */
|
1994-05-27 12:33:43 +00:00
|
|
|
u_char pr_wanted; /* 1 if wanted, 0 otherwise */
|
2007-07-16 17:15:55 +00:00
|
|
|
void (*pr_cblocks)(u_long, const char *, int, int);
|
2001-06-15 23:35:13 +00:00
|
|
|
/* control blocks printing routine */
|
2007-07-16 17:15:55 +00:00
|
|
|
void (*pr_stats)(u_long, const char *, int, int);
|
2001-06-15 23:35:13 +00:00
|
|
|
/* statistics printing routine */
|
|
|
|
void (*pr_istats)(char *); /* per/if statistics printing routine */
|
2002-04-28 12:12:49 +00:00
|
|
|
const char *pr_name; /* well-known name */
|
2007-07-16 18:13:12 +00:00
|
|
|
int pr_usesysctl; /* non-zero if we use sysctl, not kvm */
|
2007-07-16 17:15:55 +00:00
|
|
|
int pr_protocol;
|
1994-05-27 12:33:43 +00:00
|
|
|
} protox[] = {
|
2007-07-16 17:15:55 +00:00
|
|
|
{ N_TCBINFO, N_TCPSTAT, 1, protopr,
|
|
|
|
tcp_stats, NULL, "tcp", 1, IPPROTO_TCP },
|
|
|
|
{ N_UDBINFO, N_UDPSTAT, 1, protopr,
|
|
|
|
udp_stats, NULL, "udp", 1, IPPROTO_UDP },
|
2007-06-09 13:44:09 +00:00
|
|
|
#ifdef SCTP
|
2007-07-16 17:15:55 +00:00
|
|
|
{ -1, N_SCTPSTAT, 1, sctp_protopr,
|
|
|
|
sctp_stats, NULL, "sctp", 1, IPPROTO_SCTP },
|
2011-03-21 09:58:24 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SDP
|
|
|
|
{ -1, -1, 1, protopr,
|
|
|
|
NULL, NULL, "sdp", 1, IPPROTO_TCP },
|
2007-06-09 13:44:09 +00:00
|
|
|
#endif
|
2007-07-16 17:15:55 +00:00
|
|
|
{ N_DIVCBINFO, -1, 1, protopr,
|
|
|
|
NULL, NULL, "divert", 1, IPPROTO_DIVERT },
|
|
|
|
{ N_RIPCBINFO, N_IPSTAT, 1, protopr,
|
|
|
|
ip_stats, NULL, "ip", 1, IPPROTO_RAW },
|
|
|
|
{ N_RIPCBINFO, N_ICMPSTAT, 1, protopr,
|
|
|
|
icmp_stats, NULL, "icmp", 1, IPPROTO_ICMP },
|
|
|
|
{ N_RIPCBINFO, N_IGMPSTAT, 1, protopr,
|
|
|
|
igmp_stats, NULL, "igmp", 1, IPPROTO_IGMP },
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef IPSEC
|
2007-07-01 12:08:08 +00:00
|
|
|
{ -1, N_IPSECSTAT, 1, NULL, /* keep as compat */
|
2007-07-16 17:15:55 +00:00
|
|
|
ipsec_stats, NULL, "ipsec", 0, 0},
|
2007-07-01 12:08:08 +00:00
|
|
|
{ -1, N_AHSTAT, 1, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
ah_stats, NULL, "ah", 0, 0},
|
2007-07-01 12:08:08 +00:00
|
|
|
{ -1, N_ESPSTAT, 1, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
esp_stats, NULL, "esp", 0, 0},
|
2007-07-01 12:08:08 +00:00
|
|
|
{ -1, N_IPCOMPSTAT, 1, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
ipcomp_stats, NULL, "ipcomp", 0, 0},
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
2007-07-16 17:15:55 +00:00
|
|
|
{ N_RIPCBINFO, N_PIMSTAT, 1, protopr,
|
|
|
|
pim_stats, NULL, "pim", 1, IPPROTO_PIM },
|
|
|
|
{ -1, N_CARPSTAT, 1, NULL,
|
|
|
|
carp_stats, NULL, "carp", 1, 0 },
|
|
|
|
{ -1, N_PFSYNCSTAT, 1, NULL,
|
|
|
|
pfsync_stats, NULL, "pfsync", 1, 0 },
|
2009-09-03 21:10:57 +00:00
|
|
|
{ -1, N_ARPSTAT, 1, NULL,
|
|
|
|
arp_stats, NULL, "arp", 1, 0 },
|
2004-03-18 07:21:31 +00:00
|
|
|
{ -1, -1, 0, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
NULL, NULL, NULL, 0, 0 }
|
1994-05-27 12:33:43 +00:00
|
|
|
};
|
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
struct protox ip6protox[] = {
|
2007-07-16 17:15:55 +00:00
|
|
|
{ N_TCBINFO, N_TCPSTAT, 1, protopr,
|
|
|
|
tcp_stats, NULL, "tcp", 1, IPPROTO_TCP },
|
|
|
|
{ N_UDBINFO, N_UDPSTAT, 1, protopr,
|
|
|
|
udp_stats, NULL, "udp", 1, IPPROTO_UDP },
|
|
|
|
{ N_RIPCBINFO, N_IP6STAT, 1, protopr,
|
|
|
|
ip6_stats, ip6_ifstats, "ip6", 1, IPPROTO_RAW },
|
|
|
|
{ N_RIPCBINFO, N_ICMP6STAT, 1, protopr,
|
|
|
|
icmp6_stats, icmp6_ifstats, "icmp6", 1, IPPROTO_ICMPV6 },
|
2011-03-21 09:58:24 +00:00
|
|
|
#ifdef SDP
|
|
|
|
{ -1, -1, 1, protopr,
|
|
|
|
NULL, NULL, "sdp", 1, IPPROTO_TCP },
|
|
|
|
#endif
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef IPSEC
|
2004-03-18 07:21:31 +00:00
|
|
|
{ -1, N_IPSEC6STAT, 1, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
ipsec_stats, NULL, "ipsec6", 0, 0 },
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
|
|
|
#ifdef notyet
|
2004-03-18 07:21:31 +00:00
|
|
|
{ -1, N_PIM6STAT, 1, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
pim6_stats, NULL, "pim6", 1, 0 },
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
2007-07-16 17:15:55 +00:00
|
|
|
{ -1, N_RIP6STAT, 1, NULL,
|
|
|
|
rip6_stats, NULL, "rip6", 1, 0 },
|
2004-03-18 07:21:31 +00:00
|
|
|
{ -1, -1, 0, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
NULL, NULL, NULL, 0, 0 }
|
1999-12-07 17:39:16 +00:00
|
|
|
};
|
|
|
|
#endif /*INET6*/
|
|
|
|
|
2000-07-05 02:02:54 +00:00
|
|
|
#ifdef IPSEC
|
|
|
|
struct protox pfkeyprotox[] = {
|
2004-03-18 07:21:31 +00:00
|
|
|
{ -1, N_PFKEYSTAT, 1, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
pfkey_stats, NULL, "pfkey", 0, 0 },
|
2004-03-18 07:21:31 +00:00
|
|
|
{ -1, -1, 0, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
NULL, NULL, NULL, 0, 0 }
|
2000-07-05 02:02:54 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
1996-06-08 00:20:42 +00:00
|
|
|
struct protox atalkprotox[] = {
|
|
|
|
{ N_DDPCB, N_DDPSTAT, 1, atalkprotopr,
|
2007-07-16 17:15:55 +00:00
|
|
|
ddp_stats, NULL, "ddp", 0, 0 },
|
2004-03-18 07:21:31 +00:00
|
|
|
{ -1, -1, 0, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
NULL, NULL, NULL, 0, 0 }
|
1996-06-08 00:20:42 +00:00
|
|
|
};
|
2008-09-21 22:02:26 +00:00
|
|
|
#ifdef NETGRAPH
|
1999-10-21 09:06:11 +00:00
|
|
|
struct protox netgraphprotox[] = {
|
|
|
|
{ N_NGSOCKS, -1, 1, netgraphprotopr,
|
2007-07-16 17:15:55 +00:00
|
|
|
NULL, NULL, "ctrl", 0, 0 },
|
1999-10-21 09:06:11 +00:00
|
|
|
{ N_NGSOCKS, -1, 1, netgraphprotopr,
|
2007-07-16 17:15:55 +00:00
|
|
|
NULL, NULL, "data", 0, 0 },
|
2004-03-18 07:21:31 +00:00
|
|
|
{ -1, -1, 0, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
NULL, NULL, NULL, 0, 0 }
|
1999-10-21 09:06:11 +00:00
|
|
|
};
|
2008-09-21 22:02:26 +00:00
|
|
|
#endif
|
2005-08-05 18:45:49 +00:00
|
|
|
#ifdef IPX
|
1995-10-26 20:31:59 +00:00
|
|
|
struct protox ipxprotox[] = {
|
|
|
|
{ N_IPX, N_IPXSTAT, 1, ipxprotopr,
|
2007-07-16 17:15:55 +00:00
|
|
|
ipx_stats, NULL, "ipx", 0, 0 },
|
1995-10-26 20:31:59 +00:00
|
|
|
{ N_IPX, N_SPXSTAT, 1, ipxprotopr,
|
2007-07-16 17:15:55 +00:00
|
|
|
spx_stats, NULL, "spx", 0, 0 },
|
2004-03-18 07:21:31 +00:00
|
|
|
{ -1, -1, 0, NULL,
|
2007-07-16 17:15:55 +00:00
|
|
|
NULL, NULL, 0, 0, 0 }
|
1995-10-26 20:31:59 +00:00
|
|
|
};
|
2005-08-05 18:45:49 +00:00
|
|
|
#endif
|
1995-10-26 20:31:59 +00:00
|
|
|
|
1999-12-07 17:39:16 +00:00
|
|
|
struct protox *protoprotox[] = {
|
|
|
|
protox,
|
|
|
|
#ifdef INET6
|
|
|
|
ip6protox,
|
2000-07-05 02:02:54 +00:00
|
|
|
#endif
|
|
|
|
#ifdef IPSEC
|
|
|
|
pfkeyprotox,
|
1999-12-07 17:39:16 +00:00
|
|
|
#endif
|
2005-08-05 18:45:49 +00:00
|
|
|
#ifdef IPX
|
|
|
|
ipxprotox,
|
|
|
|
#endif
|
|
|
|
atalkprotox, NULL };
|
1994-05-27 12:33:43 +00:00
|
|
|
|
2004-07-26 20:18:11 +00:00
|
|
|
static void printproto(struct protox *, const char *);
|
|
|
|
static void usage(void);
|
2006-07-28 16:16:40 +00:00
|
|
|
static struct protox *name2protox(const char *);
|
|
|
|
static struct protox *knownname(const char *);
|
1994-05-27 12:33:43 +00:00
|
|
|
|
1998-08-08 08:13:04 +00:00
|
|
|
static kvm_t *kvmd;
|
2001-03-15 20:46:04 +00:00
|
|
|
static char *nlistf = NULL, *memf = NULL;
|
|
|
|
|
|
|
|
int Aflag; /* show addresses of protocol control block */
|
|
|
|
int aflag; /* show all sockets (including servers) */
|
2005-09-07 17:35:16 +00:00
|
|
|
int Bflag; /* show information about bpf consumers */
|
2001-03-15 20:46:04 +00:00
|
|
|
int bflag; /* show i/f total bytes in/out */
|
|
|
|
int dflag; /* show i/f dropped packets */
|
|
|
|
int gflag; /* show group (multicast) routing or stats */
|
2005-08-18 21:04:12 +00:00
|
|
|
int hflag; /* show counters in human readable format */
|
2001-03-15 20:46:04 +00:00
|
|
|
int iflag; /* show interfaces */
|
|
|
|
int Lflag; /* show size of listen queues */
|
|
|
|
int mflag; /* show memory stats */
|
2010-01-11 03:00:17 +00:00
|
|
|
int noutputs = 0; /* how much outputs before we exit */
|
2001-06-15 00:25:44 +00:00
|
|
|
int numeric_addr; /* show addresses numerically */
|
|
|
|
int numeric_port; /* show ports numerically */
|
2001-06-15 18:25:38 +00:00
|
|
|
static int pflag; /* show given protocol */
|
2010-02-22 15:57:36 +00:00
|
|
|
int Qflag; /* show netisr information */
|
2001-03-15 20:46:04 +00:00
|
|
|
int rflag; /* show routing tables (or routing stats) */
|
|
|
|
int sflag; /* show protocol statistics */
|
|
|
|
int Wflag; /* wide display */
|
2010-11-17 18:55:12 +00:00
|
|
|
int Tflag; /* TCP Information */
|
2008-09-01 15:04:38 +00:00
|
|
|
int xflag; /* extra information, includes all socket buffer info */
|
2001-06-23 17:17:59 +00:00
|
|
|
int zflag; /* zero stats */
|
2001-03-15 20:46:04 +00:00
|
|
|
|
|
|
|
int interval; /* repeat interval for i/f stats */
|
|
|
|
|
|
|
|
char *interface; /* desired i/f for stats, or NULL for all i/fs */
|
|
|
|
int unit; /* unit number for above */
|
|
|
|
|
|
|
|
int af; /* address family */
|
2007-07-16 17:15:55 +00:00
|
|
|
int live; /* true if we are examining a live system */
|
1994-05-27 12:33:43 +00:00
|
|
|
|
|
|
|
int
|
2002-09-05 17:06:51 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2002-09-05 17:06:51 +00:00
|
|
|
struct protox *tp = NULL; /* for printing cblocks & stats */
|
1994-05-27 12:33:43 +00:00
|
|
|
int ch;
|
|
|
|
|
|
|
|
af = AF_UNSPEC;
|
|
|
|
|
2010-11-17 18:55:12 +00:00
|
|
|
while ((ch = getopt(argc, argv, "AaBbdf:ghI:iLlM:mN:np:Qq:rSTsuWw:xz"))
|
2010-02-22 15:57:36 +00:00
|
|
|
!= -1)
|
1994-05-27 12:33:43 +00:00
|
|
|
switch(ch) {
|
|
|
|
case 'A':
|
|
|
|
Aflag = 1;
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
aflag = 1;
|
|
|
|
break;
|
2005-09-07 17:35:16 +00:00
|
|
|
case 'B':
|
|
|
|
Bflag = 1;
|
|
|
|
break;
|
1994-10-12 02:37:35 +00:00
|
|
|
case 'b':
|
|
|
|
bflag = 1;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'd':
|
|
|
|
dflag = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
1996-02-13 17:30:37 +00:00
|
|
|
if (strcmp(optarg, "ipx") == 0)
|
1995-10-26 20:31:59 +00:00
|
|
|
af = AF_IPX;
|
1994-05-27 12:33:43 +00:00
|
|
|
else if (strcmp(optarg, "inet") == 0)
|
|
|
|
af = AF_INET;
|
1999-12-07 17:39:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
else if (strcmp(optarg, "inet6") == 0)
|
|
|
|
af = AF_INET6;
|
2005-10-22 17:50:45 +00:00
|
|
|
#endif
|
|
|
|
#ifdef IPSEC
|
2000-07-05 02:02:54 +00:00
|
|
|
else if (strcmp(optarg, "pfkey") == 0)
|
|
|
|
af = PF_KEY;
|
2005-10-22 17:50:45 +00:00
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
else if (strcmp(optarg, "unix") == 0)
|
|
|
|
af = AF_UNIX;
|
1996-06-08 00:20:42 +00:00
|
|
|
else if (strcmp(optarg, "atalk") == 0)
|
|
|
|
af = AF_APPLETALK;
|
2008-09-21 22:02:26 +00:00
|
|
|
#ifdef NETGRAPH
|
1999-10-21 09:06:11 +00:00
|
|
|
else if (strcmp(optarg, "ng") == 0
|
|
|
|
|| strcmp(optarg, "netgraph") == 0)
|
|
|
|
af = AF_NETGRAPH;
|
2008-09-21 22:02:26 +00:00
|
|
|
#endif
|
2001-09-11 17:14:33 +00:00
|
|
|
else if (strcmp(optarg, "link") == 0)
|
|
|
|
af = AF_LINK;
|
1994-05-27 12:33:43 +00:00
|
|
|
else {
|
1995-01-23 20:19:16 +00:00
|
|
|
errx(1, "%s: unknown address family", optarg);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
gflag = 1;
|
|
|
|
break;
|
2005-08-18 21:04:12 +00:00
|
|
|
case 'h':
|
|
|
|
hflag = 1;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'I': {
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
iflag = 1;
|
|
|
|
for (cp = interface = optarg; isalpha(*cp); cp++)
|
|
|
|
continue;
|
|
|
|
unit = atoi(cp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'i':
|
|
|
|
iflag = 1;
|
|
|
|
break;
|
1999-12-13 20:08:44 +00:00
|
|
|
case 'L':
|
|
|
|
Lflag = 1;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'M':
|
|
|
|
memf = optarg;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
mflag = 1;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
nlistf = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
2001-06-15 00:25:44 +00:00
|
|
|
numeric_addr = numeric_port = 1;
|
1994-05-27 12:33:43 +00:00
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
if ((tp = name2protox(optarg)) == NULL) {
|
2008-01-02 23:26:11 +00:00
|
|
|
errx(1,
|
1995-01-23 20:19:16 +00:00
|
|
|
"%s: unknown or uninstrumented protocol",
|
|
|
|
optarg);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
pflag = 1;
|
|
|
|
break;
|
2010-02-22 15:57:36 +00:00
|
|
|
case 'Q':
|
|
|
|
Qflag = 1;
|
|
|
|
break;
|
2010-01-11 03:00:17 +00:00
|
|
|
case 'q':
|
|
|
|
noutputs = atoi(optarg);
|
|
|
|
if (noutputs != 0)
|
|
|
|
noutputs++;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'r':
|
|
|
|
rflag = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
++sflag;
|
|
|
|
break;
|
2001-06-15 00:25:44 +00:00
|
|
|
case 'S':
|
|
|
|
numeric_addr = 1;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'u':
|
|
|
|
af = AF_UNIX;
|
|
|
|
break;
|
2001-03-15 20:46:04 +00:00
|
|
|
case 'W':
|
2001-09-07 12:00:50 +00:00
|
|
|
case 'l':
|
2001-03-15 20:46:04 +00:00
|
|
|
Wflag = 1;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case 'w':
|
|
|
|
interval = atoi(optarg);
|
|
|
|
iflag = 1;
|
|
|
|
break;
|
2010-11-17 18:55:12 +00:00
|
|
|
case 'T':
|
|
|
|
Tflag = 1;
|
|
|
|
break;
|
2008-05-15 20:18:44 +00:00
|
|
|
case 'x':
|
|
|
|
xflag = 1;
|
|
|
|
break;
|
2001-06-23 17:17:59 +00:00
|
|
|
case 'z':
|
|
|
|
zflag = 1;
|
|
|
|
break;
|
1994-05-27 12:33:43 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argv += optind;
|
|
|
|
argc -= optind;
|
|
|
|
|
|
|
|
#define BACKWARD_COMPATIBILITY
|
|
|
|
#ifdef BACKWARD_COMPATIBILITY
|
|
|
|
if (*argv) {
|
|
|
|
if (isdigit(**argv)) {
|
|
|
|
interval = atoi(*argv);
|
|
|
|
if (interval <= 0)
|
|
|
|
usage();
|
|
|
|
++argv;
|
|
|
|
iflag = 1;
|
|
|
|
}
|
|
|
|
if (*argv) {
|
|
|
|
nlistf = *argv;
|
|
|
|
if (*++argv)
|
|
|
|
memf = *argv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Discard setgid privileges if not the running kernel so that bad
|
|
|
|
* guys can't print interesting stuff from kernel memory.
|
|
|
|
*/
|
2007-07-16 17:15:55 +00:00
|
|
|
live = (nlistf == NULL && memf == NULL);
|
|
|
|
if (!live)
|
1994-05-27 12:33:43 +00:00
|
|
|
setgid(getgid());
|
|
|
|
|
2010-11-17 18:55:12 +00:00
|
|
|
if (xflag && Tflag)
|
|
|
|
errx(1, "-x and -T are incompatible, pick one.");
|
|
|
|
|
2005-09-07 17:35:16 +00:00
|
|
|
if (Bflag) {
|
2007-07-16 17:15:55 +00:00
|
|
|
if (!live)
|
|
|
|
usage();
|
2005-09-07 17:35:16 +00:00
|
|
|
bpf_stats(interface);
|
|
|
|
exit(0);
|
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
if (mflag) {
|
2009-01-10 12:39:12 +00:00
|
|
|
if (!live) {
|
2007-07-16 17:15:55 +00:00
|
|
|
if (kread(0, NULL, 0) == 0)
|
2005-11-13 14:06:01 +00:00
|
|
|
mbpr(kvmd, nl[N_MBSTAT].n_value);
|
2001-06-14 15:45:09 +00:00
|
|
|
} else
|
2005-11-13 14:06:01 +00:00
|
|
|
mbpr(NULL, 0);
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2010-02-22 15:57:36 +00:00
|
|
|
if (Qflag) {
|
2010-03-01 00:46:45 +00:00
|
|
|
if (!live) {
|
|
|
|
if (kread(0, NULL, 0) == 0)
|
|
|
|
netisr_stats(kvmd);
|
|
|
|
} else
|
|
|
|
netisr_stats(NULL);
|
2010-02-22 15:57:36 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
1996-01-14 23:42:19 +00:00
|
|
|
#if 0
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Keep file descriptors open to avoid overhead
|
|
|
|
* of open/close on each call to get* routines.
|
|
|
|
*/
|
|
|
|
sethostent(1);
|
|
|
|
setnetent(1);
|
1996-01-14 23:42:19 +00:00
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* This does not make sense any more with DNS being default over
|
|
|
|
* the files. Doing a setXXXXent(1) causes a tcp connection to be
|
|
|
|
* used for the queries, which is slower.
|
|
|
|
*/
|
|
|
|
#endif
|
2007-07-16 17:15:55 +00:00
|
|
|
kread(0, NULL, 0);
|
2001-06-15 18:25:38 +00:00
|
|
|
if (iflag && !sflag) {
|
1999-12-07 17:39:16 +00:00
|
|
|
intpr(interval, nl[N_IFNET].n_value, NULL);
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (rflag) {
|
|
|
|
if (sflag)
|
2001-06-29 09:08:24 +00:00
|
|
|
rt_stats(nl[N_RTSTAT].n_value, nl[N_RTTRASH].n_value);
|
1994-05-27 12:33:43 +00:00
|
|
|
else
|
|
|
|
routepr(nl[N_RTREE].n_value);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (gflag) {
|
1999-12-07 17:39:16 +00:00
|
|
|
if (sflag) {
|
|
|
|
if (af == AF_INET || af == AF_UNSPEC)
|
|
|
|
mrt_stats(nl[N_MRTSTAT].n_value);
|
|
|
|
#ifdef INET6
|
|
|
|
if (af == AF_INET6 || af == AF_UNSPEC)
|
|
|
|
mrt6_stats(nl[N_MRT6STAT].n_value);
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
if (af == AF_INET || af == AF_UNSPEC)
|
2009-03-19 01:43:03 +00:00
|
|
|
mroutepr(nl[N_MFCHASHTBL].n_value,
|
|
|
|
nl[N_MFCTABLESIZE].n_value,
|
1999-12-07 17:39:16 +00:00
|
|
|
nl[N_VIFTABLE].n_value);
|
|
|
|
#ifdef INET6
|
|
|
|
if (af == AF_INET6 || af == AF_UNSPEC)
|
|
|
|
mroute6pr(nl[N_MF6CTABLE].n_value,
|
|
|
|
nl[N_MIF6TABLE].n_value);
|
|
|
|
#endif
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1999-12-07 17:39:16 +00:00
|
|
|
exit(0);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
1999-12-07 17:39:16 +00:00
|
|
|
|
2001-06-15 18:25:38 +00:00
|
|
|
if (tp) {
|
|
|
|
printproto(tp, tp->pr_name);
|
|
|
|
exit(0);
|
|
|
|
}
|
1999-12-07 17:39:16 +00:00
|
|
|
if (af == AF_INET || af == AF_UNSPEC)
|
|
|
|
for (tp = protox; tp->pr_name; tp++)
|
|
|
|
printproto(tp, tp->pr_name);
|
|
|
|
#ifdef INET6
|
|
|
|
if (af == AF_INET6 || af == AF_UNSPEC)
|
|
|
|
for (tp = ip6protox; tp->pr_name; tp++)
|
|
|
|
printproto(tp, tp->pr_name);
|
|
|
|
#endif /*INET6*/
|
2000-07-05 02:02:54 +00:00
|
|
|
#ifdef IPSEC
|
|
|
|
if (af == PF_KEY || af == AF_UNSPEC)
|
|
|
|
for (tp = pfkeyprotox; tp->pr_name; tp++)
|
|
|
|
printproto(tp, tp->pr_name);
|
|
|
|
#endif /*IPSEC*/
|
2005-08-05 18:45:49 +00:00
|
|
|
#ifdef IPX
|
1999-02-06 19:12:48 +00:00
|
|
|
if (af == AF_IPX || af == AF_UNSPEC) {
|
1995-10-26 20:31:59 +00:00
|
|
|
for (tp = ipxprotox; tp->pr_name; tp++)
|
1996-06-08 00:20:42 +00:00
|
|
|
printproto(tp, tp->pr_name);
|
1999-02-06 19:12:48 +00:00
|
|
|
}
|
2005-08-05 18:45:49 +00:00
|
|
|
#endif /* IPX */
|
1996-06-08 00:20:42 +00:00
|
|
|
if (af == AF_APPLETALK || af == AF_UNSPEC)
|
|
|
|
for (tp = atalkprotox; tp->pr_name; tp++)
|
1995-10-26 20:31:59 +00:00
|
|
|
printproto(tp, tp->pr_name);
|
2008-09-21 22:02:26 +00:00
|
|
|
#ifdef NETGRAPH
|
1999-10-21 09:06:11 +00:00
|
|
|
if (af == AF_NETGRAPH || af == AF_UNSPEC)
|
|
|
|
for (tp = netgraphprotox; tp->pr_name; tp++)
|
|
|
|
printproto(tp, tp->pr_name);
|
2008-09-21 22:02:26 +00:00
|
|
|
#endif /* NETGRAPH */
|
2008-12-31 08:56:49 +00:00
|
|
|
if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
|
2007-07-16 17:15:55 +00:00
|
|
|
unixpr(nl[N_UNP_COUNT].n_value, nl[N_UNP_GENCNT].n_value,
|
2009-10-05 15:06:14 +00:00
|
|
|
nl[N_UNP_DHEAD].n_value, nl[N_UNP_SHEAD].n_value,
|
|
|
|
nl[N_UNP_SPHEAD].n_value);
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out protocol statistics or control blocks (per sflag).
|
|
|
|
* If the interface was not specifically requested, and the symbol
|
|
|
|
* is not in the namelist, ignore this one.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
printproto(tp, name)
|
2002-09-05 17:06:51 +00:00
|
|
|
struct protox *tp;
|
2002-04-28 12:12:49 +00:00
|
|
|
const char *name;
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2007-07-16 17:15:55 +00:00
|
|
|
void (*pr)(u_long, const char *, int, int);
|
1994-05-27 12:33:43 +00:00
|
|
|
u_long off;
|
|
|
|
|
|
|
|
if (sflag) {
|
1999-12-07 17:39:16 +00:00
|
|
|
if (iflag) {
|
|
|
|
if (tp->pr_istats)
|
|
|
|
intpr(interval, nl[N_IFNET].n_value,
|
|
|
|
tp->pr_istats);
|
2001-06-15 18:25:38 +00:00
|
|
|
else if (pflag)
|
|
|
|
printf("%s: no per-interface stats routine\n",
|
|
|
|
tp->pr_name);
|
1999-12-07 17:39:16 +00:00
|
|
|
return;
|
2007-07-16 17:15:55 +00:00
|
|
|
} else {
|
1999-12-07 17:39:16 +00:00
|
|
|
pr = tp->pr_stats;
|
2001-06-15 18:25:38 +00:00
|
|
|
if (!pr) {
|
|
|
|
if (pflag)
|
|
|
|
printf("%s: no stats routine\n",
|
|
|
|
tp->pr_name);
|
|
|
|
return;
|
2008-01-02 23:26:11 +00:00
|
|
|
}
|
2007-07-16 17:15:55 +00:00
|
|
|
if (tp->pr_usesysctl && live)
|
|
|
|
off = 0;
|
|
|
|
else if (tp->pr_sindex < 0) {
|
|
|
|
if (pflag)
|
|
|
|
printf(
|
|
|
|
"%s: stats routine doesn't work on cores\n",
|
|
|
|
tp->pr_name);
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
off = nl[tp->pr_sindex].n_value;
|
1999-12-07 17:39:16 +00:00
|
|
|
}
|
1994-05-27 12:33:43 +00:00
|
|
|
} else {
|
|
|
|
pr = tp->pr_cblocks;
|
2001-06-15 18:25:38 +00:00
|
|
|
if (!pr) {
|
|
|
|
if (pflag)
|
|
|
|
printf("%s: no PCB routine\n", tp->pr_name);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-16 17:15:55 +00:00
|
|
|
if (tp->pr_usesysctl && live)
|
|
|
|
off = 0;
|
|
|
|
else if (tp->pr_index < 0) {
|
|
|
|
if (pflag)
|
|
|
|
printf(
|
|
|
|
"%s: PCB routine doesn't work on cores\n",
|
|
|
|
tp->pr_name);
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
off = nl[tp->pr_index].n_value;
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
2007-07-16 17:15:55 +00:00
|
|
|
if (pr != NULL && (off || (live && tp->pr_usesysctl) ||
|
|
|
|
af != AF_UNSPEC))
|
|
|
|
(*pr)(off, name, af, tp->pr_protocol);
|
1994-05-27 12:33:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read kernel memory, return 0 on success.
|
|
|
|
*/
|
|
|
|
int
|
2007-07-16 17:15:55 +00:00
|
|
|
kread(u_long addr, void *buf, size_t size)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2007-07-16 17:15:55 +00:00
|
|
|
char errbuf[_POSIX2_LINE_MAX];
|
|
|
|
|
|
|
|
if (kvmd == NULL) {
|
|
|
|
kvmd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf);
|
2001-08-31 16:26:37 +00:00
|
|
|
setgid(getgid());
|
1998-08-05 13:54:07 +00:00
|
|
|
if (kvmd != NULL) {
|
|
|
|
if (kvm_nlist(kvmd, nl) < 0) {
|
2007-07-16 17:15:55 +00:00
|
|
|
if (nlistf)
|
1998-08-05 13:54:07 +00:00
|
|
|
errx(1, "%s: kvm_nlist: %s", nlistf,
|
|
|
|
kvm_geterr(kvmd));
|
|
|
|
else
|
|
|
|
errx(1, "kvm_nlist: %s", kvm_geterr(kvmd));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nl[0].n_type == 0) {
|
2007-07-16 17:15:55 +00:00
|
|
|
if (nlistf)
|
1998-08-05 13:54:07 +00:00
|
|
|
errx(1, "%s: no namelist", nlistf);
|
|
|
|
else
|
|
|
|
errx(1, "no namelist");
|
|
|
|
}
|
|
|
|
} else {
|
2007-07-16 17:15:55 +00:00
|
|
|
warnx("kvm not available: %s", errbuf);
|
1998-08-05 13:54:07 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
1998-05-15 20:19:21 +00:00
|
|
|
}
|
1998-08-08 08:13:04 +00:00
|
|
|
if (!buf)
|
|
|
|
return (0);
|
2007-07-16 17:15:55 +00:00
|
|
|
if (kvm_read(kvmd, addr, buf, size) != (ssize_t)size) {
|
1995-07-29 22:34:15 +00:00
|
|
|
warnx("%s", kvm_geterr(kvmd));
|
1994-05-27 12:33:43 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-09-05 17:06:51 +00:00
|
|
|
const char *
|
2006-07-28 16:09:19 +00:00
|
|
|
plural(uintmax_t n)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
return (n != 1 ? "s" : "");
|
|
|
|
}
|
|
|
|
|
2002-09-05 17:06:51 +00:00
|
|
|
const char *
|
2006-07-28 16:09:19 +00:00
|
|
|
plurales(uintmax_t n)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
return (n != 1 ? "es" : "");
|
|
|
|
}
|
|
|
|
|
2003-01-14 16:02:56 +00:00
|
|
|
const char *
|
2006-07-28 16:09:19 +00:00
|
|
|
pluralies(uintmax_t n)
|
2003-01-14 16:02:56 +00:00
|
|
|
{
|
|
|
|
return (n != 1 ? "ies" : "y");
|
|
|
|
}
|
|
|
|
|
1994-05-27 12:33:43 +00:00
|
|
|
/*
|
|
|
|
* Find the protox for the given "well-known" name.
|
|
|
|
*/
|
|
|
|
static struct protox *
|
2006-07-28 16:16:40 +00:00
|
|
|
knownname(const char *name)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct protox **tpp, *tp;
|
|
|
|
|
|
|
|
for (tpp = protoprotox; *tpp; tpp++)
|
|
|
|
for (tp = *tpp; tp->pr_name; tp++)
|
|
|
|
if (strcmp(tp->pr_name, name) == 0)
|
|
|
|
return (tp);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the protox corresponding to name.
|
|
|
|
*/
|
|
|
|
static struct protox *
|
2006-07-28 16:16:40 +00:00
|
|
|
name2protox(const char *name)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
|
|
|
struct protox *tp;
|
|
|
|
char **alias; /* alias from p->aliases */
|
|
|
|
struct protoent *p;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find the name in the list of "well-known" names. If that
|
|
|
|
* fails, check if name is an alias for an Internet protocol.
|
|
|
|
*/
|
1999-12-07 17:39:16 +00:00
|
|
|
if ((tp = knownname(name)) != NULL)
|
1994-05-27 12:33:43 +00:00
|
|
|
return (tp);
|
|
|
|
|
|
|
|
setprotoent(1); /* make protocol lookup cheaper */
|
1999-12-07 17:39:16 +00:00
|
|
|
while ((p = getprotoent()) != NULL) {
|
1994-05-27 12:33:43 +00:00
|
|
|
/* assert: name not same as p->name */
|
|
|
|
for (alias = p->p_aliases; *alias; alias++)
|
|
|
|
if (strcmp(name, *alias) == 0) {
|
|
|
|
endprotoent();
|
|
|
|
return (knownname(p->p_name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
endprotoent();
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-06-15 23:35:13 +00:00
|
|
|
usage(void)
|
1994-05-27 12:33:43 +00:00
|
|
|
{
|
2010-02-22 15:57:36 +00:00
|
|
|
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
|
2010-11-17 18:55:12 +00:00
|
|
|
"usage: netstat [-AaLnSTWx] [-f protocol_family | -p protocol]\n"
|
2001-09-11 15:21:36 +00:00
|
|
|
" [-M core] [-N system]",
|
2009-12-01 15:18:25 +00:00
|
|
|
" netstat -i | -I interface [-abdhnW] [-f address_family]\n"
|
2001-09-11 17:14:33 +00:00
|
|
|
" [-M core] [-N system]",
|
2010-01-11 03:00:17 +00:00
|
|
|
" netstat -w wait [-I interface] [-d] [-M core] [-N system] [-q howmany]",
|
2009-01-10 22:49:02 +00:00
|
|
|
" netstat -s [-s] [-z] [-f protocol_family | -p protocol]\n"
|
|
|
|
" [-M core] [-N system]",
|
2001-09-11 15:21:36 +00:00
|
|
|
" netstat -i | -I interface -s [-f protocol_family | -p protocol]\n"
|
|
|
|
" [-M core] [-N system]",
|
2004-10-20 11:18:31 +00:00
|
|
|
" netstat -m [-M core] [-N system]",
|
2009-01-10 22:49:02 +00:00
|
|
|
" netstat -B [-I interface]",
|
|
|
|
" netstat -r [-AanW] [-f address_family] [-M core] [-N system]",
|
2001-09-11 15:21:36 +00:00
|
|
|
" netstat -rs [-s] [-M core] [-N system]",
|
|
|
|
" netstat -g [-W] [-f address_family] [-M core] [-N system]",
|
2010-02-22 15:57:36 +00:00
|
|
|
" netstat -gs [-s] [-f address_family] [-M core] [-N system]",
|
|
|
|
" netstat -Q");
|
1994-05-27 12:33:43 +00:00
|
|
|
exit(1);
|
|
|
|
}
|