xref: /illumos-gate/usr/src/cmd/ipf/tools/ipfstat.c (revision af5f29dd)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (C) 1993-2001, 2003 by Darren Reed.
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
57c478bd9Sstevel@tonic-gate  *
6786c7074Sjojemann  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
77c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
894bdecd9SRob Gulewich  *
994bdecd9SRob Gulewich  * Copyright (c) 2014, Joyent, Inc.  All rights reserved.
107c478bd9Sstevel@tonic-gate  */
117c478bd9Sstevel@tonic-gate 
127c478bd9Sstevel@tonic-gate #ifdef __FreeBSD__
137c478bd9Sstevel@tonic-gate # ifndef __FreeBSD_cc_version
147c478bd9Sstevel@tonic-gate #  include <osreldate.h>
157c478bd9Sstevel@tonic-gate # else
167c478bd9Sstevel@tonic-gate #  if __FreeBSD_cc_version < 430000
177c478bd9Sstevel@tonic-gate #   include <osreldate.h>
187c478bd9Sstevel@tonic-gate #  endif
197c478bd9Sstevel@tonic-gate # endif
207c478bd9Sstevel@tonic-gate #endif
217c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
227c478bd9Sstevel@tonic-gate #include <fcntl.h>
23ab25eeb5Syz #ifdef linux
24ab25eeb5Syz # include <linux/a.out.h>
25ab25eeb5Syz #else
26ab25eeb5Syz # include <nlist.h>
27ab25eeb5Syz #endif
287c478bd9Sstevel@tonic-gate #include <ctype.h>
29ab25eeb5Syz #if defined(sun) && (defined(__svr4__) || defined(__SVR4))
30ab25eeb5Syz # include <stddef.h>
31ab25eeb5Syz #endif
327c478bd9Sstevel@tonic-gate #include "ipf.h"
33ab25eeb5Syz #include "netinet/ipl.h"
347c478bd9Sstevel@tonic-gate #if defined(STATETOP)
357c478bd9Sstevel@tonic-gate # if defined(_BSDI_VERSION)
36ab25eeb5Syz #  undef STATETOP
377c478bd9Sstevel@tonic-gate # endif
387c478bd9Sstevel@tonic-gate # if defined(__FreeBSD__) && \
397c478bd9Sstevel@tonic-gate      (!defined(__FreeBSD_version) || (__FreeBSD_version < 430000))
407c478bd9Sstevel@tonic-gate #  undef STATETOP
417c478bd9Sstevel@tonic-gate # endif
427c478bd9Sstevel@tonic-gate # if defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105000000)
437c478bd9Sstevel@tonic-gate #  undef STATETOP
447c478bd9Sstevel@tonic-gate # endif
457c478bd9Sstevel@tonic-gate # if defined(sun)
467c478bd9Sstevel@tonic-gate #  if defined(__svr4__) || defined(__SVR4)
477c478bd9Sstevel@tonic-gate #   include <sys/select.h>
487c478bd9Sstevel@tonic-gate #  else
497c478bd9Sstevel@tonic-gate #   undef STATETOP	/* NOT supported on SunOS4 */
507c478bd9Sstevel@tonic-gate #  endif
517c478bd9Sstevel@tonic-gate # endif
527c478bd9Sstevel@tonic-gate #endif
537c478bd9Sstevel@tonic-gate #if defined(STATETOP) && !defined(linux)
547c478bd9Sstevel@tonic-gate # include <netinet/ip_var.h>
557c478bd9Sstevel@tonic-gate # include <netinet/tcp_fsm.h>
567c478bd9Sstevel@tonic-gate #endif
577c478bd9Sstevel@tonic-gate #ifdef STATETOP
58ab25eeb5Syz # include <ctype.h>
59ab25eeb5Syz # include <signal.h>
60*af5f29ddSToomas Soome # if defined(SOLARIS) || defined(__NetBSD__) || defined(_BSDI_VERSION) || \
617c478bd9Sstevel@tonic-gate      defined(__sgi)
627c478bd9Sstevel@tonic-gate #  ifdef ERR
637c478bd9Sstevel@tonic-gate #   undef ERR
647c478bd9Sstevel@tonic-gate #  endif
65ab25eeb5Syz #  undef ISASCII
66ab25eeb5Syz #  undef ISPRINT
677c478bd9Sstevel@tonic-gate #  include <curses.h>
687c478bd9Sstevel@tonic-gate # else /* SOLARIS */
697c478bd9Sstevel@tonic-gate #  include <ncurses.h>
707c478bd9Sstevel@tonic-gate # endif /* SOLARIS */
717c478bd9Sstevel@tonic-gate #endif /* STATETOP */
727c478bd9Sstevel@tonic-gate #include "kmem.h"
737c478bd9Sstevel@tonic-gate #if defined(__NetBSD__) || (__OpenBSD__)
747c478bd9Sstevel@tonic-gate # include <paths.h>
757c478bd9Sstevel@tonic-gate #endif
7694bdecd9SRob Gulewich #include "ipfzone.h"
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #if !defined(lint)
797c478bd9Sstevel@tonic-gate static const char sccsid[] = "@(#)fils.c	1.21 4/20/96 (C) 1993-2000 Darren Reed";
80ab25eeb5Syz static const char rcsid[] = "@(#)$Id: ipfstat.c,v 1.44.2.12 2005/06/12 07:18:46 darrenr Exp $";
817c478bd9Sstevel@tonic-gate #endif
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate #ifdef __hpux
847c478bd9Sstevel@tonic-gate # define	nlist	nlist64
857c478bd9Sstevel@tonic-gate #endif
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate extern	char	*optarg;
887c478bd9Sstevel@tonic-gate extern	int	optind;
89ab25eeb5Syz extern	int	opterr;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #define	PRINTF	(void)printf
927c478bd9Sstevel@tonic-gate #define	FPRINTF	(void)fprintf
937c478bd9Sstevel@tonic-gate static	char	*filters[4] = { "ipfilter(in)", "ipfilter(out)",
947c478bd9Sstevel@tonic-gate 				"ipacct(in)", "ipacct(out)" };
957c478bd9Sstevel@tonic-gate static	int	state_logging = -1;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate int	opts = 0;
987c478bd9Sstevel@tonic-gate int	use_inet6 = 0;
997c478bd9Sstevel@tonic-gate int	live_kernel = 1;
1007c478bd9Sstevel@tonic-gate int	state_fd = -1;
1017c478bd9Sstevel@tonic-gate int	ipf_fd = -1;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #ifdef STATETOP
1047c478bd9Sstevel@tonic-gate #define	STSTRSIZE 	80
1057c478bd9Sstevel@tonic-gate #define	STGROWSIZE	16
1067c478bd9Sstevel@tonic-gate #define	HOSTNMLEN	40
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #define	STSORT_PR	0
1097c478bd9Sstevel@tonic-gate #define	STSORT_PKTS	1
1107c478bd9Sstevel@tonic-gate #define	STSORT_BYTES	2
1117c478bd9Sstevel@tonic-gate #define	STSORT_TTL	3
1127c478bd9Sstevel@tonic-gate #define	STSORT_SRCIP	4
113ab25eeb5Syz #define	STSORT_SRCPT	5
114ab25eeb5Syz #define	STSORT_DSTIP	6
115ab25eeb5Syz #define	STSORT_DSTPT	7
116ab25eeb5Syz #define	STSORT_MAX	STSORT_DSTPT
1177c478bd9Sstevel@tonic-gate #define	STSORT_DEFAULT	STSORT_BYTES
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate typedef struct statetop {
1217c478bd9Sstevel@tonic-gate 	i6addr_t	st_src;
1227c478bd9Sstevel@tonic-gate 	i6addr_t	st_dst;
1237c478bd9Sstevel@tonic-gate 	u_short		st_sport;
1247c478bd9Sstevel@tonic-gate 	u_short 	st_dport;
1257c478bd9Sstevel@tonic-gate 	u_char		st_p;
126ab25eeb5Syz 	u_char		st_v;
1277c478bd9Sstevel@tonic-gate 	u_char		st_state[2];
1287c478bd9Sstevel@tonic-gate 	U_QUAD_T	st_pkts;
1297c478bd9Sstevel@tonic-gate 	U_QUAD_T	st_bytes;
1307c478bd9Sstevel@tonic-gate 	u_long		st_age;
1317c478bd9Sstevel@tonic-gate } statetop_t;
1327c478bd9Sstevel@tonic-gate #endif
1337c478bd9Sstevel@tonic-gate 
134ab25eeb5Syz int	main __P((int, char *[]));
135ab25eeb5Syz 
1367c478bd9Sstevel@tonic-gate static	void	showstats __P((friostat_t *, u_32_t));
13743412a42SDarren Reed static	void	showfrstates __P((ipfrstat_t *, u_long));
1387c478bd9Sstevel@tonic-gate static	void	showlist __P((friostat_t *));
1397c478bd9Sstevel@tonic-gate static	void	showipstates __P((ips_stat_t *));
1407c478bd9Sstevel@tonic-gate static	void	showauthstates __P((fr_authstat_t *));
1417c478bd9Sstevel@tonic-gate static	void	showgroups __P((friostat_t *));
142ab25eeb5Syz static	void	usage __P((char *));
143f4b3ec61Sdh static	void	printlivelist __P((int, int, frentry_t *, char *, char *));
144f4b3ec61Sdh static	void	printdeadlist __P((int, int, frentry_t *, char *, char *));
1457c478bd9Sstevel@tonic-gate static	void	printlist __P((frentry_t *, char *));
146ab25eeb5Syz static	void	parse_ipportstr __P((const char *, i6addr_t *, int *));
1477c478bd9Sstevel@tonic-gate static	void	ipfstate_live __P((char *, friostat_t **, ips_stat_t **,
1487c478bd9Sstevel@tonic-gate 				   ipfrstat_t **, fr_authstat_t **, u_32_t *));
1497c478bd9Sstevel@tonic-gate static	void	ipfstate_dead __P((char *, friostat_t **, ips_stat_t **,
1507c478bd9Sstevel@tonic-gate 				   ipfrstat_t **, fr_authstat_t **, u_32_t *));
1517c478bd9Sstevel@tonic-gate #ifdef STATETOP
152ab25eeb5Syz static	void	topipstates __P((i6addr_t, i6addr_t, int, int, int,
153ab25eeb5Syz 				 int, int, int));
154ab25eeb5Syz static	void	sig_break __P((int));
155ab25eeb5Syz static	void	sig_resize __P((int));
156ab25eeb5Syz static	char	*getip __P((int, i6addr_t *));
1577c478bd9Sstevel@tonic-gate static	char	*ttl_to_string __P((long));
1587c478bd9Sstevel@tonic-gate static	int	sort_p __P((const void *, const void *));
1597c478bd9Sstevel@tonic-gate static	int	sort_pkts __P((const void *, const void *));
1607c478bd9Sstevel@tonic-gate static	int	sort_bytes __P((const void *, const void *));
1617c478bd9Sstevel@tonic-gate static	int	sort_ttl __P((const void *, const void *));
1627c478bd9Sstevel@tonic-gate static	int	sort_srcip __P((const void *, const void *));
163ab25eeb5Syz static	int	sort_srcpt __P((const void *, const void *));
1647c478bd9Sstevel@tonic-gate static	int	sort_dstip __P((const void *, const void *));
165ab25eeb5Syz static	int	sort_dstpt __P((const void *, const void *));
1667c478bd9Sstevel@tonic-gate #endif
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 
usage(name)169ab25eeb5Syz static void usage(name)
1707c478bd9Sstevel@tonic-gate char *name;
1717c478bd9Sstevel@tonic-gate {
1727c478bd9Sstevel@tonic-gate #ifdef  USE_INET6
173ab25eeb5Syz 	fprintf(stderr, "Usage: %s [-6aAdfghIilnoRsv]\n", name);
1747c478bd9Sstevel@tonic-gate #else
175ab25eeb5Syz 	fprintf(stderr, "Usage: %s [-aAdfghIilnoRsv]\n", name);
1767c478bd9Sstevel@tonic-gate #endif
177ab25eeb5Syz 	fprintf(stderr, "       %s [-M corefile] [-N symbol-list]\n", name);
178ab25eeb5Syz #ifdef	USE_INET6
179ab25eeb5Syz 	fprintf(stderr, "       %s -t [-6C] ", name);
180ab25eeb5Syz #else
181ab25eeb5Syz 	fprintf(stderr, "       %s -t [-C] ", name);
182ab25eeb5Syz #endif
18394bdecd9SRob Gulewich 	fprintf(stderr, "[-G|-z zonename] ");
184ab25eeb5Syz 	fprintf(stderr, "[-D destination address] [-P protocol] [-S source address] [-T refresh time]\n");
1857c478bd9Sstevel@tonic-gate 	exit(1);
1867c478bd9Sstevel@tonic-gate }
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 
main(argc,argv)1897c478bd9Sstevel@tonic-gate int main(argc,argv)
1907c478bd9Sstevel@tonic-gate int argc;
1917c478bd9Sstevel@tonic-gate char *argv[];
1927c478bd9Sstevel@tonic-gate {
1937c478bd9Sstevel@tonic-gate 	fr_authstat_t	frauthst;
1947c478bd9Sstevel@tonic-gate 	fr_authstat_t	*frauthstp = &frauthst;
1957c478bd9Sstevel@tonic-gate 	friostat_t fio;
1967c478bd9Sstevel@tonic-gate 	friostat_t *fiop = &fio;
1977c478bd9Sstevel@tonic-gate 	ips_stat_t ipsst;
1987c478bd9Sstevel@tonic-gate 	ips_stat_t *ipsstp = &ipsst;
1997c478bd9Sstevel@tonic-gate 	ipfrstat_t ifrst;
2007c478bd9Sstevel@tonic-gate 	ipfrstat_t *ifrstp = &ifrst;
2017c478bd9Sstevel@tonic-gate 	char	*device = IPL_NAME, *memf = NULL;
202ab25eeb5Syz 	char	*options, *kern = NULL;
2037c478bd9Sstevel@tonic-gate 	int	c, myoptind;
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	int protocol = -1;		/* -1 = wild card for any protocol */
2067c478bd9Sstevel@tonic-gate 	int refreshtime = 1; 		/* default update time */
2077c478bd9Sstevel@tonic-gate 	int sport = -1;			/* -1 = wild card for any source port */
2087c478bd9Sstevel@tonic-gate 	int dport = -1;			/* -1 = wild card for any dest port */
2097c478bd9Sstevel@tonic-gate 	int topclosed = 0;		/* do not show closed tcp sessions */
210ab25eeb5Syz 	i6addr_t saddr, daddr;
2117c478bd9Sstevel@tonic-gate 	u_32_t frf;
2127c478bd9Sstevel@tonic-gate 
213ab25eeb5Syz #ifdef	USE_INET6
21494bdecd9SRob Gulewich 	options = "6aACdfgG:hIilnostvD:M:N:P:RS:T:z:";
215ab25eeb5Syz #else
21694bdecd9SRob Gulewich 	options = "aACdfgG:hIilnostvD:M:N:P:RS:T:z:";
217ab25eeb5Syz #endif
218ab25eeb5Syz 
219ab25eeb5Syz 	saddr.in4.s_addr = INADDR_ANY; 	/* default any v4 source addr */
220ab25eeb5Syz 	daddr.in4.s_addr = INADDR_ANY; 	/* default any v4 dest addr */
221ab25eeb5Syz #ifdef	USE_INET6
222ab25eeb5Syz 	saddr.in6 = in6addr_any;	/* default any v6 source addr */
223ab25eeb5Syz 	daddr.in6 = in6addr_any;	/* default any v6 dest addr */
224ab25eeb5Syz #endif
225ab25eeb5Syz 
226ab25eeb5Syz 	/* Don't warn about invalid flags when we run getopt for the 1st time */
227ab25eeb5Syz 	opterr = 0;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	/*
23094bdecd9SRob Gulewich 	 * Parse these four arguments now lest there be any buffer overflows
2317c478bd9Sstevel@tonic-gate 	 * in the parsing of the rest.
2327c478bd9Sstevel@tonic-gate 	 */
2337c478bd9Sstevel@tonic-gate 	myoptind = optind;
234ab25eeb5Syz 	while ((c = getopt(argc, argv, options)) != -1) {
2357c478bd9Sstevel@tonic-gate 		switch (c)
2367c478bd9Sstevel@tonic-gate 		{
23794bdecd9SRob Gulewich 		case 'G' :
23894bdecd9SRob Gulewich 			setzonename_global(optarg);
23994bdecd9SRob Gulewich 			break;
2407c478bd9Sstevel@tonic-gate 		case 'M' :
2417c478bd9Sstevel@tonic-gate 			memf = optarg;
2427c478bd9Sstevel@tonic-gate 			live_kernel = 0;
2437c478bd9Sstevel@tonic-gate 			break;
2447c478bd9Sstevel@tonic-gate 		case 'N' :
2457c478bd9Sstevel@tonic-gate 			kern = optarg;
2467c478bd9Sstevel@tonic-gate 			live_kernel = 0;
2477c478bd9Sstevel@tonic-gate 			break;
24894bdecd9SRob Gulewich 		case 'z' :
24994bdecd9SRob Gulewich 			setzonename(optarg);
25094bdecd9SRob Gulewich 			break;
2517c478bd9Sstevel@tonic-gate 		}
252ab25eeb5Syz 	}
2537c478bd9Sstevel@tonic-gate 	optind = myoptind;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	if (live_kernel == 1) {
2567c478bd9Sstevel@tonic-gate 		if ((state_fd = open(IPSTATE_NAME, O_RDONLY)) == -1) {
257ab25eeb5Syz 			perror("open(IPSTATE_NAME)");
2587c478bd9Sstevel@tonic-gate 			exit(-1);
2597c478bd9Sstevel@tonic-gate 		}
26094bdecd9SRob Gulewich 
26194bdecd9SRob Gulewich 		if (setzone(state_fd) != 0) {
26294bdecd9SRob Gulewich 			close(state_fd);
26394bdecd9SRob Gulewich 			exit(-1);
26494bdecd9SRob Gulewich 		}
26594bdecd9SRob Gulewich 
2667c478bd9Sstevel@tonic-gate 		if ((ipf_fd = open(device, O_RDONLY)) == -1) {
267ab25eeb5Syz 			fprintf(stderr, "open(%s)", device);
268ab25eeb5Syz 			perror("");
2697c478bd9Sstevel@tonic-gate 			exit(-1);
2707c478bd9Sstevel@tonic-gate 		}
27194bdecd9SRob Gulewich 
27294bdecd9SRob Gulewich 		if (setzone(ipf_fd) != 0) {
27394bdecd9SRob Gulewich 			close(ipf_fd);
27494bdecd9SRob Gulewich 			exit(-1);
27594bdecd9SRob Gulewich 		}
2767c478bd9Sstevel@tonic-gate 	}
2777c478bd9Sstevel@tonic-gate 
278ab25eeb5Syz 	if (kern != NULL || memf != NULL) {
2797c478bd9Sstevel@tonic-gate 		(void)setgid(getgid());
2807c478bd9Sstevel@tonic-gate 		(void)setreuid(getuid(), getuid());
281f4b3ec61Sdh 		if (openkmem(kern, memf) == -1)
282f4b3ec61Sdh 			exit(-1);
2837c478bd9Sstevel@tonic-gate 	}
2847c478bd9Sstevel@tonic-gate 
285ab25eeb5Syz 	if (live_kernel == 1)
286ab25eeb5Syz 		(void) checkrev(device);
2877c478bd9Sstevel@tonic-gate 	(void)setgid(getgid());
2887c478bd9Sstevel@tonic-gate 	(void)setreuid(getuid(), getuid());
2897c478bd9Sstevel@tonic-gate 
290ab25eeb5Syz 	opterr = 1;
291ab25eeb5Syz 
292ab25eeb5Syz 	while ((c = getopt(argc, argv, options)) != -1)
2937c478bd9Sstevel@tonic-gate 	{
2947c478bd9Sstevel@tonic-gate 		switch (c)
2957c478bd9Sstevel@tonic-gate 		{
2967c478bd9Sstevel@tonic-gate #ifdef	USE_INET6
2977c478bd9Sstevel@tonic-gate 		case '6' :
2987c478bd9Sstevel@tonic-gate 			use_inet6 = 1;
2997c478bd9Sstevel@tonic-gate 			break;
3007c478bd9Sstevel@tonic-gate #endif
3017c478bd9Sstevel@tonic-gate 		case 'a' :
3027c478bd9Sstevel@tonic-gate 			opts |= OPT_ACCNT|OPT_SHOWLIST;
3037c478bd9Sstevel@tonic-gate 			break;
3047c478bd9Sstevel@tonic-gate 		case 'A' :
3057c478bd9Sstevel@tonic-gate 			opts |= OPT_AUTHSTATS;
3067c478bd9Sstevel@tonic-gate 			break;
3077c478bd9Sstevel@tonic-gate 		case 'C' :
3087c478bd9Sstevel@tonic-gate 			topclosed = 1;
3097c478bd9Sstevel@tonic-gate 			break;
3107c478bd9Sstevel@tonic-gate 		case 'd' :
3117c478bd9Sstevel@tonic-gate 			opts |= OPT_DEBUG;
3127c478bd9Sstevel@tonic-gate 			break;
3137c478bd9Sstevel@tonic-gate 		case 'D' :
3147c478bd9Sstevel@tonic-gate 			parse_ipportstr(optarg, &daddr, &dport);
3157c478bd9Sstevel@tonic-gate 			break;
3167c478bd9Sstevel@tonic-gate 		case 'f' :
3177c478bd9Sstevel@tonic-gate 			opts |= OPT_FRSTATES;
3187c478bd9Sstevel@tonic-gate 			break;
3197c478bd9Sstevel@tonic-gate 		case 'g' :
3207c478bd9Sstevel@tonic-gate 			opts |= OPT_GROUPS;
3217c478bd9Sstevel@tonic-gate 			break;
32294bdecd9SRob Gulewich 		case 'G' :
32394bdecd9SRob Gulewich 			/* Already handled by getzoneopt() above */
32494bdecd9SRob Gulewich 			break;
3257c478bd9Sstevel@tonic-gate 		case 'h' :
3267c478bd9Sstevel@tonic-gate 			opts |= OPT_HITS;
3277c478bd9Sstevel@tonic-gate 			break;
3287c478bd9Sstevel@tonic-gate 		case 'i' :
3297c478bd9Sstevel@tonic-gate 			opts |= OPT_INQUE|OPT_SHOWLIST;
3307c478bd9Sstevel@tonic-gate 			break;
3317c478bd9Sstevel@tonic-gate 		case 'I' :
3327c478bd9Sstevel@tonic-gate 			opts |= OPT_INACTIVE;
3337c478bd9Sstevel@tonic-gate 			break;
3347c478bd9Sstevel@tonic-gate 		case 'l' :
3357c478bd9Sstevel@tonic-gate 			opts |= OPT_SHOWLIST;
3367c478bd9Sstevel@tonic-gate 			break;
3377c478bd9Sstevel@tonic-gate 		case 'M' :
3387c478bd9Sstevel@tonic-gate 			break;
3397c478bd9Sstevel@tonic-gate 		case 'N' :
3407c478bd9Sstevel@tonic-gate 			break;
3417c478bd9Sstevel@tonic-gate 		case 'n' :
3427c478bd9Sstevel@tonic-gate 			opts |= OPT_SHOWLINENO;
3437c478bd9Sstevel@tonic-gate 			break;
3447c478bd9Sstevel@tonic-gate 		case 'o' :
3457c478bd9Sstevel@tonic-gate 			opts |= OPT_OUTQUE|OPT_SHOWLIST;
3467c478bd9Sstevel@tonic-gate 			break;
3477c478bd9Sstevel@tonic-gate 		case 'P' :
348ab25eeb5Syz 			protocol = getproto(optarg);
349ab25eeb5Syz 			if (protocol == -1) {
350ab25eeb5Syz 				fprintf(stderr, "%s: Invalid protocol: %s\n",
3517c478bd9Sstevel@tonic-gate 					argv[0], optarg);
3527c478bd9Sstevel@tonic-gate 				exit(-2);
3537c478bd9Sstevel@tonic-gate 			}
3547c478bd9Sstevel@tonic-gate 			break;
355ab25eeb5Syz 		case 'R' :
356ab25eeb5Syz 			opts |= OPT_NORESOLVE;
357ab25eeb5Syz 			break;
3587c478bd9Sstevel@tonic-gate 		case 's' :
3597c478bd9Sstevel@tonic-gate 			opts |= OPT_IPSTATES;
3607c478bd9Sstevel@tonic-gate 			break;
3617c478bd9Sstevel@tonic-gate 		case 'S' :
3627c478bd9Sstevel@tonic-gate 			parse_ipportstr(optarg, &saddr, &sport);
3637c478bd9Sstevel@tonic-gate 			break;
3647c478bd9Sstevel@tonic-gate 		case 't' :
3657c478bd9Sstevel@tonic-gate #ifdef STATETOP
3667c478bd9Sstevel@tonic-gate 			opts |= OPT_STATETOP;
3677c478bd9Sstevel@tonic-gate 			break;
3687c478bd9Sstevel@tonic-gate #else
3697c478bd9Sstevel@tonic-gate 			fprintf(stderr,
370ab25eeb5Syz 				"%s: state top facility not compiled in\n",
3717c478bd9Sstevel@tonic-gate 				argv[0]);
3727c478bd9Sstevel@tonic-gate 			exit(-2);
3737c478bd9Sstevel@tonic-gate #endif
3747c478bd9Sstevel@tonic-gate 		case 'T' :
3757c478bd9Sstevel@tonic-gate 			if (!sscanf(optarg, "%d", &refreshtime) ||
3767c478bd9Sstevel@tonic-gate 				    (refreshtime <= 0)) {
3777c478bd9Sstevel@tonic-gate 				fprintf(stderr,
378