Home | History | Annotate | Download | only in netstat
      1      0       stevel /*
      2      0       stevel  * CDDL HEADER START
      3      0       stevel  *
      4      0       stevel  * The contents of this file are subject to the terms of the
      5   1676          jpk  * Common Development and Distribution License (the "License").
      6   1676          jpk  * You may not use this file except in compliance with the License.
      7      0       stevel  *
      8      0       stevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9      0       stevel  * or http://www.opensolaris.org/os/licensing.
     10      0       stevel  * See the License for the specific language governing permissions
     11      0       stevel  * and limitations under the License.
     12      0       stevel  *
     13      0       stevel  * When distributing Covered Code, include this CDDL HEADER in each
     14      0       stevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15      0       stevel  * If applicable, add the following below this CDDL HEADER, with the
     16      0       stevel  * fields enclosed by brackets "[]" replaced with your own identifying
     17      0       stevel  * information: Portions Copyright [yyyy] [name of copyright owner]
     18      0       stevel  *
     19      0       stevel  * CDDL HEADER END
     20      0       stevel  */
     21      0       stevel /*
     22   8485        Peter  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     23      0       stevel  * Use is subject to license terms.
     24      0       stevel  */
     25      0       stevel 
     26      0       stevel /*
     27      0       stevel  * Copyright (c) 1990  Mentat Inc.
     28      0       stevel  * netstat.c 2.2, last change 9/9/91
     29      0       stevel  * MROUTING Revision 3.5
     30      0       stevel  */
     31      0       stevel 
     32      0       stevel /*
     33      0       stevel  * simple netstat based on snmp/mib-2 interface to the TCP/IP stack
     34      0       stevel  *
     35      0       stevel  * NOTES:
     36      0       stevel  * 1. A comment "LINTED: (note 1)" appears before certain lines where
     37      0       stevel  *    lint would have complained, "pointer cast may result in improper
     38      0       stevel  *    alignment". These are lines where lint had suspected potential
     39      0       stevel  *    improper alignment of a data structure; in each such situation
     40      0       stevel  *    we have relied on the kernel guaranteeing proper alignment.
     41      0       stevel  * 2. Some 'for' loops have been commented as "'for' loop 1", etc
     42      0       stevel  *    because they have 'continue' or 'break' statements in their
     43      0       stevel  *    bodies. 'continue' statements have been used inside some loops
     44      0       stevel  *    where avoiding them would have led to deep levels of indentation.
     45      0       stevel  *
     46      0       stevel  * TODO:
     47      0       stevel  *	Add ability to request subsets from kernel (with level = MIB2_IP;
     48      0       stevel  *	name = 0 meaning everything for compatibility)
     49      0       stevel  */
     50      0       stevel 
     51      0       stevel #include <stdio.h>
     52      0       stevel #include <stdlib.h>
     53      0       stevel #include <stdarg.h>
     54      0       stevel #include <unistd.h>
     55      0       stevel #include <strings.h>
     56      0       stevel #include <string.h>
     57      0       stevel #include <errno.h>
     58      0       stevel #include <ctype.h>
     59      0       stevel #include <kstat.h>
     60      0       stevel #include <assert.h>
     61  10265   Krishnendu #include <locale.h>
     62      0       stevel 
     63      0       stevel #include <sys/types.h>
     64      0       stevel #include <sys/stream.h>
     65      0       stevel #include <stropts.h>
     66      0       stevel #include <sys/strstat.h>
     67      0       stevel #include <sys/tihdr.h>
     68      0       stevel 
     69      0       stevel #include <sys/socket.h>
     70      0       stevel #include <sys/sockio.h>
     71      0       stevel #include <netinet/in.h>
     72      0       stevel #include <net/if.h>
     73      0       stevel #include <net/route.h>
     74      0       stevel 
     75      0       stevel #include <inet/mib2.h>
     76      0       stevel #include <inet/ip.h>
     77      0       stevel #include <inet/arp.h>
     78      0       stevel #include <inet/tcp.h>
     79      0       stevel #include <netinet/igmp_var.h>
     80      0       stevel #include <netinet/ip_mroute.h>
     81      0       stevel 
     82      0       stevel #include <arpa/inet.h>
     83      0       stevel #include <netdb.h>
     84      0       stevel #include <fcntl.h>
     85      0       stevel #include <sys/systeminfo.h>
     86      0       stevel #include <arpa/inet.h>
     87      0       stevel 
     88      0       stevel #include <netinet/dhcp.h>
     89      0       stevel #include <dhcpagent_ipc.h>
     90      0       stevel #include <dhcpagent_util.h>
     91      0       stevel #include <compat.h>
     92      0       stevel 
     93   1676          jpk #include <libtsnet.h>
     94   1676          jpk #include <tsol/label.h>
     95  10265   Krishnendu 
     96  10265   Krishnendu #include "statcommon.h"
     97   1676          jpk 
     98      0       stevel extern void	unixpr(kstat_ctl_t *kc);
     99      0       stevel 
    100      0       stevel #define	STR_EXPAND	4
    101      0       stevel 
    102      0       stevel #define	V4MASK_TO_V6(v4, v6)	((v6)._S6_un._S6_u32[0] = 0xfffffffful, \
    103      0       stevel 				(v6)._S6_un._S6_u32[1] = 0xfffffffful, \
    104      0       stevel 				(v6)._S6_un._S6_u32[2] = 0xfffffffful, \
    105      0       stevel 				(v6)._S6_un._S6_u32[3] = (v4))
    106      0       stevel 
    107      0       stevel #define	IN6_IS_V4MASK(v6)	((v6)._S6_un._S6_u32[0] == 0xfffffffful && \
    108      0       stevel 				(v6)._S6_un._S6_u32[1] == 0xfffffffful && \
    109      0       stevel 				(v6)._S6_un._S6_u32[2] == 0xfffffffful)
    110   3431     carlsonj 
    111   3431     carlsonj /*
    112   3431     carlsonj  * This is used as a cushion in the buffer allocation directed by SIOCGLIFNUM.
    113   3431     carlsonj  * Because there's no locking between SIOCGLIFNUM and SIOCGLIFCONF, it's
    114   3431     carlsonj  * possible for an administrator to plumb new interfaces between those two
    115   3431     carlsonj  * calls, resulting in the failure of the latter.  This addition makes that
    116   3431     carlsonj  * less likely.
    117   3431     carlsonj  */
    118   3431     carlsonj #define	LIFN_GUARD_VALUE	10
    119      0       stevel 
    120      0       stevel typedef struct mib_item_s {
    121      0       stevel 	struct mib_item_s	*next_item;
    122      0       stevel 	int			group;
    123      0       stevel 	int			mib_id;
    124      0       stevel 	int			length;
    125      0       stevel 	void			*valp;
    126      0       stevel } mib_item_t;
    127      0       stevel 
    128      0       stevel struct	ifstat {
    129      0       stevel 	uint64_t	ipackets;
    130      0       stevel 	uint64_t	ierrors;
    131      0       stevel 	uint64_t	opackets;
    132      0       stevel 	uint64_t	oerrors;
    133      0       stevel 	uint64_t	collisions;
    134      0       stevel };
    135      0       stevel 
    136      0       stevel struct iflist {
    137      0       stevel 	struct iflist	*next_if;
    138      0       stevel 	char		ifname[LIFNAMSIZ];
    139      0       stevel 	struct ifstat	tot;
    140      0       stevel };
    141      0       stevel 
    142      0       stevel static	mib_item_t	*mibget(int sd);
    143      0       stevel static	void		mibfree(mib_item_t *firstitem);
    144      0       stevel static	int		mibopen(void);
    145      0       stevel static void		mib_get_constants(mib_item_t *item);
    146      0       stevel static mib_item_t	*mib_item_dup(mib_item_t *item);
    147      0       stevel static mib_item_t	*mib_item_diff(mib_item_t *item1,
    148      0       stevel     mib_item_t *item2);
    149      0       stevel static void		mib_item_destroy(mib_item_t **item);
    150      0       stevel 
    151      0       stevel static boolean_t	octetstrmatch(const Octet_t *a, const Octet_t *b);
    152   1676          jpk static char		*octetstr(const Octet_t *op, int code,
    153      0       stevel 			    char *dst, uint_t dstlen);
    154      0       stevel static char		*pr_addr(uint_t addr,
    155      0       stevel 			    char *dst, uint_t dstlen);
    156      0       stevel static char		*pr_addrnz(ipaddr_t addr, char *dst, uint_t dstlen);
    157      0       stevel static char		*pr_addr6(const in6_addr_t *addr,
    158      0       stevel 			    char *dst, uint_t dstlen);
    159      0       stevel static char		*pr_mask(uint_t addr,
    160      0       stevel 			    char *dst, uint_t dstlen);
    161   1676          jpk static char		*pr_prefix6(const struct in6_addr *addr,
    162   1676          jpk 			    uint_t prefixlen, char *dst, uint_t dstlen);
    163      0       stevel static char		*pr_ap(uint_t addr, uint_t port,
    164      0       stevel 			    char *proto, char *dst, uint_t dstlen);
    165      0       stevel static char		*pr_ap6(const in6_addr_t *addr, uint_t port,
    166      0       stevel 			    char *proto, char *dst, uint_t dstlen);
    167      0       stevel static char		*pr_net(uint_t addr, uint_t mask,
    168      0       stevel 			    char *dst, uint_t dstlen);
    169      0       stevel static char		*pr_netaddr(uint_t addr, uint_t mask,
    170      0       stevel 			    char *dst, uint_t dstlen);
    171      0       stevel static char		*fmodestr(uint_t fmode);
    172      0       stevel static char		*portname(uint_t port, char *proto,
    173      0       stevel 			    char *dst, uint_t dstlen);
    174      0       stevel 
    175   1676          jpk static const char	*mitcp_state(int code,
    176   1676          jpk 			    const mib2_transportMLPEntry_t *attr);
    177   1676          jpk static const char	*miudp_state(int code,
    178   1676          jpk 			    const mib2_transportMLPEntry_t *attr);
    179      0       stevel 
    180      0       stevel static void		stat_report(mib_item_t *item);
    181      0       stevel static void		mrt_stat_report(mib_item_t *item);
    182      0       stevel static void		arp_report(mib_item_t *item);
    183      0       stevel static void		ndp_report(mib_item_t *item);
    184      0       stevel static void		mrt_report(mib_item_t *item);
    185      0       stevel static void		if_stat_total(struct ifstat *oldstats,
    186      0       stevel 			    struct ifstat *newstats, struct ifstat *sumstats);
    187      0       stevel static void		if_report(mib_item_t *item, char *ifname,
    188      0       stevel 			    int Iflag_only, boolean_t once_only);
    189      0       stevel static void		if_report_ip4(mib2_ipAddrEntry_t *ap,
    190      0       stevel 			    char ifname[], char logintname[],
    191      0       stevel 			    struct ifstat *statptr, boolean_t ksp_not_null);
    192      0       stevel static void		if_report_ip6(mib2_ipv6AddrEntry_t *ap6,
    193      0       stevel 			    char ifname[], char logintname[],
    194      0       stevel 			    struct ifstat *statptr, boolean_t ksp_not_null);
    195   1676          jpk static void		ire_report(const mib_item_t *item);
    196   1676          jpk static void		tcp_report(const mib_item_t *item);
    197   1676          jpk static void		udp_report(const mib_item_t *item);
    198      0       stevel static void		group_report(mib_item_t *item);
    199  11042         Erik static void		dce_report(mib_item_t *item);
    200      0       stevel static void		print_ip_stats(mib2_ip_t *ip);
    201      0       stevel static void		print_icmp_stats(mib2_icmp_t *icmp);
    202      0       stevel static void		print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6);
    203      0       stevel static void		print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6);
    204      0       stevel static void		print_sctp_stats(mib2_sctp_t *tcp);
    205      0       stevel static void		print_tcp_stats(mib2_tcp_t *tcp);
    206      0       stevel static void		print_udp_stats(mib2_udp_t *udp);
    207      0       stevel static void		print_rawip_stats(mib2_rawip_t *rawip);
    208      0       stevel static void		print_igmp_stats(struct igmpstat *igps);
    209      0       stevel static void		print_mrt_stats(struct mrtstat *mrts);
    210   1676          jpk static void		sctp_report(const mib_item_t *item);
    211      0       stevel static void		sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6,
    212      0       stevel 			    mib2_ipv6IfStatsEntry_t *sum6);
    213      0       stevel static void		sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6,
    214      0       stevel 			    mib2_ipv6IfIcmpEntry_t *sum6);
    215      0       stevel static void		m_report(void);
    216      0       stevel static void		dhcp_report(char *);
    217      0       stevel 
    218      0       stevel static	uint64_t	kstat_named_value(kstat_t *, char *);
    219      0       stevel static	kid_t		safe_kstat_read(kstat_ctl_t *, kstat_t *, void *);
    220      0       stevel static int		isnum(char *);
    221      0       stevel static char		*plural(int n);
    222      0       stevel static char		*pluraly(int n);
    223      0       stevel static char		*plurales(int n);
    224      0       stevel static void		process_filter(char *arg);
    225   8485        Peter static char		*ifindex2str(uint_t, char *);
    226      0       stevel static boolean_t	family_selected(int family);
    227      0       stevel 
    228      0       stevel static void		usage(char *);
    229      0       stevel static void 		fatal(int errcode, char *str1, ...);
    230      0       stevel 
    231      0       stevel #define	PLURAL(n) plural((int)n)
    232      0       stevel #define	PLURALY(n) pluraly((int)n)
    233      0       stevel #define	PLURALES(n) plurales((int)n)
    234      0       stevel #define	IFLAGMOD(flg, val1, val2)	if (flg == val1) flg = val2
    235      0       stevel #define	MDIFF(diff, elem2, elem1, member)	(diff)->member = \
    236      0       stevel 	(elem2)->member - (elem1)->member
    237      0       stevel 
    238      0       stevel 
    239      0       stevel static	boolean_t	Aflag = B_FALSE;	/* All sockets/ifs/rtng-tbls */
    240  11042         Erik static	boolean_t	Dflag = B_FALSE;	/* DCE info */
    241      0       stevel static	boolean_t	Iflag = B_FALSE;	/* IP Traffic Interfaces */
    242      0       stevel static	boolean_t	Mflag = B_FALSE;	/* STREAMS Memory Statistics */
    243      0       stevel static	boolean_t	Nflag = B_FALSE;	/* Numeric Network Addresses */
    244      0       stevel static	boolean_t	Rflag = B_FALSE;	/* Routing Tables */
    245   1676          jpk static	boolean_t	RSECflag = B_FALSE;	/* Security attributes */
    246      0       stevel static	boolean_t	Sflag = B_FALSE;	/* Per-protocol Statistics */
    247      0       stevel static	boolean_t	Vflag = B_FALSE;	/* Verbose */
    248      0       stevel static	boolean_t	Pflag = B_FALSE;	/* Net to Media Tables */
    249      0       stevel static	boolean_t	Gflag = B_FALSE;	/* Multicast group membership */
    250      0       stevel static	boolean_t	MMflag = B_FALSE;	/* Multicast routing table */
    251      0       stevel static	boolean_t	DHCPflag = B_FALSE;	/* DHCP statistics */
    252  11042         Erik static	boolean_t	Xflag = B_FALSE;	/* Debug Info */
    253      0       stevel 
    254      0       stevel static	int	v4compat = 0;	/* Compatible printing format for status */
    255      0       stevel 
    256      0       stevel static int	proto = IPPROTO_MAX;	/* all protocols */
    257      0       stevel kstat_ctl_t	*kc = NULL;
    258      0       stevel 
    259      0       stevel /*
    260      0       stevel  * Sizes of data structures extracted from the base mib.
    261      0       stevel  * This allows the size of the tables entries to grow while preserving
    262      0       stevel  * binary compatibility.
    263      0       stevel  */
    264      0       stevel static int ipAddrEntrySize;
    265      0       stevel static int ipRouteEntrySize;
    266      0       stevel static int ipNetToMediaEntrySize;
    267      0       stevel static int ipMemberEntrySize;
    268      0       stevel static int ipGroupSourceEntrySize;
    269   1676          jpk static int ipRouteAttributeSize;
    270      0       stevel static int vifctlSize;
    271      0       stevel static int mfcctlSize;
    272      0       stevel 
    273      0       stevel static int ipv6IfStatsEntrySize;
    274      0       stevel static int ipv6IfIcmpEntrySize;
    275      0       stevel static int ipv6AddrEntrySize;
    276      0       stevel static int ipv6RouteEntrySize;
    277      0       stevel static int ipv6NetToMediaEntrySize;
    278      0       stevel static int ipv6MemberEntrySize;
    279      0       stevel static int ipv6GroupSourceEntrySize;
    280      0       stevel 
    281  11042         Erik static int ipDestEntrySize;
    282  11042         Erik 
    283   1676          jpk static int transportMLPSize;
    284      0       stevel static int tcpConnEntrySize;
    285      0       stevel static int tcp6ConnEntrySize;
    286      0       stevel static int udpEntrySize;
    287      0       stevel static int udp6EntrySize;
    288      0       stevel static int sctpEntrySize;
    289      0       stevel static int sctpLocalEntrySize;
    290      0       stevel static int sctpRemoteEntrySize;
    291      0       stevel 
    292      0       stevel #define	protocol_selected(p)	(proto == IPPROTO_MAX || proto == (p))
    293      0       stevel 
    294      0       stevel /* Machinery used for -f (filter) option */
    295   4823          seb enum { FK_AF = 0, FK_OUTIF, FK_DST, FK_FLAGS, NFILTERKEYS };
    296      0       stevel 
    297      0       stevel static const char *filter_keys[NFILTERKEYS] = {
    298   4823          seb 	"af", "outif", "dst", "flags"
    299      0       stevel };
    300      0       stevel 
    301   9710          Ken static m_label_t *zone_security_label = NULL;
    302   9710          Ken 
    303      0       stevel /* Flags on routes */
    304      0       stevel #define	FLF_A		0x00000001
    305  11042         Erik #define	FLF_b		0x00000002
    306      0       stevel #define	FLF_D		0x00000004
    307      0       stevel #define	FLF_G		0x00000008
    308      0       stevel #define	FLF_H		0x00000010
    309      0       stevel #define	FLF_L		0x00000020
    310      0       stevel #define	FLF_U		0x00000040
    311      0       stevel #define	FLF_M		0x00000080
    312      0       stevel #define	FLF_S		0x00000100
    313  11042         Erik #define	FLF_C		0x00000200	/* IRE_IF_CLONE */
    314  11042         Erik #define	FLF_I		0x00000400	/* RTF_INDIRECT */
    315  11042         Erik #define	FLF_R		0x00000800	/* RTF_REJECT */
    316  11042         Erik #define	FLF_B		0x00001000	/* RTF_BLACKHOLE */
    317  11042         Erik 
    318  11042         Erik static const char flag_list[] = "AbDGHLUMSCIRB";
    319      0       stevel 
    320      0       stevel typedef struct filter_rule filter_t;
    321      0       stevel 
    322      0       stevel struct filter_rule {
    323      0       stevel 	filter_t *f_next;
    324      0       stevel 	union {
    325      0       stevel 		int f_family;
    326      0       stevel 		const char *f_ifname;
    327      0       stevel 		struct {
    328      0       stevel 			struct hostent *f_address;
    329      0       stevel 			in6_addr_t f_mask;
    330      0       stevel 		} a;
    331      0       stevel 		struct {
    332      0       stevel 			uint_t f_flagset;
    333      0       stevel 			uint_t f_flagclear;
    334      0       stevel 		} f;
    335      0       stevel 	} u;
    336      0       stevel };
    337      0       stevel 
    338      0       stevel /*
    339      0       stevel  * The user-specified filters are linked into lists separated by
    340      0       stevel  * keyword (type of filter).  Thus, the matching algorithm is:
    341      0       stevel  *	For each non-empty filter list
    342      0       stevel  *		If no filters in the list match
    343      0       stevel  *			then stop here; route doesn't match
    344      0       stevel  *	If loop above completes, then route does match and will be
    345      0       stevel  *	displayed.
    346      0       stevel  */
    347      0       stevel static filter_t *filters[NFILTERKEYS];
    348      0       stevel 
    349  10265   Krishnendu static uint_t timestamp_fmt = NODATE;
    350  10265   Krishnendu 
    351  10265   Krishnendu #if !defined(TEXT_DOMAIN)		/* Should be defined by cc -D */
    352  10265   Krishnendu #define	TEXT_DOMAIN "SYS_TEST"		/* Use this only if it isn't */
    353  10265   Krishnendu #endif
    354  10265   Krishnendu 
    355      0       stevel int
    356      0       stevel main(int argc, char **argv)
    357      0       stevel {
    358      0       stevel 	char		*name;
    359      0       stevel 	mib_item_t	*item = NULL;
    360      0       stevel 	mib_item_t	*previtem = NULL;
    361      0       stevel 	int		sd = -1;
    362      0       stevel 	char	*ifname = NULL;
    363      0       stevel 	int	interval = 0;	/* Single time by default */
    364      0       stevel 	int	count = -1;	/* Forever */
    365      0       stevel 	int	c;
    366      0       stevel 	int	d;
    367      0       stevel 	/*
    368      0       stevel 	 * Possible values of 'Iflag_only':
    369      0       stevel 	 * -1, no feature-flags;
    370      0       stevel 	 *  0, IFlag and other feature-flags enabled
    371      0       stevel 	 *  1, IFlag is the only feature-flag enabled
    372      0       stevel 	 * : trinary variable, modified using IFLAGMOD()
    373      0       stevel 	 */
    374      0       stevel 	int Iflag_only = -1;
    375      0       stevel 	boolean_t once_only = B_FALSE; /* '-i' with count > 1 */
    376      0       stevel 	extern char	*optarg;
    377      0       stevel 	extern int	optind;
    378      0       stevel 	char *default_ip_str = NULL;
    379      0       stevel 
    380      0       stevel 	name = argv[0];
    381      0       stevel 
    382      0       stevel 	v4compat = get_compat_flag(&default_ip_str);
    383      0       stevel 	if (v4compat == DEFAULT_PROT_BAD_VALUE)
    384      0       stevel 		fatal(2, "%s: %s: Bad value for %s in %s\n", name,
    385      0       stevel 		    default_ip_str, DEFAULT_IP, INET_DEFAULT_FILE);
    386      0       stevel 	free(default_ip_str);
    387      0       stevel 
    388  10265   Krishnendu 	(void) setlocale(LC_ALL, "");
    389  10265   Krishnendu 	(void) textdomain(TEXT_DOMAIN);
    390  10265   Krishnendu 
    391  11042         Erik 	while ((c = getopt(argc, argv, "adimnrspMgvxf:P:I:DRT:")) != -1) {
    392      0       stevel 		switch ((char)c) {
    393      0       stevel 		case 'a':		/* all connections */
    394      0       stevel 			Aflag = B_TRUE;
    395      0       stevel 			break;
    396      0       stevel 
    397  11042         Erik 		case 'd':		/* DCE info */
    398      0       stevel 			Dflag = B_TRUE;
    399  11042         Erik 			IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
    400      0       stevel 			break;
    401      0       stevel 
    402      0       stevel 		case 'i':		/* interface (ill/ipif report) */
    403      0       stevel 			Iflag = B_TRUE;
    404      0       stevel 			IFLAGMOD(Iflag_only, -1, 1); /* '-i' exists */
    405      0       stevel 			break;
    406      0       stevel 
    407      0       stevel 		case 'm':		/* streams msg report */
    408      0       stevel 			Mflag = B_TRUE;
    409      0       stevel 			IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
    410      0       stevel 			break;
    411      0       stevel 
    412      0       stevel 		case 'n':		/* numeric format */
    413      0       stevel 			Nflag = B_TRUE;
    414      0       stevel 			break;
    415      0       stevel 
    416      0       stevel 		case 'r':		/* route tables */
    417      0       stevel 			Rflag = B_TRUE;
    418   1676          jpk 			IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
    419   1676          jpk 			break;
    420   1676          jpk 
    421   1676          jpk 		case 'R':		/* security attributes */
    422   1676          jpk 			RSECflag = B_TRUE;
    423      0       stevel 			IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
    424      0       stevel 			break;
    425      0       stevel 
    426      0       stevel 		case 's':		/* per-protocol statistics */
    427      0       stevel 			Sflag = B_TRUE;
    428      0       stevel 			IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
    429      0       stevel 			break;
    430      0       stevel 
    431      0       stevel 		case 'p':		/* arp/ndp table */
    432      0       stevel 			Pflag = B_TRUE;
    433      0       stevel 			IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
    434      0       stevel 			break;
    435      0       stevel 
    436      0       stevel 		case 'M':		/* multicast routing tables */
    437      0       stevel 			MMflag = B_TRUE;
    438      0       stevel 			IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
    439      0       stevel 			break;
    440      0       stevel 
    441      0       stevel 		case 'g':		/* multicast group membership */
    442      0       stevel 			Gflag = B_TRUE;
    443      0       stevel 			IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
    444      0       stevel 			break;
    445      0       stevel 
    446      0       stevel 		case 'v':		/* verbose output format */
    447      0       stevel 			Vflag = B_TRUE;
    448      0       stevel 			IFLAGMOD(Iflag_only, 1, 0); /* see macro def'n */
    449  11042         Erik 			break;
    450  11042         Erik 
    451  11042         Erik 		case 'x':		/* turn on debugging */
    452  11042         Erik 			Xflag = B_TRUE;
    453      0       stevel 			break;
    454      0       stevel 
    455      0       stevel 		case 'f':
    456      0       stevel 			process_filter(optarg);
    457      0       stevel 			break;
    458      0       stevel 
    459      0       stevel 		case 'P':
    460      0       stevel 			if (strcmp(optarg, "ip") == 0) {
    461      0       stevel 				proto = IPPROTO_IP;
    462      0       stevel 			} else if (strcmp(optarg, "ipv6") == 0 ||
    463      0       stevel 			    strcmp(optarg, "ip6") == 0) {
    464      0       stevel 				v4compat = 0;	/* Overridden */
    465      0       stevel 				proto = IPPROTO_IPV6;
    466      0       stevel 			} else if (strcmp(optarg, "icmp") == 0) {
    467      0       stevel 				proto = IPPROTO_ICMP;
    468      0       stevel 			} else if (strcmp(optarg, "icmpv6") == 0 ||
    469      0       stevel 			    strcmp(optarg, "icmp6") == 0) {
    470      0       stevel 				v4compat = 0;	/* Overridden */
    471      0       stevel 				proto = IPPROTO_ICMPV6;
    472      0       stevel 			} else if (strcmp(optarg, "igmp") == 0) {
    473      0       stevel 				proto = IPPROTO_IGMP;
    474      0       stevel 			} else if (strcmp(optarg, "udp") == 0) {
    475      0       stevel 				proto = IPPROTO_UDP;
    476      0       stevel 			} else if (strcmp(optarg, "tcp") == 0) {
    477      0       stevel 				proto = IPPROTO_TCP;
    478      0       stevel 			} else if (strcmp(optarg, "sctp") == 0) {
    479      0       stevel 				proto = IPPROTO_SCTP;
    480      0       stevel 			} else if (strcmp(optarg, "raw") == 0 ||
    481      0       stevel 			    strcmp(optarg, "rawip") == 0) {
    482      0       stevel 				proto = IPPROTO_RAW;
    483      0       stevel 			} else {
    484      0       stevel 				fatal(1, "%s: unknown protocol.\n", optarg);
    485      0       stevel 			}
    486      0       stevel 			break;
    487      0       stevel 
    488      0       stevel 		case 'I':
    489      0       stevel 			ifname = optarg;
    490      0       stevel 			Iflag = B_TRUE;
    491      0       stevel 			IFLAGMOD(Iflag_only, -1, 1); /* see macro def'n */
    492      0       stevel 			break;
    493      0       stevel 
    494      0       stevel 		case 'D':
    495      0       stevel 			DHCPflag = B_TRUE;
    496      0       stevel 			Iflag_only = 0;
    497      0       stevel 			break;
    498      0       stevel 
    499  10265   Krishnendu 		case 'T':
    500  10265   Krishnendu 			if (optarg) {
    501  10265   Krishnendu 				if (*optarg == 'u')
    502  10265   Krishnendu 					timestamp_fmt = UDATE;
    503  10265   Krishnendu 				else if (*optarg == 'd')
    504  10265   Krishnendu 					timestamp_fmt = DDATE;
    505  10265   Krishnendu 				else
    506  10265   Krishnendu 					usage(name);
    507  10265   Krishnendu 			} else {
    508  10265   Krishnendu 				usage(name);
    509  10265   Krishnendu 			}
    510  10265   Krishnendu 			break;
    511  10265   Krishnendu 
    512      0       stevel 		case '?':
    513      0       stevel 		default:
    514      0       stevel 			usage(name);
    515      0       stevel 		}
    516   1676          jpk 	}
    517   1676          jpk 
    518   1676          jpk 	/*
    519   1676          jpk 	 * Make sure -R option is set only on a labeled system.
    520   1676          jpk 	 */
    521   1676          jpk 	if (RSECflag && !is_system_labeled()) {
    522   1676          jpk 		(void) fprintf(stderr, "-R set but labeling is not enabled\n");
    523   1676          jpk 		usage(name);
    524      0       stevel 	}
    525      0       stevel 
    526      0       stevel 	/*
    527      0       stevel 	 * Handle other arguments: find interval, count; the
    528      0       stevel 	 * flags that accept 'interval' and 'count' are OR'd
    529      0       stevel 	 * in the outermost 'if'; more flags may be added as
    530      0       stevel 	 * required
    531      0       stevel 	 */
    532      0       stevel 	if (Iflag || Sflag || Mflag) {
    533      0       stevel 		for (d = optind; d < argc; d++) {
    534      0       stevel 			if (isnum(argv[d])) {
    535      0       stevel 				interval = atoi(argv[d]);
    536      0       stevel 				if (d + 1 < argc &&
    537      0       stevel 				    isnum(argv[d + 1])) {
    538      0       stevel 					count = atoi(argv[d + 1]);
    539      0       stevel 					optind++;
    540      0       stevel 				}
    541      0       stevel 				optind++;
    542      0       stevel 				if (interval == 0 || count == 0)
    543      0       stevel 					usage(name);
    544      0       stevel 				break;
    545      0       stevel 			}
    546      0       stevel 		}
    547      0       stevel 	}
    548      0       stevel 	if (optind < argc) {
    549      0       stevel 		if (Iflag && isnum(argv[optind])) {
    550      0       stevel 			count = atoi(argv[optind]);
    551      0       stevel 			if (count == 0)
    552      0       stevel 				usage(name);
    553      0       stevel 			optind++;
    554      0       stevel 		}
    555      0       stevel 	}
    556      0       stevel 	if (optind < argc) {
    557      0       stevel 		(void) fprintf(stderr,
    558      0       stevel 		    "%s: extra arguments\n", name);
    559      0       stevel 		usage(name);
    560      0       stevel 	}
    561      0       stevel 	if (interval)
    562      0       stevel 		setbuf(stdout, NULL);
    563      0       stevel 
    564      0       stevel 	if (DHCPflag) {
    565      0       stevel 		dhcp_report(Iflag ? ifname : NULL);
    566      0       stevel 		exit(0);
    567      0       stevel 	}
    568      0       stevel 
    569   9710          Ken 	/*
    570   9710          Ken 	 * Get this process's security label if the -R switch is set.
    571   9710          Ken 	 * We use this label as the current zone's security label.
    572   9710          Ken 	 */
    573   9710          Ken 	if (RSECflag) {
    574   9710          Ken 		zone_security_label = m_label_alloc(MAC_LABEL);
    575   9710          Ken 		if (zone_security_label == NULL)
    576   9710          Ken 			fatal(errno, "m_label_alloc() failed");
    577   9710          Ken 		if (getplabel(zone_security_label) < 0)
    578   9710          Ken 			fatal(errno, "getplabel() failed");
    579   9710          Ken 	}
    580   9710          Ken 
    581      0       stevel 	/* Get data structures: priming before iteration */
    582      0       stevel 	if (family_selected(AF_INET) || family_selected(AF_INET6)) {
    583      0       stevel 		sd = mibopen();
    584      0       stevel 		if (sd == -1)
    585      0       stevel 			fatal(1, "can't open mib stream\n");
    586      0       stevel 		if ((item = mibget(sd)) == NULL) {
    587      0       stevel 			(void) close(sd);
    588      0       stevel 			fatal(1, "mibget() failed\n");
    589      0       stevel 		}
    590      0       stevel 		/* Extract constant sizes - need do once only */
    591      0       stevel 		mib_get_constants(item);
    592      0       stevel 	}
    593      0       stevel 	if ((kc = kstat_open()) == NULL) {
    594      0       stevel 		mibfree(item);
    595      0       stevel 		(void) close(sd);
    596      0       stevel 		fail(1, "kstat_open(): can't open /dev/kstat");
    597      0       stevel 	}
    598      0       stevel 
    599      0       stevel 	if (interval <= 0) {
    600      0       stevel 		count = 1;
    601      0       stevel 		once_only = B_TRUE;
    602      0       stevel 	}
    603      0       stevel 	/* 'for' loop 1: */
    604      0       stevel 	for (;;) {
    605      0       stevel 		mib_item_t *curritem = NULL; /* only for -[M]s */
    606  10265   Krishnendu 
    607  10265   Krishnendu 		if (timestamp_fmt != NODATE)
    608  10265   Krishnendu 			print_timestamp(timestamp_fmt);
    609      0       stevel 
    610      0       stevel 		/* netstat: AF_INET[6] behaviour */
    611      0       stevel 		if (family_selected(AF_INET) || family_selected(AF_INET6)) {
    612      0       stevel 			if (Sflag) {
    613      0       stevel 				curritem = mib_item_diff(previtem, item);
    614      0       stevel 				if (curritem == NULL)
    615      0       stevel 					fatal(1, "can't process mib data, "
    616      0       stevel 					    "out of memory\n");
    617      0       stevel 				mib_item_destroy(&previtem);
    618      0       stevel 			}
    619      0       stevel 
    620  11042         Erik 			if (!(Dflag || Iflag || Rflag || Sflag || Mflag ||
    621      0       stevel 			    MMflag || Pflag || Gflag || DHCPflag)) {
    622      0       stevel 				if (protocol_selected(IPPROTO_UDP))
    623      0       stevel 					udp_report(item);
    624      0       stevel 				if (protocol_selected(IPPROTO_TCP))
    625      0       stevel 					tcp_report(item);
    626      0       stevel 				if (protocol_selected(IPPROTO_SCTP))
    627      0       stevel 					sctp_report(item);
    628      0       stevel 			}
    629      0       stevel 			if (Iflag)
    630      0       stevel 				if_report(item, ifname, Iflag_only, once_only);
    631      0       stevel 			if (Mflag)
    632      0       stevel 				m_report();
    633      0       stevel 			if (Rflag)
    634      0       stevel 				ire_report(item);
    635      0       stevel 			if (Sflag && MMflag) {
    636      0       stevel 				mrt_stat_report(curritem);
    637      0       stevel 			} else {
    638      0       stevel 				if (Sflag)
    639      0       stevel 					stat_report(curritem);
    640      0       stevel 				if (MMflag)
    641      0       stevel 					mrt_report(item);
    642      0       stevel 			}
    643      0       stevel 			if (Gflag)
    644      0       stevel 				group_report(item);
    645      0       stevel 			if (Pflag) {
    646      0       stevel 				if (family_selected(AF_INET))
    647      0       stevel 					arp_report(item);
    648      0       stevel 				if (family_selected(AF_INET6))
    649      0       stevel 					ndp_report(item);
    650      0       stevel 			}
    651  11042         Erik 			if (Dflag)
    652  11042         Erik 				dce_report(item);
    653      0       stevel 			mib_item_destroy(&curritem);
    654      0       stevel 		}
    655      0       stevel 
    656      0       stevel 		/* netstat: AF_UNIX behaviour */
    657      0       stevel 		if (family_selected(AF_UNIX) &&
    658  11042         Erik 		    (!(Dflag || Iflag || Rflag || Sflag || Mflag ||
    659      0       stevel 		    MMflag || Pflag || Gflag)))
    660      0       stevel 			unixpr(kc);
    661      0       stevel 		(void) kstat_close(kc);
    662      0       stevel 
    663      0       stevel 		/* iteration handling code */
    664      0       stevel 		if (count > 0 && --count == 0)
    665      0       stevel 			break;
    666      0       stevel 		(void) sleep(interval);
    667      0       stevel 
    668      0       stevel 		/* re-populating of data structures */
    669      0       stevel 		if (family_selected(AF_INET) || family_selected(AF_INET6)) {
    670      0       stevel 			if (Sflag) {
    671      0       stevel 				/* previtem is a cut-down list */
    672      0       stevel 				previtem = mib_item_dup(item);
    673      0       stevel 				if (previtem == NULL)
    674      0       stevel 					fatal(1, "can't process mib data, "
    675      0       stevel 					    "out of memory\n");
    676      0       stevel 			}
    677      0       stevel 			mibfree(item);
    678      0       stevel 			(void) close(sd);
    679      0       stevel 			if ((sd = mibopen()) == -1)
    680      0       stevel 				fatal(1, "can't open mib stream anymore\n");
    681      0       stevel 			if ((item = mibget(sd)) == NULL) {
    682      0       stevel 				(void) close(sd);
    683      0       stevel 				fatal(1, "mibget() failed\n");
    684      0       stevel 			}
    685      0       stevel 		}
    686      0       stevel 		if ((kc = kstat_open()) == NULL)
    687      0       stevel 			fail(1, "kstat_open(): can't open /dev/kstat");
    688      0       stevel 
    689      0       stevel 	} /* 'for' loop 1 ends */
    690      0       stevel 	mibfree(item);
    691      0       stevel 	(void) close(sd);
    692   9710          Ken 	if (zone_security_label != NULL)
    693   9710          Ken 		m_label_free(zone_security_label);
    694      0       stevel 
    695      0       stevel 	return (0);
    696      0       stevel }
    697      0       stevel 
    698      0       stevel 
    699      0       stevel static int
    700      0       stevel isnum(char *p)
    701      0       stevel {
    702      0       stevel 	int	len;
    703      0       stevel 	int	i;
    704      0       stevel 
    705      0       stevel 	len = strlen(p);
    706      0       stevel 	for (i = 0; i < len; i++)
    707      0       stevel 		if (!isdigit(p[i]))
    708      0       stevel 			return (0);
    709      0       stevel 	return (1);
    710      0       stevel }
    711      0       stevel 
    712      0       stevel 
    713      0       stevel /* --------------------------------- MIBGET -------------------------------- */
    714      0       stevel 
    715      0       stevel static mib_item_t *
    716      0       stevel mibget(int sd)
    717      0       stevel {
    718      0       stevel 	/*
    719      0       stevel 	 * buf is an automatic for this function, so the
    720      0       stevel 	 * compiler has complete control over its alignment;
    721      0       stevel 	 * it is assumed this alignment is satisfactory for
    722      0       stevel 	 * it to be casted to certain other struct pointers
    723      0       stevel 	 * here, such as struct T_optmgmt_ack * .
    724      0       stevel 	 */
    725      0       stevel 	uintptr_t		buf[512 / sizeof (uintptr_t)];
    726      0       stevel 	int			flags;
    727      0       stevel 	int			i, j, getcode;
    728      0       stevel 	struct strbuf		ctlbuf, databuf;
    729      0       stevel 	struct T_optmgmt_req	*tor = (struct T_optmgmt_req *)buf;
    730      0       stevel 	struct T_optmgmt_ack	*toa = (struct T_optmgmt_ack *)buf;
    731      0       stevel 	struct T_error_ack	*tea = (struct T_error_ack *)buf;
    732      0       stevel 	struct opthdr		*req;
    733      0       stevel 	mib_item_t		*first_item = NULL;
    734      0       stevel 	mib_item_t		*last_item  = NULL;
    735      0       stevel 	mib_item_t		*temp;
    736      0       stevel 
    737      0       stevel 	tor->PRIM_type = T_SVR4_OPTMGMT_REQ;
    738      0       stevel 	tor->OPT_offset = sizeof (struct T_optmgmt_req);
    739      0       stevel 	tor->OPT_length = sizeof (struct opthdr);
    740      0       stevel 	tor->MGMT_flags = T_CURRENT;
    741   8485        Peter 
    742   8485        Peter 
    743   8485        Peter 	/*
    744   8485        Peter 	 * Note: we use the special level value below so that IP will return
    745   8485        Peter 	 * us information concerning IRE_MARK_TESTHIDDEN routes.
    746   8485        Peter 	 */
    747      0       stevel 	req = (struct opthdr *)&tor[1];
    748  11042         Erik 	req->level = EXPER_IP_AND_ALL_IRES;
    749      0       stevel 	req->name  = 0;
    750      0       stevel 	req->len   = 0;
    751      0       stevel 
    752      0       stevel 	ctlbuf.buf = (char *)buf;
    753      0       stevel 	ctlbuf.len = tor->OPT_length + tor->OPT_offset;
    754      0       stevel 	flags = 0;
    755      0       stevel 	if (putmsg(sd, &ctlbuf, (struct strbuf *)0, flags) == -1) {
    756      0       stevel 		perror("mibget: putmsg(ctl) failed");
    757      0       stevel 		goto error_exit;
    758      0       stevel 	}
    759      0       stevel 
    760      0       stevel 	/*
    761      0       stevel 	 * Each reply consists of a ctl part for one fixed structure
    762      0       stevel 	 * or table, as defined in mib2.h.  The format is a T_OPTMGMT_ACK,
    763      0       stevel 	 * containing an opthdr structure.  level/name identify the entry,
    764      0       stevel 	 * len is the size of the data part of the message.
    765      0       stevel 	 */
    766      0       stevel 	req = (struct opthdr *)&toa[1];
    767      0       stevel 	ctlbuf.maxlen = sizeof (buf);
    768      0       stevel 	j = 1;
    769      0       stevel 	for (;;) {
    770      0       stevel 		flags = 0;
    771      0       stevel 		getcode = getmsg(sd, &ctlbuf, (struct strbuf *)0, &flags);
    772      0       stevel 		if (getcode == -1) {
    773      0       stevel 			perror("mibget getmsg(ctl) failed");
    774  11042         Erik 			if (Xflag) {
    775      0       stevel 				(void) fputs("#   level   name    len\n",
    776      0       stevel 				    stderr);
    777      0       stevel 				i = 0;
    778      0       stevel 				for (last_item = first_item; last_item;
    779   8485        Peter 				    last_item = last_item->next_item)
    780      0       stevel 					(void) printf("%d  %4d   %5d   %d\n",
    781      0       stevel 					    ++i,
    782      0       stevel 					    last_item->group,
    783      0       stevel 					    last_item->mib_id,
    784      0       stevel 					    last_item->length);
    785      0       stevel 			}
    786      0       stevel 			goto error_exit;
    787      0       stevel 		}
    788      0       stevel 		if (getcode == 0 &&
    789      0       stevel 		    ctlbuf.len >= sizeof (struct T_optmgmt_ack) &&
    790      0       stevel 		    toa->PRIM_type == T_OPTMGMT_ACK &&
    791      0       stevel 		    toa->MGMT_flags == T_SUCCESS &&
    792      0       stevel 		    req->len == 0) {
    793  11042         Erik 			if (Xflag)
    794      0       stevel 				(void) printf("mibget getmsg() %d returned "
    795      0       stevel 				    "EOD (level %ld, name %ld)\n",
    796      0       stevel 				    j, req->level, req->name);
    797      0       stevel 			return (first_item);		/* this is EOD msg */
    798      0       stevel 		}
    799      0       stevel 
    800      0       stevel 		if (ctlbuf.len >= sizeof (struct T_error_ack) &&
    801      0       stevel 		    tea->PRIM_type == T_ERROR_ACK) {
    802      0       stevel 			(void) fprintf(stderr,
    803      0       stevel 			    "mibget %d gives T_ERROR_ACK: TLI_error = 0x%lx, "
    804      0       stevel 			    "UNIX_error = 0x%lx\n",
    805      0       stevel 			    j, tea->TLI_error, tea->UNIX_error);
    806      0       stevel 
    807      0       stevel 			errno = (tea->TLI_error == TSYSERR) ?
    808      0       stevel 			    tea->UNIX_error : EPROTO;
    809      0       stevel 			goto error_exit;
    810      0       stevel 		}
    811      0       stevel 
    812      0       stevel 		if (getcode != MOREDATA ||
    813      0       stevel 		    ctlbuf.len < sizeof (struct T_optmgmt_ack) ||
    814      0       stevel 		    toa->PRIM_type != T_OPTMGMT_ACK ||
    815      0       stevel 		    toa->MGMT_flags != T_SUCCESS) {
    816      0       stevel 			(void) printf("mibget getmsg(ctl) %d returned %d, "
    817      0       stevel 			    "ctlbuf.len = %d, PRIM_type = %ld\n",
    818      0       stevel 			    j, getcode, ctlbuf.len, toa->PRIM_type);
    819      0       stevel 
    820      0       stevel 			if (toa->PRIM_type == T_OPTMGMT_ACK)
    821      0       stevel 				(void) printf("T_OPTMGMT_ACK: "
    822      0       stevel 				    "MGMT_flags = 0x%lx, req->len = %ld\n",
    823      0       stevel 				    toa->MGMT_flags, req->len);
    824      0       stevel 			errno = ENOMSG;
    825      0       stevel 			goto error_exit;
    826      0       stevel 		}
    827      0       stevel 
    828      0       stevel 		temp = (mib_item_t *)malloc(sizeof (mib_item_t));
    829      0       stevel 		if (temp == NULL) {
    830      0       stevel 			perror("mibget malloc failed");
    831      0       stevel 			goto error_exit;
    832      0       stevel 		}
    833      0       stevel 		if (last_item != NULL)
    834      0       stevel 			last_item->next_item = temp;
    835      0       stevel 		else
    836      0       stevel 			first_item = temp;
    837      0       stevel 		last_item = temp;
    838      0       stevel 		last_item->next_item = NULL;
    839      0       stevel 		last_item->group = req->level;
    840      0       stevel 		last_item->mib_id = req->name;
    841      0       stevel 		last_item->length = req->len;
    842      0       stevel 		last_item->valp = malloc((int)req->len);
    843      0       stevel 		if (last_item->valp == NULL)
    844      0       stevel 			goto error_exit;
    845  11042         Erik 		if (Xflag)
    846      0       stevel 			(void) printf("msg %d: group = %4d   mib_id = %5d"
    847      0       stevel 			    "length = %d\n",
    848      0       stevel 			    j, last_item->group, last_item->mib_id,
    849      0       stevel 			    last_item->length);
    850      0       stevel 
    851      0       stevel 		databuf.maxlen = last_item->length;
    852      0       stevel 		databuf.buf    = (char *)last_item->valp;
    853      0       stevel 		databuf.len    = 0;
    854      0       stevel 		flags = 0;
    855      0       stevel 		getcode = getmsg(sd, (struct strbuf *)0, &databuf, &flags);
    856      0       stevel 		if (getcode == -1) {
    857      0       stevel 			perror("mibget getmsg(data) failed");
    858      0       stevel 			goto error_exit;
    859      0       stevel 		} else if (getcode != 0) {
    860      0       stevel 			(void) printf("mibget getmsg(data) returned %d, "
    861      0       stevel 			    "databuf.maxlen = %d, databuf.len = %d\n",
    862      0       stevel 			    getcode, databuf.maxlen, databuf.len);
    863      0       stevel 			goto error_exit;
    864      0       stevel 		}
    865      0       stevel 		j++;
    866      0       stevel 	}
    867      0       stevel 	/* NOTREACHED */
    868      0       stevel 
    869      0       stevel error_exit:;
    870      0       stevel 	mibfree(first_item);
    871      0       stevel 	return (NULL);
    872      0       stevel }
    873      0       stevel 
    874      0       stevel /*
    875      0       stevel  * mibfree: frees a linked list of type (mib_item_t *)
    876      0       stevel  * returned by mibget(); this is NOT THE SAME AS
    877      0       stevel  * mib_item_destroy(), so should be used for objects
    878      0       stevel  * returned by mibget() only
    879      0       stevel  */
    880      0       stevel static void
    881      0       stevel mibfree(mib_item_t *firstitem)
    882      0       stevel {
    883      0       stevel 	mib_item_t *lastitem;
    884      0       stevel 
    885      0       stevel 	while (firstitem != NULL) {
    886      0       stevel 		lastitem = firstitem;
    887      0       stevel 		firstitem = firstitem->next_item;
    888      0       stevel 		if (lastitem->valp != NULL)
    889      0       stevel 			free(lastitem->valp);
    890      0       stevel 		free(lastitem);
    891      0       stevel 	}
    892      0       stevel }
    893      0       stevel 
    894      0       stevel static int
    895      0       stevel mibopen(void)
    896      0       stevel {
    897      0       stevel 	int	sd;
    898      0       stevel 
    899      0       stevel 	sd = open("/dev/arp", O_RDWR);
    900      0       stevel 	if (sd == -1) {
    901      0       stevel 		perror("arp open");
    902      0       stevel 		return (-1);
    903      0       stevel 	}
    904      0       stevel 	if (ioctl(sd, I_PUSH, "tcp") == -1) {
    905      0       stevel 		perror("tcp I_PUSH");
    906      0       stevel 		(void) close(sd);
    907      0       stevel 		return (-1);
    908      0       stevel 	}
    909      0       stevel 	if (ioctl(sd, I_PUSH, "udp") == -1) {
    910      0       stevel 		perror("udp I_PUSH");
    911      0       stevel 		(void) close(sd);
    912      0       stevel 		return (-1);
    913      0       stevel 	}
    914      0       stevel 	if (ioctl(sd, I_PUSH, "icmp") == -1) {
    915      0       stevel 		perror("icmp I_PUSH");
    916      0       stevel 		(void) close(sd);
    917      0       stevel 		return (-1);
    918      0       stevel 	}
    919      0       stevel 	return (sd);
    920      0       stevel }
    921      0       stevel 
    922      0       stevel /*
    923      0       stevel  * mib_item_dup: returns a clean mib_item_t * linked
    924      0       stevel  * list, so that for every element item->mib_id is 0;
    925      0       stevel  * to deallocate this linked list, use mib_item_destroy
    926      0       stevel  */
    927      0       stevel static mib_item_t *
    928      0       stevel mib_item_dup(mib_item_t *item)
    929      0       stevel {
    930      0       stevel 	int	c = 0;
    931      0       stevel 	mib_item_t *localp;
    932      0       stevel 	mib_item_t *tempp;
    933      0       stevel 
    934      0       stevel 	for (tempp = item; tempp; tempp = tempp->next_item)
    935      0       stevel 		if (tempp->mib_id == 0)
    936      0       stevel 			c++;
    937      0       stevel 	tempp = NULL;
    938      0       stevel 
    939      0       stevel 	localp = (mib_item_t *)malloc(c * sizeof (mib_item_t));
    940      0       stevel 	if (localp == NULL)
    941      0       stevel 		return (NULL);
    942      0       stevel 	c = 0;
    943      0       stevel 	for (; item; item = item->next_item) {
    944      0       stevel 		if (item->mib_id == 0) {
    945      0       stevel 			/* Replicate item in localp */
    946      0       stevel 			(localp[c]).next_item = NULL;
    947      0       stevel 			(localp[c]).group = item->group;
    948      0       stevel 			(localp[c]).mib_id = item->mib_id;
    949      0       stevel 			(localp[c]).length = item->length;
    950      0       stevel 			(localp[c]).valp = (uintptr_t *)malloc(
    951      0       stevel 			    item->length);
    952      0       stevel 			if ((localp[c]).valp == NULL) {
    953      0       stevel 				mib_item_destroy(&localp);
    954      0       stevel 				return (NULL);
    955      0       stevel 			}
    956      0       stevel 			(void *) memcpy((localp[c]).valp,
    957      0       stevel 			    item->valp,
    958      0       stevel 			    item->length);
    959      0       stevel 			tempp = &(localp[c]);
    960      0       stevel 			if (c > 0)
    961      0       stevel 				(localp[c - 1]).next_item = tempp;
    962      0       stevel 			c++;
    963      0       stevel 		}
    964      0       stevel 	}
    965      0       stevel 	return (localp);
    966      0       stevel }
    967      0       stevel 
    968      0       stevel /*
    969      0       stevel  * mib_item_diff: takes two (mib_item_t *) linked lists
    970      0       stevel  * item1 and item2 and computes the difference between
    971      0       stevel  * differentiable values in item2 against item1 for every
    972      0       stevel  * given member of item2; returns an mib_item_t * linked
    973      0       stevel  * list of diff's, or a copy of item2 if item1 is NULL;
    974      0       stevel  * will return NULL if system out of memory; works only
    975      0       stevel  * for item->mib_id == 0
    976      0       stevel  */
    977      0       stevel static mib_item_t *
    978      0       stevel mib_item_diff(mib_item_t *item1, mib_item_t *item2) {
    979      0       stevel 	int	nitems	= 0; /* no. of items in item2 */
    980      0       stevel 	mib_item_t *tempp2;  /* walking copy of item2 */
    981      0       stevel 	mib_item_t *tempp1;  /* walking copy of item1 */
    982      0       stevel 	mib_item_t *diffp;
    983      0       stevel 	mib_item_t *diffptr; /* walking copy of diffp */
    984      0       stevel 	mib_item_t *prevp = NULL;
    985      0       stevel 
    986      0       stevel 	if (item1 == NULL) {
    987      0       stevel 		diffp = mib_item_dup(item2);
    988      0       stevel 		return (diffp);
    989      0       stevel 	}
    990      0       stevel 
    991      0       stevel 	for (tempp2 = item2;
    992      0       stevel 	    tempp2;
    993      0       stevel 	    tempp2 = tempp2->next_item) {
    994      0       stevel 		if (tempp2->mib_id == 0)
    995      0       stevel 			switch (tempp2->group) {
    996      0       stevel 			/*
    997      0       stevel 			 * upon adding a case here, the same
    998      0       stevel 			 * must also be added in the next
    999      0       stevel 			 * switch statement, alongwith
   1000      0       stevel 			 * appropriate code
   1001      0       stevel 			 */
   1002      0       stevel 			case MIB2_IP:
   1003      0       stevel 			case MIB2_IP6:
   1004      0       stevel 			case EXPER_DVMRP:
   1005      0       stevel 			case EXPER_IGMP:
   1006      0       stevel 			case MIB2_ICMP:
   1007      0       stevel 			case MIB2_ICMP6:
   1008      0       stevel 			case MIB2_TCP:
   1009      0       stevel 			case MIB2_UDP:
   1010      0       stevel 			case MIB2_SCTP:
   1011      0       stevel 			case EXPER_RAWIP:
   1012      0       stevel 				nitems++;
   1013      0       stevel 			}
   1014      0       stevel 	}
   1015      0       stevel 	tempp2 = NULL;
   1016      0       stevel 	if (nitems == 0) {
   1017      0       stevel 		diffp = mib_item_dup(item2);
   1018      0       stevel 		return (diffp);
   1019      0       stevel 	}
   1020      0       stevel 
   1021      0       stevel 	diffp = (mib_item_t *)calloc(nitems, sizeof (mib_item_t));
   1022      0       stevel 	if (diffp == NULL)
   1023      0       stevel 		return (NULL);
   1024      0       stevel 	diffptr = diffp;
   1025      0       stevel 	/* 'for' loop 1: */
   1026      0       stevel 	for (tempp2 = item2; tempp2 != NULL; tempp2 = tempp2->next_item) {
   1027      0       stevel 		if (tempp2->mib_id != 0)
   1028      0       stevel 			continue; /* 'for' loop 1 */
   1029      0       stevel 		/* 'for' loop 2: */
   1030      0       stevel 		for (tempp1 = item1; tempp1 != NULL;
   1031      0       stevel 		    tempp1 = tempp1->next_item) {
   1032      0       stevel 			if (!(tempp1->mib_id == 0 &&
   1033      0       stevel 			    tempp1->group == tempp2->group &&
   1034      0       stevel 			    tempp1->mib_id == tempp2->mib_id))
   1035      0       stevel 				continue; /* 'for' loop 2 */
   1036      0       stevel 			/* found comparable data sets */
   1037      0       stevel 			if (prevp != NULL)
   1038      0       stevel 				prevp->next_item = diffptr;
   1039      0       stevel 			switch (tempp2->group) {
   1040      0       stevel 			/*
   1041      0       stevel 			 * Indenting note: Because of long variable names
   1042      0       stevel 			 * in cases MIB2_IP6 and MIB2_ICMP6, their contents
   1043      0       stevel 			 * have been indented by one tab space only
   1044      0       stevel 			 */
   1045      0       stevel 			case MIB2_IP: {
   1046      0       stevel 				mib2_ip_t *i2 = (mib2_ip_t *)tempp2->valp;
   1047      0       stevel 				mib2_ip_t *i1 = (mib2_ip_t *)tempp1->valp;
   1048      0       stevel 				mib2_ip_t *d;
   1049      0       stevel 
   1050      0       stevel 				diffptr->group = tempp2->group;
   1051      0       stevel 				diffptr->mib_id = tempp2->mib_id;
   1052      0       stevel 				diffptr->length = tempp2->length;
   1053      0       stevel 				d = (mib2_ip_t *)calloc(tempp2->length, 1);
   1054      0       stevel 				if (d == NULL)
   1055      0       stevel 					goto mibdiff_out_of_memory;
   1056      0       stevel 				diffptr->valp = d;
   1057      0       stevel 				d->ipForwarding = i2->ipForwarding;
   1058      0       stevel 				d->ipDefaultTTL = i2->ipDefaultTTL;
   1059      0       stevel 				MDIFF(d, i2, i1, ipInReceives);
   1060      0       stevel 				MDIFF(d, i2, i1, ipInHdrErrors);
   1061      0       stevel 				MDIFF(d, i2, i1, ipInAddrErrors);
   1062      0       stevel 				MDIFF(d, i2, i1, ipInCksumErrs);
   1063      0       stevel 				MDIFF(d, i2, i1, ipForwDatagrams);
   1064      0       stevel 				MDIFF(d, i2, i1, ipForwProhibits);
   1065      0       stevel 				MDIFF(d, i2, i1, ipInUnknownProtos);
   1066      0       stevel 				MDIFF(d, i2, i1, ipInDiscards);
   1067      0       stevel 				MDIFF(d, i2, i1, ipInDelivers);
   1068      0       stevel 				MDIFF(d, i2, i1, ipOutRequests);
   1069      0       stevel 				MDIFF(d, i2, i1, ipOutDiscards);
   1070      0       stevel 				MDIFF(d, i2, i1, ipOutNoRoutes);
   1071      0       stevel 				MDIFF(d, i2, i1, ipReasmTimeout);
   1072      0       stevel 				MDIFF(d, i2, i1, ipReasmReqds);
   1073      0       stevel 				MDIFF(d, i2, i1, ipReasmOKs);
   1074      0       stevel 				MDIFF(d, i2, i1, ipReasmFails);
   1075      0       stevel 				MDIFF(d, i2, i1, ipReasmDuplicates);
   1076      0       stevel 				MDIFF(d, i2, i1, ipReasmPartDups);
   1077      0       stevel 				MDIFF(d, i2, i1, ipFragOKs);
   1078      0       stevel 				MDIFF(d, i2, i1, ipFragFails);
   1079      0       stevel 				MDIFF(d, i2, i1, ipFragCreates);
   1080      0       stevel 				MDIFF(d, i2, i1, ipRoutingDiscards);
   1081      0       stevel 				MDIFF(d, i2, i1, tcpInErrs);
   1082      0       stevel 				MDIFF(d, i2, i1, udpNoPorts);
   1083      0       stevel 				MDIFF(d, i2, i1, udpInCksumErrs);
   1084      0       stevel 				MDIFF(d, i2, i1, udpInOverflows);
   1085      0       stevel 				MDIFF(d, i2, i1, rawipInOverflows);
   1086      0       stevel 				MDIFF(d, i2, i1, ipsecInSucceeded);
   1087      0       stevel 				MDIFF(d, i2, i1, ipsecInFailed);
   1088      0       stevel 				MDIFF(d, i2, i1, ipInIPv6);
   1089      0       stevel 				MDIFF(d, i2, i1, ipOutIPv6);
   1090      0       stevel 				MDIFF(d, i2, i1, ipOutSwitchIPv6);
   1091      0       stevel 				prevp = diffptr++;
   1092      0       stevel 				break;
   1093      0       stevel 			}
   1094      0       stevel 			case MIB2_IP6: {
   1095      0       stevel 			mib2_ipv6IfStatsEntry_t *i2;
   1096      0       stevel 			mib2_ipv6IfStatsEntry_t *i1;
   1097      0       stevel 			mib2_ipv6IfStatsEntry_t *d;
   1098      0       stevel 
   1099      0       stevel 			i2 = (mib2_ipv6IfStatsEntry_t *)tempp2->valp;
   1100      0       stevel 			i1 = (mib2_ipv6IfStatsEntry_t *)tempp1->valp;
   1101      0       stevel 			diffptr->group = tempp2->group;
   1102      0       stevel 			diffptr->mib_id = tempp2->mib_id;
   1103      0       stevel 			diffptr->length = tempp2->length;
   1104      0       stevel 			d = (mib2_ipv6IfStatsEntry_t *)calloc(
   1105      0       stevel 			    tempp2->length, 1);
   1106      0       stevel 			if (d == NULL)
   1107      0       stevel 				goto mibdiff_out_of_memory;
   1108      0       stevel 			diffptr->valp = d;
   1109      0       stevel 			d->ipv6Forwarding = i2->ipv6Forwarding;
   1110      0       stevel 			d->ipv6DefaultHopLimit =
   1111      0       stevel 			    i2->ipv6DefaultHopLimit;
   1112      0       stevel 
   1113      0       stevel 			MDIFF(d, i2, i1, ipv6InReceives);
   1114      0       stevel 			MDIFF(d, i2, i1, ipv6InHdrErrors);
   1115      0       stevel 			MDIFF(d, i2, i1, ipv6InTooBigErrors);
   1116      0       stevel 			MDIFF(d, i2, i1, ipv6InNoRoutes);
   1117      0       stevel 			MDIFF(d, i2, i1, ipv6InAddrErrors);
   1118      0       stevel 			MDIFF(d, i2, i1, ipv6InUnknownProtos);
   1119      0       stevel 			MDIFF(d, i2, i1, ipv6InTruncatedPkts);
   1120      0       stevel 			MDIFF(d, i2, i1, ipv6InDiscards);
   1121      0       stevel 			MDIFF(d, i2, i1, ipv6InDelivers);
   1122      0       stevel 			MDIFF(d, i2, i1, ipv6OutForwDatagrams);
   1123      0       stevel 			MDIFF(d, i2, i1, ipv6OutRequests);
   1124      0       stevel 			MDIFF(d, i2, i1, ipv6OutDiscards);
   1125      0       stevel 			MDIFF(d, i2, i1, ipv6OutNoRoutes);
   1126      0       stevel 			MDIFF(d, i2, i1, ipv6OutFragOKs);
   1127      0       stevel 			MDIFF(d, i2, i1, ipv6OutFragFails);
   1128      0       stevel 			MDIFF(d, i2, i1, ipv6OutFragCreates);
   1129      0       stevel 			MDIFF(d, i2, i1, ipv6ReasmReqds);
   1130      0       stevel 			MDIFF(d, i2, i1, ipv6ReasmOKs);
   1131      0       stevel 			MDIFF(d, i2, i1, ipv6ReasmFails);
   1132      0       stevel 			MDIFF(d, i2, i1, ipv6InMcastPkts);
   1133      0       stevel 			MDIFF(d, i2, i1, ipv6OutMcastPkts);
   1134      0       stevel 			MDIFF(d, i2, i1, ipv6ReasmDuplicates);
   1135      0       stevel 			MDIFF(d, i2, i1, ipv6ReasmPartDups);
   1136      0       stevel 			MDIFF(d, i2, i1, ipv6ForwProhibits);
   1137      0       stevel 			MDIFF(d, i2, i1, udpInCksumErrs);
   1138      0       stevel 			MDIFF(d, i2, i1, udpInOverflows);
   1139      0       stevel 			MDIFF(d, i2, i1, rawipInOverflows);
   1140      0       stevel 			MDIFF(d, i2, i1, ipv6InIPv4);
   1141      0       stevel 			MDIFF(d, i2, i1, ipv6OutIPv4);
   1142      0       stevel 			MDIFF(d, i2, i1, ipv6OutSwitchIPv4);
   1143      0       stevel 			prevp = diffptr++;
   1144      0       stevel 			break;
   1145      0       stevel 			}
   1146      0       stevel 			case EXPER_DVMRP: {
   1147      0       stevel 				struct mrtstat *m2;
   1148      0       stevel 				struct mrtstat *m1;
   1149      0       stevel 				struct mrtstat *d;
   1150      0       stevel 
   1151      0       stevel 				m2 = (struct mrtstat *)tempp2->valp;
   1152      0       stevel 				m1 = (struct mrtstat *)tempp1->valp;
   1153      0       stevel 				diffptr->group = tempp2->group;
   1154      0       stevel 				diffptr->mib_id = tempp2->mib_id;
   1155      0       stevel 				diffptr->length = tempp2->length;
   1156      0       stevel 				d = (struct mrtstat *)calloc(tempp2->length, 1);
   1157      0       stevel 				if (d == NULL)
   1158      0       stevel 					goto mibdiff_out_of_memory;
   1159      0       stevel 				diffptr->valp = d;
   1160      0       stevel 				MDIFF(d, m2, m1, mrts_mfc_hits);
   1161      0       stevel 				MDIFF(d, m2, m1, mrts_mfc_misses);
   1162      0       stevel 				MDIFF(d, m2, m1, mrts_fwd_in);
   1163      0       stevel 				MDIFF(d, m2, m1, mrts_fwd_out);
   1164      0       stevel 				d->mrts_upcalls = m2->mrts_upcalls;
   1165      0       stevel 				MDIFF(d, m2, m1, mrts_fwd_drop);
   1166      0       stevel 				MDIFF(d, m2, m1, mrts_bad_tunnel);
   1167      0       stevel 				MDIFF(d, m2, m1, mrts_cant_tunnel);
   1168      0       stevel 				MDIFF(d, m2, m1, mrts_wrong_if);
   1169      0       stevel 				MDIFF(d, m2, m1, mrts_upq_ovflw);
   1170      0       stevel 				MDIFF(d, m2, m1, mrts_cache_cleanups);
   1171      0       stevel 				MDIFF(d, m2, m1, mrts_drop_sel);
   1172      0       stevel 				MDIFF(d, m2, m1, mrts_q_overflow);
   1173      0       stevel 				MDIFF(d, m2, m1, mrts_pkt2large);
   1174      0       stevel 				MDIFF(d, m2, m1, mrts_pim_badversion);
   1175      0       stevel 				MDIFF(d, m2, m1, mrts_pim_rcv_badcsum);
   1176      0       stevel 				MDIFF(d, m2, m1, mrts_pim_badregisters);
   1177      0       stevel 				MDIFF(d, m2, m1, mrts_pim_regforwards);
   1178      0       stevel 				MDIFF(d, m2, m1, mrts_pim_regsend_drops);
   1179      0       stevel 				MDIFF(d, m2, m1, mrts_pim_malformed);
   1180      0       stevel 				MDIFF(d, m2, m1, mrts_pim_nomemory);
   1181      0       stevel 				prevp = diffptr++;
   1182      0       stevel 				break;
   1183      0       stevel 			}
   1184      0       stevel 			case EXPER_IGMP: {
   1185      0       stevel 				struct igmpstat *i2;
   1186      0       stevel 				struct igmpstat *i1;
   1187      0       stevel 				struct igmpstat *d;
   1188      0       stevel 
   1189      0       stevel 				i2 = (struct igmpstat *)tempp2->valp;
   1190      0       stevel 				i1 = (struct igmpstat *)tempp1->valp;
   1191      0       stevel 				diffptr->group = tempp2->group;
   1192      0       stevel 				diffptr->mib_id = tempp2->mib_id;
   1193      0       stevel 				diffptr->length = tempp2->length;
   1194      0       stevel 				d = (struct igmpstat *)calloc(
   1195      0       stevel 				    tempp2->length, 1);
   1196      0       stevel 				if (d == NULL)
   1197      0       stevel 					goto mibdiff_out_of_memory;
   1198      0       stevel 				diffptr->valp = d;
   1199      0       stevel 				MDIFF(d, i2, i1, igps_rcv_total);
   1200      0       stevel 				MDIFF(d, i2, i1, igps_rcv_tooshort);
   1201      0       stevel 				MDIFF(d, i2, i1, igps_rcv_badsum);
   1202      0       stevel 				MDIFF(d, i2, i1, igps_rcv_queries);
   1203      0       stevel 				MDIFF(d, i2, i1, igps_rcv_badqueries);
   1204      0       stevel 				MDIFF(d, i2, i1, igps_rcv_reports);
   1205      0       stevel 				MDIFF(d, i2, i1, igps_rcv_badreports);
   1206      0       stevel 				MDIFF(d, i2, i1, igps_rcv_ourreports);
   1207      0       stevel 				MDIFF(d, i2, i1, igps_snd_reports);
   1208      0       stevel 				prevp = diffptr++;
   1209      0       stevel 				break;
   1210      0       stevel 			}
   1211      0       stevel 			case MIB2_ICMP: {
   1212      0       stevel 				mib2_icmp_t *i2;
   1213      0       stevel 				mib2_icmp_t *i1;
   1214      0       stevel 				mib2_icmp_t *d;
   1215      0       stevel 
   1216      0       stevel 				i2 = (mib2_icmp_t *)tempp2->valp;
   1217      0       stevel 				i1 = (mib2_icmp_t *)tempp1->valp;
   1218      0       stevel 				diffptr->group = tempp2->group;
   1219      0       stevel 				diffptr->mib_id = tempp2->mib_id;
   1220      0       stevel 				diffptr->length = tempp2->length;
   1221      0       stevel 				d = (mib2_icmp_t *)calloc(tempp2->length, 1);
   1222      0       stevel 				if (d == NULL)
   1223      0       stevel 					goto mibdiff_out_of_memory;
   1224      0       stevel 				diffptr->valp = d;
   1225      0       stevel 				MDIFF(d, i2, i1, icmpInMsgs);
   1226      0       stevel 				MDIFF(d, i2, i1, icmpInErrors);
   1227      0       stevel 				MDIFF(d, i2, i1, icmpInCksumErrs);
   1228      0       stevel 				MDIFF(d, i2, i1, icmpInUnknowns);
   1229      0       stevel 				MDIFF(d, i2, i1, icmpInDestUnreachs);
   1230      0       stevel 				MDIFF(d, i2, i1, icmpInTimeExcds);
   1231      0       stevel 				MDIFF(d, i2, i1, icmpInParmProbs);
   1232      0       stevel 				MDIFF(d, i2, i1, icmpInSrcQuenchs);
   1233      0       stevel 				MDIFF(d, i2, i1, icmpInRedirects);
   1234      0       stevel 				MDIFF(d, i2, i1, icmpInBadRedirects);
   1235      0       stevel 				MDIFF(d, i2, i1, icmpInEchos);
   1236      0       stevel 				MDIFF(d, i2, i1, icmpInEchoReps);
   1237      0       stevel 				MDIFF(d, i2, i1, icmpInTimestamps);
   1238      0       stevel 				MDIFF(d, i2, i1, icmpInAddrMasks);
   1239      0       stevel 				MDIFF(d, i2, i1, icmpInAddrMaskReps);
   1240      0       stevel 				MDIFF(d, i2, i1, icmpInFragNeeded);
   1241      0       stevel 				MDIFF(d, i2, i1, icmpOutMsgs);
   1242      0       stevel 				MDIFF(d, i2, i1, icmpOutDrops);
   1243      0       stevel 				MDIFF(d, i2, i1, icmpOutErrors);
   1244      0       stevel 				MDIFF(d, i2, i1, icmpOutDestUnreachs);
   1245      0       stevel 				MDIFF(d, i2, i1, icmpOutTimeExcds);
   1246      0       stevel 				MDIFF(d, i2, i1, icmpOutParmProbs);
   1247      0       stevel 				MDIFF(d, i2, i1, icmpOutSrcQuenchs);
   1248      0       stevel 				MDIFF(d, i2, i1, icmpOutRedirects);
   1249      0       stevel 				MDIFF(d, i2, i1, icmpOutEchos);
   1250      0       stevel 				MDIFF(d, i2, i1, icmpOutEchoReps);
   1251      0       stevel 				MDIFF(d, i2, i1, icmpOutTimestamps);
   1252      0       stevel 				MDIFF(d, i2, i1, icmpOutTimestampReps);
   1253      0       stevel 				MDIFF(d, i2, i1, icmpOutAddrMasks);
   1254      0       stevel 				MDIFF(d, i2, i1, icmpOutAddrMaskReps);
   1255      0       stevel 				MDIFF(d, i2, i1, icmpOutFragNeeded);
   1256      0       stevel 				MDIFF(d, i2, i1, icmpInOverflows);
   1257      0       stevel 				prevp = diffptr++;
   1258      0       stevel 				break;
   1259      0       stevel 			}
   1260      0       stevel 			case MIB2_ICMP6: {
   1261      0       stevel 	mib2_ipv6IfIcmpEntry_t *i2;
   1262      0       stevel 	mib2_ipv6IfIcmpEntry_t *i1;
   1263      0       stevel 	mib2_ipv6IfIcmpEntry_t *d;
   1264      0       stevel 
   1265      0       stevel 	i2 = (mib2_ipv6IfIcmpEntry_t *)tempp2->valp;
   1266      0       stevel 	i1 = (mib2_ipv6IfIcmpEntry_t *)tempp1->valp;
   1267      0       stevel 	diffptr->group = tempp2->group;
   1268      0       stevel 	diffptr->mib_id = tempp2->mib_id;
   1269      0       stevel 	diffptr->length = tempp2->length;
   1270      0       stevel 	d = (mib2_ipv6IfIcmpEntry_t *)calloc(tempp2->length, 1);
   1271      0       stevel 	if (d == NULL)
   1272      0       stevel 		goto mibdiff_out_of_memory;
   1273      0       stevel 	diffptr->valp = d;
   1274      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInMsgs);
   1275      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInErrors);
   1276      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInDestUnreachs);
   1277      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInAdminProhibs);
   1278      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInTimeExcds);
   1279      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInParmProblems);
   1280      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInPktTooBigs);
   1281      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInEchos);
   1282      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInEchoReplies);
   1283      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInRouterSolicits);
   1284      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInRouterAdvertisements);
   1285      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInNeighborSolicits);
   1286      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInNeighborAdvertisements);
   1287      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInRedirects);
   1288      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInBadRedirects);
   1289      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembQueries);
   1290      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembResponses);
   1291      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInGroupMembReductions);
   1292      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpInOverflows);
   1293      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutMsgs);
   1294      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutErrors);
   1295      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutDestUnreachs);
   1296      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutAdminProhibs);
   1297      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutTimeExcds);
   1298      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutParmProblems);
   1299      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutPktTooBigs);
   1300      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutEchos);
   1301      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutEchoReplies);
   1302      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutRouterSolicits);
   1303      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutRouterAdvertisements);
   1304      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutNeighborSolicits);
   1305      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutNeighborAdvertisements);
   1306      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutRedirects);
   1307      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembQueries);
   1308      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembResponses);
   1309      0       stevel 	MDIFF(d, i2, i1, ipv6IfIcmpOutGroupMembReductions);
   1310      0       stevel 	prevp = diffptr++;
   1311      0       stevel 	break;
   1312      0       stevel 			}
   1313      0       stevel 			case MIB2_TCP: {
   1314      0       stevel 				mib2_tcp_t *t2;
   1315      0       stevel 				mib2_tcp_t *t1;
   1316      0       stevel 				mib2_tcp_t *d;
   1317      0       stevel 
   1318      0       stevel 				t2 = (mib2_tcp_t *)tempp2->valp;
   1319      0       stevel 				t1 = (mib2_tcp_t *)tempp1->valp;
   1320      0       stevel 				diffptr->group = tempp2->group;
   1321      0       stevel 				diffptr->mib_id = tempp2->mib_id;
   1322      0       stevel 				diffptr->length = tempp2->length;
   1323      0       stevel 				d = (mib2_tcp_t *)calloc(tempp2->length, 1);
   1324      0       stevel 				if (d == NULL)
   1325      0       stevel 					goto mibdiff_out_of_memory;
   1326      0       stevel 				diffptr->valp = d;
   1327      0       stevel 				d->tcpRtoMin = t2->tcpRtoMin;
   1328      0       stevel 				d->tcpRtoMax = t2->tcpRtoMax;
   1329      0       stevel 				d->tcpMaxConn = t2->tcpMaxConn;
   1330      0       stevel 				MDIFF(d, t2, t1, tcpActiveOpens);
   1331      0       stevel 				MDIFF(d, t2, t1, tcpPassiveOpens);
   1332      0       stevel 				MDIFF(d, t2, t1, tcpAttemptFails);
   1333      0       stevel 				MDIFF(d, t2, t1, tcpEstabResets);
   1334      0       stevel 				d->tcpCurrEstab = t2->tcpCurrEstab;
   1335   3284     apersson 				MDIFF(d, t2, t1, tcpHCOutSegs);
   1336      0       stevel 				MDIFF(d, t2, t1, tcpOutDataSegs);
   1337      0       stevel 				MDIFF(d, t2, t1, tcpOutDataBytes);
   1338      0       stevel 				MDIFF(d, t2, t1, tcpRetransSegs);
   1339      0       stevel 				MDIFF(d, t2, t1, tcpRetransBytes);
   1340      0       stevel 				MDIFF(d, t2, t1, tcpOutAck);
   1341      0       stevel 				MDIFF(d, t2, t1, tcpOutAckDelayed);
   1342      0       stevel 				MDIFF(d, t2, t1, tcpOutUrg);
   1343      0       stevel 				MDIFF(d, t2, t1, tcpOutWinUpdate);
   1344      0       stevel 				MDIFF(d, t2, t1, tcpOutWinProbe);
   1345      0       stevel 				MDIFF(d, t2, t1, tcpOutControl);
   1346      0       stevel 				MDIFF(d, t2, t1, tcpOutRsts);
   1347      0       stevel 				MDIFF(d, t2, t1, tcpOutFastRetrans);
   1348   3284     apersson 				MDIFF(d, t2, t1, tcpHCInSegs);
   1349      0       stevel 				MDIFF(d, t2, t1, tcpInAckSegs);
   1350      0       stevel 				MDIFF(d, t2, t1, tcpInAckBytes);
   1351      0       stevel 				MDIFF(d, t2, t1, tcpInDupAck);
   1352      0       stevel 				MDIFF(d, t2, t1, tcpInAckUnsent);
   1353      0       stevel 				MDIFF(d, t2, t1, tcpInDataInorderSegs);
   1354      0       stevel 				MDIFF(d, t2, t1, tcpInDataInorderBytes);
   1355      0       stevel 				MDIFF(d, t2, t1, tcpInDataUnorderSegs);
   1356      0       stevel 				MDIFF(d, t2, t1, tcpInDataUnorderBytes);
   1357      0       stevel 				MDIFF(d, t2, t1, tcpInDataDupSegs);
   1358      0       stevel 				MDIFF(d, t2, t1, tcpInDataDupBytes);
   1359      0       stevel 				MDIFF(d, t2, t1, tcpInDataPartDupSegs);
   1360      0       stevel 				MDIFF(d, t2, t1, tcpInDataPartDupBytes);
   1361      0       stevel 				MDIFF(d, t2, t1, tcpInDataPastWinSegs);
   1362      0       stevel 				MDIFF(d, t2, t1, tcpInDataPastWinBytes);
   1363      0       stevel 				MDIFF(d, t2, t1, tcpInWinProbe);
   1364      0       stevel 				MDIFF(d, t2, t1, tcpInWinUpdate);
   1365      0       stevel 				MDIFF(d, t2, t1, tcpInClosed);
   1366      0       stevel 				MDIFF(d, t2, t1, tcpRttNoUpdate);
   1367      0       stevel 				MDIFF(d, t2, t1, tcpRttUpdate);
   1368      0       stevel 				MDIFF(d, t2, t1, tcpTimRetrans);
   1369      0       stevel 				MDIFF(d, t2, t1, tcpTimRetransDrop);
   1370      0       stevel 				MDIFF(d, t2, t1, tcpTimKeepalive);
   1371      0       stevel 				MDIFF(d, t2, t1, tcpTimKeepaliveProbe);
   1372      0       stevel 				MDIFF(d, t2, t1, tcpTimKeepaliveDrop);
   1373      0       stevel 				MDIFF(d, t2, t1, tcpListenDrop);
   1374      0       stevel 				MDIFF(d, t2, t1, tcpListenDropQ0);
   1375      0       stevel 				MDIFF(d, t2, t1, tcpHalfOpenDrop);
   1376      0       stevel 				MDIFF(d, t2, t1, tcpOutSackRetransSegs);
   1377      0       stevel 				prevp = diffptr++;
   1378      0       stevel 				break;
   1379      0       stevel 			}
   1380      0       stevel 			case MIB2_UDP: {
   1381      0       stevel 				mib2_udp_t *u2;
   1382      0       stevel 				mib2_udp_t *u1;
   1383      0       stevel 				mib2_udp_t *d;
   1384      0       stevel 
   1385      0       stevel 				u2 = (mib2_udp_t *)tempp2->valp;
   1386      0       stevel 				u1 = (mib2_udp_t *)tempp1->valp;
   1387      0       stevel 				diffptr->group = tempp2->group;
   1388      0       stevel 				diffptr->mib_id = tempp2->mib_id;
   1389      0       stevel 				diffptr->length = tempp2->length;
   1390      0       stevel 				d = (mib2_udp_t *)calloc(tempp2->length, 1);
   1391      0       stevel 				if (d == NULL)
   1392      0       stevel 					goto mibdiff_out_of_memory;
   1393      0       stevel 				diffptr->valp = d;
   1394   3284     apersson 				MDIFF(d, u2, u1, udpHCInDatagrams);
   1395      0       stevel 				MDIFF(d, u2, u1, udpInErrors);
   1396   3284     apersson 				MDIFF(d, u2, u1, udpHCOutDatagrams);
   1397      0       stevel 				MDIFF(d, u2, u1, udpOutErrors);
   1398      0       stevel 				prevp = diffptr++;
   1399      0       stevel 				break;
   1400      0       stevel 			}
   1401      0       stevel 			case MIB2_SCTP: {
   1402      0       stevel 				mib2_sctp_t *s2;
   1403      0       stevel 				mib2_sctp_t *s1;
   1404      0       stevel 				mib2_sctp_t *d;
   1405      0       stevel 
   1406      0       stevel 				s2 = (mib2_sctp_t *)tempp2->valp;
   1407      0       stevel 				s1 = (mib2_sctp_t *)tempp1->valp;
   1408      0       stevel 				diffptr->group = tempp2->group;
   1409      0       stevel 				diffptr->mib_id = tempp2->mib_id;
   1410      0       stevel 				diffptr->length = tempp2->length;
   1411      0       stevel 				d = (mib2_sctp_t *)calloc(tempp2->length, 1);
   1412      0       stevel 				if (d == NULL)
   1413      0       stevel 					goto mibdiff_out_of_memory;
   1414      0       stevel 				diffptr->valp = d;
   1415      0       stevel 				d->sctpRtoAlgorithm = s2->sctpRtoAlgorithm;
   1416      0       stevel 				d->sctpRtoMin = s2->sctpRtoMin;
   1417      0       stevel 				d->sctpRtoMax = s2->sctpRtoMax;
   1418      0       stevel 				d->sctpRtoInitial = s2->sctpRtoInitial;
   1419      0       stevel 				d->sctpMaxAssocs = s2->sctpMaxAssocs;
   1420      0       stevel 				d->sctpValCookieLife = s2->sctpValCookieLife;
   1421      0       stevel 				d->sctpMaxInitRetr = s2->sctpMaxInitRetr;
   1422      0       stevel 				d->sctpCurrEstab = s2->sctpCurrEstab;
   1423      0       stevel 				MDIFF(d, s2, s1, sctpActiveEstab);
   1424      0       stevel 				MDIFF(d, s2, s1, sctpPassiveEstab);
   1425      0       stevel 				MDIFF(d, s2, s1, sctpAborted);
   1426      0       stevel 				MDIFF(d, s2, s1, sctpShutdowns);
   1427      0       stevel 				MDIFF(d, s2, s1, sctpOutOfBlue);
   1428      0       stevel 				MDIFF(d, s2, s1, sctpChecksumError);
   1429      0       stevel 				MDIFF(d, s2, s1, sctpOutCtrlChunks);
   1430      0       stevel 				MDIFF(d, s2, s1, sctpOutOrderChunks);
   1431      0       stevel 				MDIFF(d, s2, s1, sctpOutUnorderChunks);
   1432      0       stevel 				MDIFF(d, s2, s1, sctpRetransChunks);
   1433      0       stevel 				MDIFF(d, s2, s1, sctpOutAck);
   1434      0       stevel 				MDIFF(d, s2, s1, sctpOutAckDelayed);
   1435      0       stevel 				MDIFF(d, s2, s1, sctpOutWinUpdate);
   1436      0       stevel 				MDIFF(d, s2, s1, sctpOutFastRetrans);
   1437      0       stevel 				MDIFF(d, s2, s1, sctpOutWinProbe);
   1438      0       stevel 				MDIFF(d, s2, s1, sctpInCtrlChunks);
   1439      0       stevel 				MDIFF(d, s2, s1, sctpInOrderChunks);
   1440      0       stevel 				MDIFF(d, s2, s1, sctpInUnorderChunks);
   1441      0       stevel 				MDIFF(d, s2, s1, sctpInAck);
   1442      0       stevel 				MDIFF(d, s2, s1, sctpInDupAck);
   1443      0       stevel 				MDIFF(d, s2, s1, sctpInAckUnsent);
   1444      0       stevel 				MDIFF(d, s2, s1, sctpFragUsrMsgs);
   1445      0       stevel 				MDIFF(d, s2, s1, sctpReasmUsrMsgs);
   1446      0       stevel 				MDIFF(d, s2, s1, sctpOutSCTPPkts);
   1447      0       stevel 				MDIFF(d, s2, s1, sctpInSCTPPkts);
   1448      0       stevel 				MDIFF(d, s2, s1, sctpInInvalidCookie);
   1449      0       stevel 				MDIFF(d, s2, s1, sctpTimRetrans);
   1450      0       stevel 				MDIFF(d, s2, s1, sctpTimRetransDrop);
   1451      0       stevel 				MDIFF(d, s2, s1, sctpTimHeartBeatProbe);
   1452      0       stevel 				MDIFF(d, s2, s1, sctpTimHeartBeatDrop);
   1453      0       stevel 				MDIFF(d, s2, s1, sctpListenDrop);
   1454      0       stevel 				MDIFF(d, s2, s1, sctpInClosed);
   1455      0       stevel 				prevp = diffptr++;
   1456      0       stevel 				break;
   1457      0       stevel 			}
   1458      0       stevel 			case EXPER_RAWIP: {
   1459      0       stevel 				mib2_rawip_t *r2;
   1460      0       stevel 				mib2_rawip_t *r1;
   1461      0       stevel 				mib2_rawip_t *d;
   1462      0       stevel 
   1463      0       stevel 				r2 = (mib2_rawip_t *)tempp2->valp;
   1464      0       stevel 				r1 = (mib2_rawip_t *)tempp1->valp;
   1465      0       stevel 				diffptr->group = tempp2->group;
   1466      0       stevel 				diffptr->mib_id = tempp2->mib_id;
   1467      0       stevel 				diffptr->length = tempp2->length;
   1468      0       stevel 				d = (mib2_rawip_t *)calloc(tempp2->length, 1);
   1469      0       stevel 				if (d == NULL)
   1470      0       stevel 					goto mibdiff_out_of_memory;
   1471      0       stevel 				diffptr->valp = d;
   1472      0       stevel 				MDIFF(d, r2, r1, rawipInDatagrams);
   1473      0       stevel 				MDIFF(d, r2, r1, rawipInErrors);
   1474      0       stevel 				MDIFF(d, r2, r1, rawipInCksumErrs);
   1475      0       stevel 				MDIFF(d, r2, r1, rawipOutDatagrams);
   1476      0       stevel 				MDIFF(d, r2, r1, rawipOutErrors);
   1477      0       stevel 				prevp = diffptr++;
   1478      0       stevel 				break;
   1479      0       stevel 			}
   1480      0       stevel 			/*
   1481      0       stevel 			 * there are more "group" types but they aren't
   1482      0       stevel 			 * required for the -s and -Ms options
   1483      0       stevel 			 */
   1484      0       stevel 			}
   1485      0       stevel 		} /* 'for' loop 2 ends */
   1486      0       stevel 		tempp1 = NULL;
   1487      0       stevel 	} /* 'for' loop 1 ends */
   1488      0       stevel 	tempp2 = NULL;
   1489      0       stevel 	diffptr--;
   1490      0       stevel 	diffptr->next_item = NULL;
   1491      0       stevel 	return (diffp);
   1492      0       stevel 
   1493      0       stevel mibdiff_out_of_memory:;
   1494      0       stevel 	mib_item_destroy(&diffp);
   1495      0       stevel 	return (NULL);
   1496      0       stevel }
   1497      0       stevel 
   1498      0       stevel /*
   1499      0       stevel  * mib_item_destroy: cleans up a mib_item_t *
   1500      0       stevel  * that was created by calling mib_item_dup or
   1501      0       stevel  * mib_item_diff
   1502      0       stevel  */
   1503      0       stevel static void
   1504      0       stevel mib_item_destroy(mib_item_t **itemp) {
   1505      0       stevel 	int	nitems = 0;
   1506      0       stevel 	int	c = 0;
   1507      0       stevel 	mib_item_t *tempp;
   1508      0       stevel 
   1509      0       stevel 	if (itemp == NULL || *itemp == NULL)
   1510      0       stevel 		return;
   1511      0       stevel 
   1512      0       stevel 	for (tempp = *itemp; tempp != NULL; tempp = tempp->next_item)
   1513      0       stevel 		if (tempp->mib_id == 0)
   1514      0       stevel 			nitems++;
   1515      0       stevel 		else
   1516      0       stevel 			return;	/* cannot destroy! */
   1517      0       stevel 
   1518      0       stevel 	if (nitems == 0)
   1519      0       stevel 		return;		/* cannot destroy! */
   1520      0       stevel 
   1521      0       stevel 	for (c = nitems - 1; c >= 0; c--) {
   1522      0       stevel 		if ((itemp[0][c]).valp != NULL)
   1523      0       stevel 			free((itemp[0][c]).valp);
   1524      0       stevel 	}
   1525      0       stevel 	free(*itemp);
   1526      0       stevel 
   1527      0       stevel 	*itemp = NULL;
   1528      0       stevel }
   1529      0       stevel 
   1530      0       stevel /* Compare two Octet_ts.  Return B_TRUE if they match, B_FALSE if not. */
   1531      0       stevel static boolean_t
   1532      0       stevel octetstrmatch(const Octet_t *a, const Octet_t *b)
   1533      0       stevel {
   1534      0       stevel 	if (a == NULL || b == NULL)
   1535      0       stevel 		return (B_FALSE);
   1536      0       stevel 
   1537      0       stevel 	if (a->o_length != b->o_length)
   1538      0       stevel 		return (B_FALSE);
   1539      0       stevel 
   1540      0       stevel 	return (memcmp(a->o_bytes, b->o_bytes, a->o_length) == 0);
   1541      0       stevel }
   1542      0       stevel 
   1543      0       stevel /* If octetstr() changes make an appropriate change to STR_EXPAND */
   1544      0       stevel static char *
   1545   1676          jpk octetstr(const Octet_t *op, int code, char *dst, uint_t dstlen)
   1546      0       stevel {
   1547      0       stevel 	int	i;
   1548      0       stevel 	char	*cp;
   1549      0       stevel 
   1550      0       stevel 	cp = dst;
   1551      0       stevel 	if (op) {
   1552      0       stevel 		for (i = 0; i < op->o_length; i++) {
   1553      0       stevel 			switch (code) {
   1554      0       stevel 			case 'd':
   1555      0       stevel 				if (cp - dst + 4 > dstlen) {
   1556      0       stevel 					*cp = '\0';
   1557      0       stevel 					return (dst);
   1558      0       stevel 				}
   1559      0       stevel 				(void) snprintf(cp, 5, "%d.",
   1560      0       stevel 				    0xff & op->o_bytes[i]);
   1561      0       stevel 				cp = strchr(cp, '\0');
   1562      0       stevel 				break;
   1563      0       stevel 			case 'a':
   1564      0       stevel 				if (cp - dst + 1 > dstlen) {
   1565      0       stevel 					*cp = '\0';
   1566      0       stevel 					return (dst);
   1567      0       stevel 				}
   1568      0       stevel 				*cp++ = op->o_bytes[i];
   1569      0       stevel 				break;
   1570      0       stevel 			case 'h':
   1571      0       stevel 			default:
   1572      0       stevel 				if (cp - dst + 3 > dstlen) {
   1573      0       stevel 					*cp = '\0';
   1574      0       stevel 					return (dst);
   1575      0       stevel 				}
   1576      0       stevel 				(void) snprintf(cp, 4, "%02x:",
   1577      0       stevel 				    0xff & op->o_bytes[i]);
   1578      0       stevel 				cp += 3;
   1579      0       stevel 				break;
   1580      0       stevel 			}
   1581      0       stevel 		}
   1582      0       stevel 	}
   1583      0       stevel 	if (code != 'a' && cp != dst)
   1584      0       stevel 		cp--;
   1585      0       stevel 	*cp = '\0';
   1586      0       stevel 	return (dst);
   1587      0       stevel }
   1588      0       stevel 
   1589   1676          jpk static const char *
   1590   1676          jpk mitcp_state(int state, const mib2_transportMLPEntry_t *attr)
   1591   1676          jpk {
   1592   1676          jpk 	static char tcpsbuf[50];
   1593   1676          jpk 	const char *cp;
   1594      0       stevel 
   1595      0       stevel 	switch (state) {
   1596      0       stevel 	case TCPS_CLOSED:
   1597      0       stevel 		cp = "CLOSED";
   1598      0       stevel 		break;
   1599      0       stevel 	case TCPS_IDLE:
   1600      0       stevel 		cp = "IDLE";
   1601      0       stevel 		break;
   1602      0       stevel 	case TCPS_BOUND:
   1603      0       stevel 		cp = "BOUND";
   1604      0       stevel 		break;
   1605      0       stevel 	case TCPS_LISTEN:
   1606      0       stevel 		cp = "LISTEN";
   1607      0       stevel 		break;
   1608      0       stevel 	case TCPS_SYN_SENT:
   1609      0       stevel 		cp = "SYN_SENT";
   1610      0       stevel 		break;
   1611      0       stevel 	case TCPS_SYN_RCVD:
   1612      0       stevel 		cp = "SYN_RCVD";
   1613      0       stevel 		break;
   1614      0       stevel 	case TCPS_ESTABLISHED:
   1615      0       stevel 		cp = "ESTABLISHED";
   1616      0       stevel 		break;
   1617      0       stevel 	case TCPS_CLOSE_WAIT:
   1618      0       stevel 		cp = "CLOSE_WAIT";
   1619      0       stevel 		break;
   1620      0       stevel 	case TCPS_FIN_WAIT_1:
   1621      0       stevel 		cp = "FIN_WAIT_1";
   1622      0       stevel 		break;
   1623      0       stevel 	case TCPS_CLOSING:
   1624      0       stevel 		cp = "CLOSING";
   1625      0       stevel 		break;
   1626      0       stevel 	case TCPS_LAST_ACK:
   1627      0       stevel 		cp = "LAST_ACK";
   1628      0       stevel 		break;
   1629      0       stevel 	case TCPS_FIN_WAIT_2:
   1630      0       stevel 		cp = "FIN_WAIT_2";
   1631      0       stevel 		break;
   1632      0       stevel 	case TCPS_TIME_WAIT:
   1633      0       stevel 		cp = "TIME_WAIT";
   1634      0       stevel 		break;
   1635      0       stevel 	default:
   1636      0       stevel 		(void) snprintf(tcpsbuf, sizeof (tcpsbuf),
   1637      0       stevel 		    "UnknownState(%d)", state);
   1638      0       stevel 		cp = tcpsbuf;
   1639      0       stevel 		break;
   1640      0       stevel 	}
   1641   1676          jpk 
   1642   1676          jpk 	if (RSECflag && attr != NULL && attr->tme_flags != 0) {
   1643   1676          jpk 		if (cp != tcpsbuf) {
   1644   1676          jpk 			(void) strlcpy(tcpsbuf, cp, sizeof (tcpsbuf));
   1645   1676          jpk 			cp = tcpsbuf;
   1646   1676          jpk 		}
   1647   1676          jpk 		if (attr->tme_flags & MIB2_TMEF_PRIVATE)
   1648   1676          jpk 			(void) strlcat(tcpsbuf, " P", sizeof (tcpsbuf));
   1649   1676          jpk 		if (attr->tme_flags & MIB2_TMEF_SHARED)
   1650   1676          jpk 			(void) strlcat(tcpsbuf, " S", sizeof (tcpsbuf));
   1651   1676          jpk 	}
   1652   1676          jpk 
   1653   1676          jpk 	return (cp);
   1654   1676          jpk }
   1655   1676          jpk 
   1656   1676          jpk static const char *
   1657   1676          jpk miudp_state(int state, const mib2_transportMLPEntry_t *attr)
   1658   1676          jpk {
   1659   1676          jpk 	static char udpsbuf[50];
   1660   1676          jpk 	const char *cp;
   1661   1676          jpk 
   1662   1676          jpk 	switch (state) {
   1663   1676          jpk 	case MIB2_UDP_unbound:
   1664   1676          jpk 		cp = "Unbound";
   1665   1676          jpk 		break;
   1666   1676          jpk 	case MIB2_UDP_idle:
   1667   1676          jpk 		cp = "Idle";
   1668   1676          jpk 		break;
   1669   1676          jpk 	case MIB2_UDP_connected:
   1670   1676          jpk 		cp = "Connected";
   1671   1676          jpk 		break;
   1672   1676          jpk 	default:
   1673   1676          jpk 		(void) snprintf(udpsbuf, sizeof (udpsbuf),
   1674   1676          jpk 		    "Unknown State(%d)", state);
   1675   1676          jpk 		cp = udpsbuf;
   1676   1676          jpk 		break;
   1677   1676          jpk 	}
   1678   1676          jpk 
   1679   1676          jpk 	if (RSECflag && attr != NULL && attr->tme_flags != 0) {
   1680   1676          jpk 		if (cp != udpsbuf) {
   1681   1676          jpk 			(void) strlcpy(udpsbuf, cp, sizeof (udpsbuf));
   1682   1676          jpk 			cp = udpsbuf;
   1683   1676          jpk 		}
   1684   1676          jpk 		if (attr->tme_flags & MIB2_TMEF_PRIVATE)
   1685   1676          jpk 			(void) strlcat(udpsbuf, " P", sizeof (udpsbuf));
   1686   1676          jpk 		if (attr->tme_flags & MIB2_TMEF_SHARED)
   1687   1676          jpk 			(void) strlcat(udpsbuf, " S", sizeof (udpsbuf));
   1688   1676          jpk 	}
   1689   1676          jpk 
   1690      0       stevel 	return (cp);
   1691      0       stevel }
   1692      0       stevel 
   1693      0       stevel static int odd;
   1694      0       stevel 
   1695      0       stevel static void
   1696      0       stevel prval_init(void)
   1697      0       stevel {
   1698      0       stevel 	odd = 0;
   1699      0       stevel }
   1700      0       stevel 
   1701      0       stevel static void
   1702      0       stevel prval(char *str, Counter val)
   1703      0       stevel {
   1704      0       stevel 	(void) printf("\t%-20s=%6u", str, val);
   1705      0       stevel 	if (odd++ & 1)
   1706      0       stevel 		(void) putchar('\n');
   1707      0       stevel }
   1708      0       stevel 
   1709      0       stevel static void
   1710      0       stevel prval64(char *str, Counter64 val)
   1711      0       stevel {
   1712      0       stevel 	(void) printf("\t%-20s=%6llu", str, val);
   1713      0       stevel 	if (odd++ & 1)
   1714      0       stevel 		(void) putchar('\n');
   1715      0       stevel }
   1716      0       stevel 
   1717      0       stevel static void
   1718      0       stevel pr_int_val(char *str, int val)
   1719      0       stevel {
   1720      0       stevel 	(void) printf("\t%-20s=%6d", str, val);
   1721      0       stevel 	if (odd++ & 1)
   1722      0       stevel 		(void) putchar('\n');
   1723      0       stevel }
   1724      0       stevel 
   1725      0       stevel static void
   1726      0       stevel pr_sctp_rtoalgo(char *str, int val)
   1727      0       stevel {
   1728      0       stevel 	(void) printf("\t%-20s=", str);
   1729      0       stevel 	switch (val) {
   1730      0       stevel 		case MIB2_SCTP_RTOALGO_OTHER:
   1731      0       stevel 			(void) printf("%6.6s", "other");
   1732      0       stevel 			break;
   1733      0       stevel 
   1734      0       stevel 		case MIB2_SCTP_RTOALGO_VANJ:
   1735      0       stevel 			(void) printf("%6.6s", "vanj");
   1736      0       stevel 			break;
   1737      0       stevel 
   1738      0       stevel 		default:
   1739      0       stevel 			(void) printf("%6d", val);
   1740      0       stevel 			break;
   1741      0       stevel 	}
   1742      0       stevel 	if (odd++ & 1)
   1743      0       stevel 		(void) putchar('\n');
   1744      0       stevel }
   1745      0       stevel 
   1746      0       stevel static void
   1747      0       stevel prval_end(void)
   1748      0       stevel {
   1749      0       stevel 	if (odd++ & 1)
   1750      0       stevel 		(void) putchar('\n');
   1751      0       stevel }
   1752      0       stevel 
   1753      0       stevel /* Extract constant sizes */
   1754      0       stevel static void
   1755      0       stevel mib_get_constants(mib_item_t *item)
   1756      0       stevel {
   1757      0       stevel 	/* 'for' loop 1: */
   1758      0       stevel 	for (; item; item = item->next_item) {
   1759      0       stevel 		if (item->mib_id != 0)
   1760      0       stevel 			continue; /* 'for' loop 1 */
   1761      0       stevel 
   1762      0       stevel 		switch (item->group) {
   1763      0       stevel 		case MIB2_IP: {
   1764      0       stevel 			mib2_ip_t	*ip = (mib2_ip_t *)item->valp;
   1765      0       stevel 
   1766      0       stevel 			ipAddrEntrySize = ip->ipAddrEntrySize;
   1767      0       stevel 			ipRouteEntrySize = ip->ipRouteEntrySize;
   1768      0       stevel 			ipNetToMediaEntrySize = ip->ipNetToMediaEntrySize;
   1769      0       stevel 			ipMemberEntrySize = ip->ipMemberEntrySize;
   1770      0       stevel 			ipGroupSourceEntrySize = ip->ipGroupSourceEntrySize;
   1771   1676          jpk 			ipRouteAttributeSize = ip->ipRouteAttributeSize;
   1772   1676          jpk 			transportMLPSize = ip->transportMLPSize;
   1773  11042         Erik 			ipDestEntrySize = ip->ipDestEntrySize;
   1774      0       stevel 			assert(IS_P2ALIGNED(ipAddrEntrySize,
   1775   8485        Peter 			    sizeof (mib2_ipAddrEntry_t *)));
   1776   8485        Peter 			assert(IS_P2ALIGNED(ipRouteEntrySize,
   1777   8485        Peter 			    sizeof (mib2_ipRouteEntry_t *)));
   1778   8485        Peter 			assert(IS_P2ALIGNED(ipNetToMediaEntrySize,
   1779   8485        Peter 			    sizeof (mib2_ipNetToMediaEntry_t *)));
   1780   8485        Peter 			assert(IS_P2ALIGNED(ipMemberEntrySize,
   1781   8485        Peter 			    sizeof (ip_member_t *)));
   1782   8485        Peter 			assert(IS_P2ALIGNED(ipGroupSourceEntrySize,
   1783   8485        Peter 			    sizeof (ip_grpsrc_t *)));
   1784   8485        Peter 			assert(IS_P2ALIGNED(ipRouteAttributeSize,
   1785   8485        Peter 			    sizeof (mib2_ipAttributeEntry_t *)));
   1786   8485        Peter 			assert(IS_P2ALIGNED(transportMLPSize,
   1787   8485        Peter 			    sizeof (mib2_transportMLPEntry_t *)));
   1788      0       stevel 			break;
   1789      0       stevel 		}
   1790      0       stevel 		case EXPER_DVMRP: {
   1791      0       stevel 			struct mrtstat	*mrts = (struct mrtstat *)item->valp;
   1792      0       stevel 
   1793      0       stevel 			vifctlSize = mrts->mrts_vifctlSize;
   1794      0       stevel 			mfcctlSize = mrts->mrts_mfcctlSize;
   1795      0       stevel 			assert(IS_P2ALIGNED(vifctlSize,
   1796   8485        Peter 			    sizeof (struct vifclt *)));
   1797   8485        Peter 			assert(IS_P2ALIGNED(mfcctlSize,
   1798   8485        Peter 			    sizeof (struct mfcctl *)));
   1799      0       stevel 			break;
   1800      0       stevel 		}
   1801      0       stevel 		case MIB2_IP6: {
   1802      0       stevel 			mib2_ipv6IfStatsEntry_t *ip6;
   1803      0       stevel 			/* Just use the first entry */
   1804      0       stevel 
   1805      0       stevel 			ip6 = (mib2_ipv6IfStatsEntry_t *)item->valp;
   1806      0       stevel 			ipv6IfStatsEntrySize = ip6->ipv6IfStatsEntrySize;
   1807      0       stevel 			ipv6AddrEntrySize = ip6->ipv6AddrEntrySize;
   1808      0       stevel 			ipv6RouteEntrySize = ip6->ipv6RouteEntrySize;
   1809      0       stevel 			ipv6NetToMediaEntrySize = ip6->ipv6NetToMediaEntrySize;
   1810      0       stevel 			ipv6MemberEntrySize = ip6->ipv6MemberEntrySize;
   1811      0       stevel 			ipv6GroupSourceEntrySize =
   1812      0       stevel 			    ip6->ipv6GroupSourceEntrySize;
   1813      0       stevel 			assert(IS_P2ALIGNED(ipv6IfStatsEntrySize,
   1814   8485        Peter 			    sizeof (mib2_ipv6IfStatsEntry_t *)));
   1815   8485        Peter 			assert(IS_P2ALIGNED(ipv6AddrEntrySize,
   1816   8485        Peter 			    sizeof (mib2_ipv6AddrEntry_t *)));
   1817   8485        Peter 			assert(IS_P2ALIGNED(ipv6RouteEntrySize,
   1818   8485        Peter 			    sizeof (mib2_ipv6RouteEntry_t *)));
   1819   8485        Peter 			assert(IS_P2ALIGNED(ipv6NetToMediaEntrySize,
   1820   8485        Peter 			    sizeof (mib2_ipv6NetToMediaEntry_t *)));
   1821   8485        Peter 			assert(IS_P2ALIGNED(ipv6MemberEntrySize,
   1822   8485        Peter 			    sizeof (ipv6_member_t *)));
   1823   8485        Peter 			assert(IS_P2ALIGNED(ipv6GroupSourceEntrySize,
   1824   8485        Peter 			    sizeof (ipv6_grpsrc_t *)));
   1825      0       stevel 			break;
   1826      0       stevel 		}
   1827      0       stevel 		case MIB2_ICMP6: {
   1828      0       stevel 			mib2_ipv6IfIcmpEntry_t *icmp6;
   1829      0       stevel 			/* Just use the first entry */
   1830      0       stevel 
   1831      0       stevel 			icmp6 = (mib2_ipv6IfIcmpEntry_t *)item->valp;
   1832      0       stevel 			ipv6IfIcmpEntrySize = icmp6->ipv6IfIcmpEntrySize;
   1833      0       stevel 			assert(IS_P2ALIGNED(ipv6IfIcmpEntrySize,
   1834      0       stevel 			    sizeof (mib2_ipv6IfIcmpEntry_t *)));
   1835      0       stevel 			break;
   1836      0       stevel 		}
   1837      0       stevel 		case MIB2_TCP: {
   1838      0       stevel 			mib2_tcp_t	*tcp = (mib2_tcp_t *)item->valp;
   1839      0       stevel 
   1840      0       stevel 			tcpConnEntrySize = tcp->tcpConnTableSize;
   1841      0       stevel 			tcp6ConnEntrySize = tcp->tcp6ConnTableSize;
   1842      0       stevel 			assert(IS_P2ALIGNED(tcpConnEntrySize,
   1843   8485        Peter 			    sizeof (mib2_tcpConnEntry_t *)));
   1844   8485        Peter 			assert(IS_P2ALIGNED(tcp6ConnEntrySize,
   1845   8485        Peter 			    sizeof (mib2_tcp6ConnEntry_t *)));
   1846      0       stevel 			break;
   1847      0       stevel 		}
   1848      0       stevel 		case MIB2_UDP: {
   1849      0       stevel 			mib2_udp_t	*udp = (mib2_udp_t *)item->valp;
   1850      0       stevel 
   1851      0       stevel 			udpEntrySize = udp->udpEntrySize;
   1852      0       stevel 			udp6EntrySize = udp->udp6EntrySize;
   1853      0       stevel 			assert(IS_P2ALIGNED(udpEntrySize,
   1854   8485        Peter 			    sizeof (mib2_udpEntry_t *)));
   1855   8485        Peter 			assert(IS_P2ALIGNED(udp6EntrySize,
   1856   8485        Peter 			    sizeof (mib2_udp6Entry_t *)));
   1857      0       stevel 			break;
   1858      0       stevel 		}
   1859      0       stevel 		case MIB2_SCTP: {
   1860      0       stevel 			mib2_sctp_t	*sctp = (mib2_sctp_t *)item->valp;
   1861      0       stevel 
   1862      0       stevel 			sctpEntrySize = sctp->sctpEntrySize;
   1863      0       stevel 			sctpLocalEntrySize = sctp->sctpLocalEntrySize;
   1864      0       stevel 			sctpRemoteEntrySize = sctp->sctpRemoteEntrySize;
   1865      0       stevel 			break;
   1866      0       stevel 		}
   1867      0       stevel 		}
   1868      0       stevel 	} /* 'for' loop 1 ends */
   1869      0       stevel 
   1870  11042         Erik 	if (Xflag) {
   1871      0       stevel 		(void) puts("mib_get_constants:");
   1872      0       stevel 		(void) printf("\tipv6IfStatsEntrySize %d\n",
   1873      0       stevel 		    ipv6IfStatsEntrySize);
   1874      0       stevel 		(void) printf("\tipAddrEntrySize %d\n", ipAddrEntrySize);
   1875      0       stevel 		(void) printf("\tipRouteEntrySize %d\n", ipRouteEntrySize);
   1876      0       stevel 		(void) printf("\tipNetToMediaEntrySize %d\n",
   1877      0       stevel 		    ipNetToMediaEntrySize);
   1878      0       stevel 		(void) printf("\tipMemberEntrySize %d\n", ipMemberEntrySize);
   1879   1676          jpk 		(void) printf("\tipRouteAttributeSize %d\n",
   1880   1676          jpk 		    ipRouteAttributeSize);
   1881      0       stevel 		(void) printf("\tvifctlSize %d\n", vifctlSize);
   1882      0       stevel 		(void) printf("\tmfcctlSize %d\n", mfcctlSize);
   1883      0       stevel 
   1884      0       stevel 		(void) printf("\tipv6AddrEntrySize %d\n", ipv6AddrEntrySize);
   1885      0       stevel 		(void) printf("\tipv6RouteEntrySize %d\n", ipv6RouteEntrySize);
   1886      0       stevel 		(void) printf("\tipv6NetToMediaEntrySize %d\n",
   1887      0       stevel 		    ipv6NetToMediaEntrySize);
   1888      0       stevel 		(void) printf("\tipv6MemberEntrySize %d\n",
   1889      0       stevel 		    ipv6MemberEntrySize);
   1890      0       stevel 		(void) printf("\tipv6IfIcmpEntrySize %d\n",
   1891      0       stevel 		    ipv6IfIcmpEntrySize);
   1892  11042         Erik 		(void) printf("\tipDestEntrySize %d\n", ipDestEntrySize);
   1893   1676          jpk 		(void) printf("\ttransportMLPSize %d\n", transportMLPSize);
   1894      0       stevel 		(void) printf("\ttcpConnEntrySize %d\n", tcpConnEntrySize);
   1895      0       stevel 		(void) printf("\ttcp6ConnEntrySize %d\n", tcp6ConnEntrySize);
   1896      0       stevel 		(void) printf("\tudpEntrySize %d\n", udpEntrySize);
   1897      0       stevel 		(void) printf("\tudp6EntrySize %d\n", udp6EntrySize);
   1898      0       stevel 		(void) printf("\tsctpEntrySize %d\n", sctpEntrySize);
   1899      0       stevel 		(void) printf("\tsctpLocalEntrySize %d\n", sctpLocalEntrySize);
   1900      0       stevel 		(void) printf("\tsctpRemoteEntrySize %d\n",
   1901      0       stevel 		    sctpRemoteEntrySize);
   1902      0       stevel 	}
   1903      0       stevel }
   1904      0       stevel 
   1905      0       stevel 
   1906      0       stevel /* ----------------------------- STAT_REPORT ------------------------------- */
   1907      0       stevel 
   1908      0       stevel static void
   1909      0       stevel stat_report(mib_item_t *item)
   1910      0       stevel {
   1911      0       stevel 	int	jtemp = 0;
   1912      0       stevel 	char	ifname[LIFNAMSIZ + 1];
   1913      0       stevel 
   1914      0       stevel 	/* 'for' loop 1: */
   1915      0       stevel 	for (; item; item = item->next_item) {
   1916  11042         Erik 		if (Xflag) {
   1917      0       stevel 			(void) printf("\n--- Entry %d ---\n", ++jtemp);
   1918      0       stevel 			(void) printf("Group = %d, mib_id = %d, "
   1919      0       stevel 			    "length = %d, valp = 0x%p\n",
   1920      0       stevel 			    item->group, item->mib_id,
   1921      0       stevel 			    item->length, item->valp);
   1922      0       stevel 		}
   1923      0       stevel 		if (item->mib_id != 0)
   1924      0       stevel 			continue; /* 'for' loop 1 */
   1925      0       stevel 
   1926      0       stevel 		switch (item->group) {
   1927      0       stevel 		case MIB2_IP: {
   1928      0       stevel 			mib2_ip_t	*ip = (mib2_ip_t *)item->valp;
   1929      0       stevel 
   1930      0       stevel 			if (protocol_selected(IPPROTO_IP) &&
   1931      0       stevel 			    family_selected(AF_INET)) {
   1932      0       stevel 				(void) fputs(v4compat ? "\nIP" : "\nIPv4",
   1933      0       stevel 				    stdout);
   1934      0       stevel 				print_ip_stats(ip);
   1935      0       stevel 			}
   1936      0       stevel 			break;
   1937      0       stevel 		}
   1938      0       stevel 		case MIB2_ICMP: {
   1939      0       stevel 			mib2_icmp_t	*icmp =
   1940      0       stevel 			    (mib2_icmp_t *)item->valp;
   1941      0       stevel 
   1942      0       stevel 			if (protocol_selected(IPPROTO_ICMP) &&
   1943      0       stevel 			    family_selected(AF_INET)) {
   1944      0       stevel 				(void) fputs(v4compat ? "\nICMP" : "\nICMPv4",
   1945      0       stevel 				    stdout);
   1946      0       stevel 				print_icmp_stats(icmp);
   1947      0       stevel 			}
   1948      0       stevel 			break;
   1949      0       stevel 		}
   1950      0       stevel 		case MIB2_IP6: {
   1951      0       stevel 			mib2_ipv6IfStatsEntry_t *ip6;
   1952      0       stevel 			mib2_ipv6IfStatsEntry_t sum6;
   1953      0       stevel 
   1954      0       stevel 			if (!(protocol_selected(IPPROTO_IPV6)) ||
   1955      0       stevel 			    !(family_selected(AF_INET6)))
   1956      0       stevel 				break;
   1957      0       stevel 			bzero(&sum6, sizeof (sum6));
   1958      0       stevel 			/* 'for' loop 2a: */
   1959      0       stevel 			for (ip6 = (mib2_ipv6IfStatsEntry_t *)item->valp;
   1960   8485        Peter 			    (char *)ip6 < (char *)item->valp + item->length;
   1961      0       stevel 			    /* LINTED: (note 1) */
   1962      0       stevel 			    ip6 = (mib2_ipv6IfStatsEntry_t *)((char *)ip6 +
   1963      0       stevel 			    ipv6IfStatsEntrySize)) {
   1964      0       stevel 				if (ip6->ipv6IfIndex == 0) {
   1965      0       stevel 					/*
   1966      0       stevel 					 * The "unknown interface" ip6
   1967      0       stevel 					 * mib. Just add to the sum.
   1968      0       stevel 					 */
   1969      0       stevel 					sum_ip6_stats(ip6, &sum6);
   1970      0       stevel 					continue; /* 'for' loop 2a */
   1971      0       stevel 				}
   1972      0       stevel 				if (Aflag) {
   1973      0       stevel 					(void) printf("\nIPv6 for %s\n",
   1974   8485        Peter 					    ifindex2str(ip6->ipv6IfIndex,
   1975   8485        Peter 					    ifname));
   1976      0       stevel 					print_ip6_stats(ip6);
   1977      0       stevel 				}
   1978      0       stevel 				sum_ip6_stats(ip6, &sum6);
   1979      0       stevel 			} /* 'for' loop 2a ends */
   1980      0       stevel 			(void) fputs("\nIPv6", stdout);
   1981      0       stevel 			print_ip6_stats(&sum6);
   1982      0       stevel 			break;
   1983      0       stevel 		}
   1984      0       stevel 		case MIB2_ICMP6: {
   1985      0       stevel 			mib2_ipv6IfIcmpEntry_t *icmp6;
   1986      0       stevel 			mib2_ipv6IfIcmpEntry_t sum6;
   1987      0       stevel 
   1988      0       stevel 			if (!(protocol_selected(IPPROTO_ICMPV6)) ||
   1989      0       stevel 			    !(family_selected(AF_INET6)))
   1990      0       stevel 				break;
   1991      0       stevel 			bzero(&sum6, sizeof (sum6));
   1992      0       stevel 			/* 'for' loop 2b: */
   1993   8485        Peter 			for (icmp6 = (mib2_ipv6IfIcmpEntry_t *)item->valp;
   1994   8485        Peter 			    (char *)icmp6 < (char *)item->valp + item->length;
   1995   8485        Peter 			    icmp6 = (void *)((char *)icmp6 +
   1996   8485        Peter 			    ipv6IfIcmpEntrySize)) {
   1997      0       stevel 				if (icmp6->ipv6IfIcmpIfIndex == 0) {
   1998      0       stevel 					/*
   1999      0       stevel 					 * The "unknown interface" icmp6
   2000      0       stevel 					 * mib. Just add to the sum.
   2001      0       stevel 					 */
   2002      0       stevel 					sum_icmp6_stats(icmp6, &sum6);
   2003      0       stevel 					continue; /* 'for' loop 2b: */
   2004      0       stevel 				}
   2005      0       stevel 				if (Aflag) {
   2006   8485        Peter 					(void) printf("\nICMPv6 for %s\n",
   2007   8485        Peter 					    ifindex2str(
   2008   8485        Peter 					    icmp6->ipv6IfIcmpIfIndex, ifname));
   2009      0       stevel 					print_icmp6_stats(icmp6);
   2010      0       stevel 				}
   2011      0       stevel 				sum_icmp6_stats(icmp6, &sum6);
   2012      0       stevel 			} /* 'for' loop 2b ends */
   2013      0       stevel 			(void) fputs("\nICMPv6", stdout);
   2014      0       stevel 			print_icmp6_stats(&sum6);
   2015      0       stevel 			break;
   2016      0       stevel 		}
   2017      0       stevel 		case MIB2_TCP: {
   2018      0       stevel 			mib2_tcp_t	*tcp = (mib2_tcp_t *)item->valp;
   2019      0       stevel 
   2020      0       stevel 			if (protocol_selected(IPPROTO_TCP) &&
   2021      0       stevel 			    (family_selected(AF_INET) ||
   2022      0       stevel 			    family_selected(AF_INET6))) {
   2023      0       stevel 				(void) fputs("\nTCP", stdout);
   2024      0       stevel 				print_tcp_stats(tcp);
   2025      0       stevel 			}
   2026      0       stevel 			break;
   2027      0       stevel 		}
   2028      0       stevel 		case MIB2_UDP: {
   2029      0       stevel 			mib2_udp_t	*udp = (mib2_udp_t *)item->valp;
   2030      0       stevel 
   2031      0       stevel 			if (protocol_selected(IPPROTO_UDP) &&
   2032      0       stevel 			    (family_selected(AF_INET) ||
   2033      0       stevel 			    family_selected(AF_INET6))) {
   2034      0       stevel 				(void) fputs("\nUDP", stdout);
   2035      0       stevel 				print_udp_stats(udp);
   2036      0       stevel 			}
   2037      0       stevel 			break;
   2038      0       stevel 		}
   2039      0       stevel 		case MIB2_SCTP: {
   2040      0       stevel 			mib2_sctp_t	*sctp = (mib2_sctp_t *)item->valp;
   2041      0       stevel 
   2042      0       stevel 			if (protocol_selected(IPPROTO_SCTP) &&
   2043      0       stevel 			    (family_selected(AF_INET) ||
   2044      0       stevel 			    family_selected(AF_INET6))) {
   2045      0       stevel 				(void) fputs("\nSCTP", stdout);
   2046      0       stevel 				print_sctp_stats(sctp);
   2047      0       stevel 			}
   2048      0       stevel 			break;
   2049      0       stevel 		}
   2050      0       stevel 		case EXPER_RAWIP: {
   2051      0       stevel 			mib2_rawip_t	*rawip =
   2052      0       stevel 			    (mib2_rawip_t *)item->valp;
   2053      0       stevel 
   2054      0       stevel 			if (protocol_selected(IPPROTO_RAW) &&
   2055      0       stevel 			    (family_selected(AF_INET) ||
   2056      0       stevel 			    family_selected(AF_INET6))) {
   2057      0       stevel 				(void) fputs("\nRAWIP", stdout);
   2058      0       stevel 				print_rawip_stats(rawip);
   2059      0       stevel 			}
   2060      0       stevel 			break;
   2061      0       stevel 		}
   2062      0       stevel 		case EXPER_IGMP: {
   2063      0       stevel 			struct igmpstat	*igps =
   2064      0       stevel 			    (struct igmpstat *)item->valp;
   2065      0       stevel 
   2066      0       stevel 			if (protocol_selected(IPPROTO_IGMP) &&
   2067      0       stevel 			    (family_selected(AF_INET))) {
   2068      0       stevel 				(void) fputs("\nIGMP:\n", stdout);
   2069      0       stevel 				print_igmp_stats(igps);
   2070      0       stevel 			}
   2071      0       stevel 			break;
   2072      0       stevel 		}
   2073      0       stevel 		}
   2074      0       stevel 	} /* 'for' loop 1 ends */
   2075      0       stevel 	(void) putchar('\n');
   2076      0       stevel 	(void) fflush(stdout);
   2077      0       stevel }
   2078      0       stevel 
   2079      0       stevel static void
   2080      0       stevel print_ip_stats(mib2_ip_t *ip)
   2081      0       stevel {
   2082      0       stevel 	prval_init();
   2083      0       stevel 	pr_int_val("ipForwarding",	ip->ipForwarding);
   2084      0       stevel 	pr_int_val("ipDefaultTTL",	ip->ipDefaultTTL);
   2085      0       stevel 	prval("ipInReceives",		ip->ipInReceives);
   2086      0       stevel 	prval("ipInHdrErrors",		ip->ipInHdrErrors);
   2087      0       stevel 	prval("ipInAddrErrors",		ip->ipInAddrErrors);
   2088      0       stevel 	prval("ipInCksumErrs",		ip->ipInCksumErrs);
   2089      0       stevel 	prval("ipForwDatagrams",	ip->ipForwDatagrams);
   2090      0       stevel 	prval("ipForwProhibits",	ip->ipForwProhibits);
   2091      0       stevel 	prval("ipInUnknownProtos",	ip->ipInUnknownProtos);
   2092      0       stevel 	prval("ipInDiscards",		ip->ipInDiscards);
   2093      0       stevel 	prval("ipInDelivers",		ip->ipInDelivers);
   2094      0       stevel 	prval("ipOutRequests",		ip->ipOutRequests);
   2095      0       stevel 	prval("ipOutDiscards",		ip->ipOutDiscards);
   2096      0       stevel 	prval("ipOutNoRoutes",		ip->ipOutNoRoutes);
   2097      0       stevel 	pr_int_val("ipReasmTimeout",	ip->ipReasmTimeout);
   2098      0       stevel 	prval("ipReasmReqds",		ip->ipReasmReqds);
   2099      0       stevel 	prval("ipReasmOKs",		ip->ipReasmOKs);
   2100      0       stevel 	prval("ipReasmFails",		ip->ipReasmFails);
   2101      0       stevel 	prval("ipReasmDuplicates",	ip->ipReasmDuplicates);
   2102      0       stevel 	prval("ipReasmPartDups",	ip->ipReasmPartDups);
   2103      0       stevel 	prval("ipFragOKs",		ip->ipFragOKs);
   2104      0       stevel 	prval("ipFragFails",		ip->ipFragFails);
   2105      0       stevel 	prval("ipFragCreates",		ip->ipFragCreates);
   2106      0       stevel 	prval("ipRoutingDiscards",	ip->ipRoutingDiscards);
   2107      0       stevel 
   2108      0       stevel 	prval("tcpInErrs",		ip->tcpInErrs);
   2109      0       stevel 	prval("udpNoPorts",		ip->udpNoPorts);
   2110      0       stevel 	prval("udpInCksumErrs",		ip->udpInCksumErrs);
   2111      0       stevel 	prval("udpInOverflows",		ip->udpInOverflows);
   2112      0       stevel 	prval("rawipInOverflows",	ip->rawipInOverflows);
   2113      0       stevel 	prval("ipsecInSucceeded",	ip->ipsecInSucceeded);
   2114      0       stevel 	prval("ipsecInFailed",		ip->ipsecInFailed);
   2115      0       stevel 	prval("ipInIPv6",		ip->ipInIPv6);
   2116      0       stevel 	prval("ipOutIPv6",		ip->ipOutIPv6);
   2117      0       stevel 	prval("ipOutSwitchIPv6",	ip->ipOutSwitchIPv6);
   2118      0       stevel 	prval_end();
   2119      0       stevel }
   2120      0       stevel 
   2121      0       stevel static void
   2122      0       stevel print_icmp_stats(mib2_icmp_t *icmp)
   2123      0       stevel {
   2124      0       stevel 	prval_init();
   2125      0       stevel 	prval("icmpInMsgs",		icmp->icmpInMsgs);
   2126      0       stevel 	prval("icmpInErrors",		icmp->icmpInErrors);
   2127      0       stevel 	prval("icmpInCksumErrs",	icmp->icmpInCksumErrs);
   2128      0       stevel 	prval("icmpInUnknowns",		icmp->icmpInUnknowns);
   2129      0       stevel 	prval("icmpInDestUnreachs",	icmp->icmpInDestUnreachs);
   2130      0       stevel 	prval("icmpInTimeExcds",	icmp->icmpInTimeExcds);
   2131      0       stevel 	prval("icmpInParmProbs",	icmp->icmpInParmProbs);
   2132      0       stevel 	prval("icmpInSrcQuenchs",	icmp->icmpInSrcQuenchs);
   2133      0       stevel 	prval("icmpInRedirects",	icmp->icmpInRedirects);
   2134      0       stevel 	prval("icmpInBadRedirects",	icmp->icmpInBadRedirects);
   2135      0       stevel 	prval("icmpInEchos",		icmp->icmpInEchos);
   2136      0       stevel 	prval("icmpInEchoReps",		icmp->icmpInEchoReps);
   2137      0       stevel 	prval("icmpInTimestamps",	icmp->icmpInTimestamps);
   2138      0       stevel 	prval("icmpInTimestampReps",	icmp->icmpInTimestampReps);
   2139      0       stevel 	prval("icmpInAddrMasks",	icmp->icmpInAddrMasks);
   2140      0       stevel 	prval("icmpInAddrMaskReps",	icmp->icmpInAddrMaskReps);
   2141      0       stevel 	prval("icmpInFragNeeded",	icmp->icmpInFragNeeded);
   2142      0       stevel 	prval("icmpOutMsgs",		icmp->icmpOutMsgs);
   2143      0       stevel 	prval("icmpOutDrops",		icmp->icmpOutDrops);
   2144      0       stevel 	prval("icmpOutErrors",		icmp->icmpOutErrors);
   2145      0       stevel 	prval("icmpOutDestUnreachs",	icmp->icmpOutDestUnreachs);
   2146      0       stevel 	prval("icmpOutTimeExcds",	icmp->icmpOutTimeExcds);
   2147      0       stevel 	prval("icmpOutParmProbs",	icmp->icmpOutParmProbs);
   2148      0       stevel 	prval("icmpOutSrcQuenchs",	icmp->icmpOutSrcQuenchs);
   2149      0       stevel 	prval("icmpOutRedirects",	icmp->icmpOutRedirects);
   2150      0       stevel 	prval("icmpOutEchos",		icmp->icmpOutEchos);
   2151      0       stevel 	prval("icmpOutEchoReps",	icmp->icmpOutEchoReps);
   2152      0       stevel 	prval("icmpOutTimestamps",	icmp->icmpOutTimestamps);
   2153      0       stevel 	prval("icmpOutTimestampReps",	icmp->icmpOutTimestampReps);
   2154      0       stevel 	prval("icmpOutAddrMasks",	icmp->icmpOutAddrMasks);
   2155      0       stevel 	prval("icmpOutAddrMaskReps",	icmp->icmpOutAddrMaskReps);
   2156      0       stevel 	prval("icmpOutFragNeeded",	icmp->icmpOutFragNeeded);
   2157      0       stevel 	prval("icmpInOverflows",	icmp->icmpInOverflows);
   2158      0       stevel 	prval_end();
   2159      0       stevel }
   2160      0       stevel 
   2161      0       stevel static void
   2162      0       stevel print_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6)
   2163      0       stevel {
   2164      0       stevel 	prval_init();
   2165      0       stevel 	prval("ipv6Forwarding",		ip6->ipv6Forwarding);
   2166      0       stevel 	prval("ipv6DefaultHopLimit",	ip6->ipv6DefaultHopLimit);
   2167      0       stevel 
   2168      0       stevel 	prval("ipv6InReceives",		ip6->ipv6InReceives);
   2169      0       stevel 	prval("ipv6InHdrErrors",	ip6->ipv6InHdrErrors);
   2170      0       stevel 	prval("ipv6InTooBigErrors",	ip6->ipv6InTooBigErrors);
   2171      0       stevel 	prval("ipv6InNoRoutes",		ip6->ipv6InNoRoutes);
   2172      0       stevel 	prval("ipv6InAddrErrors",	ip6->ipv6InAddrErrors);
   2173      0       stevel 	prval("ipv6InUnknownProtos",	ip6->ipv6InUnknownProtos);
   2174      0       stevel 	prval("ipv6InTruncatedPkts",	ip6->ipv6InTruncatedPkts);
   2175      0       stevel 	prval("ipv6InDiscards",		ip6->ipv6InDiscards);
   2176      0       stevel 	prval("ipv6InDelivers",		ip6->ipv6InDelivers);
   2177      0       stevel 	prval("ipv6OutForwDatagrams",	ip6->ipv6OutForwDatagrams);
   2178      0       stevel 	prval("ipv6OutRequests",	ip6->ipv6OutRequests);
   2179      0       stevel 	prval("ipv6OutDiscards",	ip6->ipv6OutDiscards);
   2180      0       stevel 	prval("ipv6OutNoRoutes",	ip6->ipv6OutNoRoutes);
   2181      0       stevel 	prval("ipv6OutFragOKs",		ip6->ipv6OutFragOKs);
   2182      0       stevel 	prval("ipv6OutFragFails",	ip6->ipv6OutFragFails);
   2183      0       stevel 	prval("ipv6OutFragCreates",	ip6->ipv6OutFragCreates);
   2184      0       stevel 	prval("ipv6ReasmReqds",		ip6->ipv6ReasmReqds);
   2185      0       stevel 	prval("ipv6ReasmOKs",		ip6->ipv6ReasmOKs);
   2186      0       stevel 	prval("ipv6ReasmFails",		ip6->ipv6ReasmFails);
   2187      0       stevel 	prval("ipv6InMcastPkts",	ip6->ipv6InMcastPkts);
   2188      0       stevel 	prval("ipv6OutMcastPkts",	ip6->ipv6OutMcastPkts);
   2189      0       stevel 	prval("ipv6ReasmDuplicates",	ip6->ipv6ReasmDuplicates);
   2190      0       stevel 	prval("ipv6ReasmPartDups",	ip6->ipv6ReasmPartDups);
   2191      0       stevel 	prval("ipv6ForwProhibits",	ip6->ipv6ForwProhibits);
   2192      0       stevel 	prval("udpInCksumErrs",		ip6->udpInCksumErrs);
   2193      0       stevel 	prval("udpInOverflows",		ip6->udpInOverflows);
   2194      0       stevel 	prval("rawipInOverflows",	ip6->rawipInOverflows);
   2195      0       stevel 	prval("ipv6InIPv4",		ip6->ipv6InIPv4);
   2196      0       stevel 	prval("ipv6OutIPv4",		ip6->ipv6OutIPv4);
   2197      0       stevel 	prval("ipv6OutSwitchIPv4",	ip6->ipv6OutSwitchIPv4);
   2198      0       stevel 	prval_end();
   2199      0       stevel }
   2200      0       stevel 
   2201      0       stevel static void
   2202      0       stevel print_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6)
   2203      0       stevel {
   2204      0       stevel 	prval_init();
   2205      0       stevel 	prval("icmp6InMsgs",		icmp6->ipv6IfIcmpInMsgs);
   2206      0       stevel 	prval("icmp6InErrors",		icmp6->ipv6IfIcmpInErrors);
   2207      0       stevel 	prval("icmp6InDestUnreachs",	icmp6->ipv6IfIcmpInDestUnreachs);
   2208      0       stevel 	prval("icmp6InAdminProhibs",	icmp6->ipv6IfIcmpInAdminProhibs);
   2209      0       stevel 	prval("icmp6InTimeExcds",	icmp6->ipv6IfIcmpInTimeExcds);
   2210      0       stevel 	prval("icmp6InParmProblems",	icmp6->ipv6IfIcmpInParmProblems);
   2211      0       stevel 	prval("icmp6InPktTooBigs",	icmp6->ipv6IfIcmpInPktTooBigs);
   2212      0       stevel 	prval("icmp6InEchos",		icmp6->ipv6IfIcmpInEchos);
   2213      0       stevel 	prval("icmp6InEchoReplies",	icmp6->ipv6IfIcmpInEchoReplies);
   2214      0       stevel 	prval("icmp6InRouterSols",	icmp6->ipv6IfIcmpInRouterSolicits);
   2215      0       stevel 	prval("icmp6InRouterAds",
   2216      0       stevel 	    icmp6->ipv6IfIcmpInRouterAdvertisements);
   2217      0       stevel 	prval("icmp6InNeighborSols",	icmp6->ipv6IfIcmpInNeighborSolicits);
   2218      0       stevel 	prval("icmp6InNeighborAds",
   2219      0       stevel 	    icmp6->ipv6IfIcmpInNeighborAdvertisements);
   2220      0       stevel 	prval("icmp6InRedirects",	icmp6->ipv6IfIcmpInRedirects);
   2221      0       stevel 	prval("icmp6InBadRedirects",	icmp6->ipv6IfIcmpInBadRedirects);
   2222      0       stevel 	prval("icmp6InGroupQueries",	icmp6->ipv6IfIcmpInGroupMembQueries);
   2223      0       stevel 	prval("icmp6InGroupResps",	icmp6->ipv6IfIcmpInGroupMembResponses);
   2224      0       stevel 	prval("icmp6InGroupReds",	icmp6->ipv6IfIcmpInGroupMembReductions);
   2225      0       stevel 	prval("icmp6InOverflows",	icmp6->ipv6IfIcmpInOverflows);
   2226      0       stevel 	prval_end();
   2227      0       stevel 	prval_init();
   2228      0       stevel 	prval("icmp6OutMsgs",		icmp6->ipv6IfIcmpOutMsgs);
   2229      0       stevel 	prval("icmp6OutErrors",		icmp6->ipv6IfIcmpOutErrors);
   2230      0       stevel 	prval("icmp6OutDestUnreachs",	icmp6->ipv6IfIcmpOutDestUnreachs);
   2231      0       stevel 	prval("icmp6OutAdminProhibs",	icmp6->ipv6IfIcmpOutAdminProhibs);
   2232      0       stevel 	prval("icmp6OutTimeExcds",	icmp6->ipv6IfIcmpOutTimeExcds);
   2233      0       stevel 	prval("icmp6OutParmProblems",	icmp6->ipv6IfIcmpOutParmProblems);
   2234      0       stevel 	prval("icmp6OutPktTooBigs",	icmp6->ipv6IfIcmpOutPktTooBigs);
   2235      0       stevel 	prval("icmp6OutEchos",		icmp6->ipv6IfIcmpOutEchos);
   2236      0       stevel 	prval("icmp6OutEchoReplies",	icmp6->ipv6IfIcmpOutEchoReplies);
   2237      0       stevel 	prval("icmp6OutRouterSols",	icmp6->ipv6IfIcmpOutRouterSolicits);
   2238      0       stevel 	prval("icmp6OutRouterAds",
   2239      0       stevel 	    icmp6->ipv6IfIcmpOutRouterAdvertisements);
   2240      0       stevel 	prval("icmp6OutNeighborSols",	icmp6->ipv6IfIcmpOutNeighborSolicits);
   2241      0       stevel 	prval("icmp6OutNeighborAds",
   2242      0       stevel 	    icmp6->ipv6IfIcmpOutNeighborAdvertisements);
   2243      0       stevel 	prval("icmp6OutRedirects",	icmp6->ipv6IfIcmpOutRedirects);
   2244      0       stevel 	prval("icmp6OutGroupQueries",	icmp6->ipv6IfIcmpOutGroupMembQueries);
   2245      0       stevel 	prval("icmp6OutGroupResps",
   2246      0       stevel 	    icmp6->ipv6IfIcmpOutGroupMembResponses);
   2247      0       stevel 	prval("icmp6OutGroupReds",
   2248      0       stevel 	    icmp6->ipv6IfIcmpOutGroupMembReductions);
   2249      0       stevel 	prval_end();
   2250      0       stevel }
   2251      0       stevel 
   2252      0       stevel static void
   2253      0       stevel print_sctp_stats(mib2_sctp_t *sctp)
   2254      0       stevel {
   2255      0       stevel 	prval_init();
   2256      0       stevel 	pr_sctp_rtoalgo("sctpRtoAlgorithm", sctp->sctpRtoAlgorithm);
   2257      0       stevel 	prval("sctpRtoMin",		sctp->sctpRtoMin);
   2258      0       stevel 	prval("sctpRtoMax",		sctp->sctpRtoMax);
   2259      0       stevel 	prval("sctpRtoInitial",		sctp->sctpRtoInitial);
   2260      0       stevel 	pr_int_val("sctpMaxAssocs",	sctp->sctpMaxAssocs);
   2261      0       stevel 	prval("sctpValCookieLife",	sctp->sctpValCookieLife);
   2262      0       stevel 	prval("sctpMaxInitRetr",	sctp->sctpMaxInitRetr);
   2263      0       stevel 	prval("sctpCurrEstab",		sctp->sctpCurrEstab);
   2264      0       stevel 	prval("sctpActiveEstab",	sctp->sctpActiveEstab);
   2265      0       stevel 	prval("sctpPassiveEstab",	sctp->sctpPassiveEstab);
   2266      0       stevel 	prval("sctpAborted",		sctp->sctpAborted);
   2267      0       stevel 	prval("sctpShutdowns",		sctp->sctpShutdowns);
   2268      0       stevel 	prval("sctpOutOfBlue",		sctp->sctpOutOfBlue);
   2269      0       stevel 	prval("sctpChecksumError",	sctp->sctpChecksumError);
   2270      0       stevel 	prval64("sctpOutCtrlChunks",	sctp->sctpOutCtrlChunks);
   2271      0       stevel 	prval64("sctpOutOrderChunks",	sctp->sctpOutOrderChunks);
   2272      0       stevel 	prval64("sctpOutUnorderChunks",	sctp->sctpOutUnorderChunks);
   2273      0       stevel 	prval64("sctpRetransChunks",	sctp->sctpRetransChunks);
   2274      0       stevel 	prval("sctpOutAck",		sctp->sctpOutAck);
   2275      0       stevel 	prval("sctpOutAckDelayed",	sctp->sctpOutAckDelayed);
   2276      0       stevel 	prval("sctpOutWinUpdate",	sctp->sctpOutWinUpdate);
   2277      0       stevel 	prval("sctpOutFastRetrans",	sctp->sctpOutFastRetrans);
   2278      0       stevel 	prval("sctpOutWinProbe",	sctp->sctpOutWinProbe);
   2279      0       stevel 	prval64("sctpInCtrlChunks",	sctp->sctpInCtrlChunks);
   2280      0       stevel 	prval64("sctpInOrderChunks",	sctp->sctpInOrderChunks);
   2281      0       stevel 	prval64("sctpInUnorderChunks",	sctp->sctpInUnorderChunks);
   2282      0       stevel 	prval("sctpInAck",		sctp->sctpInAck);
   2283      0       stevel 	prval("sctpInDupAck",		sctp->sctpInDupAck);
   2284      0       stevel 	prval("sctpInAckUnsent",	sctp->sctpInAckUnsent);
   2285      0       stevel 	prval64("sctpFragUsrMsgs",	sctp->sctpFragUsrMsgs);
   2286      0       stevel 	prval64("sctpReasmUsrMsgs",	sctp->sctpReasmUsrMsgs);
   2287      0       stevel 	prval64("sctpOutSCTPPkts",	sctp->sctpOutSCTPPkts);
   2288      0       stevel 	prval64("sctpInSCTPPkts",	sctp->sctpInSCTPPkts);
   2289      0       stevel 	prval("sctpInInvalidCookie",	sctp->sctpInInvalidCookie);
   2290      0       stevel 	prval("sctpTimRetrans",		sctp->sctpTimRetrans);
   2291      0       stevel 	prval("sctpTimRetransDrop",	sctp->sctpTimRetransDrop);
   2292      0       stevel 	prval("sctpTimHearBeatProbe",	sctp->sctpTimHeartBeatProbe);
   2293      0       stevel 	prval("sctpTimHearBeatDrop",	sctp->sctpTimHeartBeatDrop);
   2294      0       stevel 	prval("sctpListenDrop",		sctp->sctpListenDrop);
   2295      0       stevel 	prval("sctpInClosed",		sctp->sctpInClosed);
   2296      0       stevel 	prval_end();
   2297      0       stevel }
   2298      0       stevel 
   2299      0       stevel static void
   2300      0       stevel print_tcp_stats(mib2_tcp_t *tcp)
   2301      0       stevel {
   2302      0       stevel 	prval_init();
   2303      0       stevel 	pr_int_val("tcpRtoAlgorithm",	tcp->tcpRtoAlgorithm);
   2304      0       stevel 	pr_int_val("tcpRtoMin",		tcp->tcpRtoMin);
   2305      0       stevel 	pr_int_val("tcpRtoMax",		tcp->tcpRtoMax);
   2306      0       stevel 	pr_int_val("tcpMaxConn",	tcp->tcpMaxConn);
   2307      0       stevel 	prval("tcpActiveOpens",		tcp->tcpActiveOpens);
   2308      0       stevel 	prval("tcpPassiveOpens",	tcp->tcpPassiveOpens);
   2309      0       stevel 	prval("tcpAttemptFails",	tcp->tcpAttemptFails);
   2310      0       stevel 	prval("tcpEstabResets",		tcp->tcpEstabResets);
   2311      0       stevel 	prval("tcpCurrEstab",		tcp->tcpCurrEstab);
   2312   3284     apersson 	prval64("tcpOutSegs",		tcp->tcpHCOutSegs);
   2313      0       stevel 	prval("tcpOutDataSegs",		tcp->tcpOutDataSegs);
   2314      0       stevel 	prval("tcpOutDataBytes",	tcp->tcpOutDataBytes);
   2315      0       stevel 	prval("tcpRetransSegs",		tcp->tcpRetransSegs);
   2316      0       stevel 	prval("tcpRetransBytes",	tcp->tcpRetransBytes);
   2317      0       stevel 	prval("tcpOutAck",		tcp->tcpOutAck);
   2318      0       stevel 	prval("tcpOutAckDelayed",	tcp->tcpOutAckDelayed);
   2319      0       stevel 	prval("tcpOutUrg",		tcp->tcpOutUrg);
   2320      0       stevel 	prval("tcpOutWinUpdate",	tcp->tcpOutWinUpdate);
   2321      0       stevel 	prval("tcpOutWinProbe",		tcp->tcpOutWinProbe);
   2322      0       stevel 	prval("tcpOutControl",		tcp->tcpOutControl);
   2323      0       stevel 	prval("tcpOutRsts",		tcp->tcpOutRsts);
   2324      0       stevel 	prval("tcpOutFastRetrans",	tcp->tcpOutFastRetrans);
   2325   3284     apersson 	prval64("tcpInSegs",		tcp->tcpHCInSegs);
   2326      0       stevel 	prval_end();
   2327      0       stevel 	prval("tcpInAckSegs",		tcp->tcpInAckSegs);
   2328      0       stevel 	prval("tcpInAckBytes",		tcp->tcpInAckBytes);
   2329      0       stevel 	prval("tcpInDupAck",		tcp->tcpInDupAck);
   2330      0       stevel 	prval("tcpInAckUnsent",		tcp->tcpInAckUnsent);
   2331      0       stevel 	prval("tcpInInorderSegs",	tcp->tcpInDataInorderSegs);
   2332      0       stevel 	prval("tcpInInorderBytes",	tcp->tcpInDataInorderBytes);
   2333      0       stevel 	prval("tcpInUnorderSegs",	tcp->tcpInDataUnorderSegs);
   2334      0       stevel 	prval("tcpInUnorderBytes",	tcp->tcpInDataUnorderBytes);
   2335      0       stevel 	prval("tcpInDupSegs",		tcp->tcpInDataDupSegs);
   2336      0       stevel 	prval("tcpInDupBytes",		tcp->tcpInDataDupBytes);
   2337      0       stevel 	prval("tcpInPartDupSegs",	tcp->tcpInDataPartDupSegs);
   2338      0       stevel 	prval("tcpInPartDupBytes",	tcp->tcpInDataPartDupBytes);
   2339      0       stevel 	prval("tcpInPastWinSegs",	tcp->tcpInDataPastWinSegs);
   2340      0       stevel 	prval("tcpInPastWinBytes",	tcp->tcpInDataPastWinBytes);
   2341      0       stevel 	prval("tcpInWinProbe",		tcp->tcpInWinProbe);
   2342      0       stevel 	prval("tcpInWinUpdate",		tcp->tcpInWinUpdate);
   2343      0       stevel 	prval("tcpInClosed",		tcp->tcpInClosed);
   2344      0       stevel 	prval("tcpRttNoUpdate",		tcp->tcpRttNoUpdate);
   2345      0       stevel 	prval("tcpRttUpdate",		tcp->tcpRttUpdate);
   2346      0       stevel 	prval("tcpTimRetrans",		tcp->tcpTimRetrans);
   2347      0       stevel 	prval("tcpTimRetransDrop",	tcp->tcpTimRetransDrop);
   2348      0       stevel 	prval("tcpTimKeepalive",	tcp->tcpTimKeepalive);
   2349      0       stevel 	prval("tcpTimKeepaliveProbe",	tcp->tcpTimKeepaliveProbe);
   2350      0       stevel 	prval("tcpTimKeepaliveDrop",	tcp->tcpTimKeepaliveDrop);
   2351      0       stevel 	prval("tcpListenDrop",		tcp->tcpListenDrop);
   2352      0       stevel 	prval("tcpListenDropQ0",	tcp->tcpListenDropQ0);
   2353      0       stevel 	prval("tcpHalfOpenDrop",	tcp->tcpHalfOpenDrop);
   2354      0       stevel 	prval("tcpOutSackRetrans",	tcp->tcpOutSackRetransSegs);
   2355      0       stevel 	prval_end();
   2356      0       stevel 
   2357      0       stevel }
   2358      0       stevel 
   2359      0       stevel static void
   2360      0       stevel print_udp_stats(mib2_udp_t *udp)
   2361      0       stevel {
   2362      0       stevel 	prval_init();
   2363   3284     apersson 	prval64("udpInDatagrams",	udp->udpHCInDatagrams);
   2364      0       stevel 	prval("udpInErrors",		udp->udpInErrors);
   2365   3284     apersson 	prval64("udpOutDatagrams",	udp->udpHCOutDatagrams);
   2366      0       stevel 	prval("udpOutErrors",		udp->udpOutErrors);
   2367      0       stevel 	prval_end();
   2368      0       stevel }
   2369      0       stevel 
   2370      0       stevel static void
   2371      0       stevel print_rawip_stats(mib2_rawip_t *rawip)
   2372      0       stevel {
   2373      0       stevel 	prval_init();
   2374      0       stevel 	prval("rawipInDatagrams",	rawip->rawipInDatagrams);
   2375      0       stevel 	prval("rawipInErrors",		rawip->rawipInErrors);
   2376      0       stevel 	prval("rawipInCksumErrs",	rawip->rawipInCksumErrs);
   2377      0       stevel 	prval("rawipOutDatagrams",	rawip->rawipOutDatagrams);
   2378      0       stevel 	prval("rawipOutErrors",		rawip->rawipOutErrors);
   2379      0       stevel 	prval_end();
   2380      0       stevel }
   2381      0       stevel 
   2382      0       stevel void
   2383      0       stevel print_igmp_stats(struct igmpstat *igps)
   2384      0       stevel {
   2385      0       stevel 	(void) printf(" %10u message%s received\n",
   2386      0       stevel 	    igps->igps_rcv_total, PLURAL(igps->igps_rcv_total));
   2387      0       stevel 	(void) printf(" %10u message%s received with too few bytes\n",
   2388      0       stevel 	    igps->igps_rcv_tooshort, PLURAL(igps->igps_rcv_tooshort));
   2389      0       stevel 	(void) printf(" %10u message%s received with bad checksum\n",
   2390      0       stevel 	    igps->igps_rcv_badsum, PLURAL(igps->igps_rcv_badsum));
   2391      0       stevel 	(void) printf(" %10u membership quer%s received\n",
   2392      0       stevel 	    igps->igps_rcv_queries, PLURALY(igps->igps_rcv_queries));
   2393      0       stevel 	(void) printf(" %10u membership quer%s received with invalid "
   2394      0       stevel 	    "field(s)\n",
   2395      0       stevel 	    igps->igps_rcv_badqueries, PLURALY(igps->igps_rcv_badqueries));
   2396      0       stevel 	(void) printf(" %10u membership report%s received\n",
   2397      0       stevel 	    igps->igps_rcv_reports, PLURAL(igps->igps_rcv_reports));
   2398      0       stevel 	(void) printf(" %10u membership report%s received with invalid "
   2399      0       stevel 	    "field(s)\n",
   2400      0       stevel 	    igps->igps_rcv_badreports, PLURAL(igps->igps_rcv_badreports));
   2401      0       stevel 	(void) printf(" %10u membership report%s received for groups to "
   2402      0       stevel 	    "which we belong\n",
   2403      0       stevel 	    igps->igps_rcv_ourreports, PLURAL(igps->igps_rcv_ourreports));
   2404      0       stevel 	(void) printf(" %10u membership report%s sent\n",
   2405      0       stevel 	    igps->igps_snd_reports, PLURAL(igps->igps_snd_reports));
   2406      0       stevel }
   2407      0       stevel 
   2408      0       stevel static void
   2409      0       stevel print_mrt_stats(struct mrtstat *mrts)
   2410      0       stevel {
   2411      0       stevel 	(void) puts("DVMRP multicast routing:");
   2412      0       stevel 	(void) printf(" %10u hit%s - kernel forwarding cache hits\n",
   2413   8485        Peter 	    mrts->mrts_mfc_hits, PLURAL(mrts->mrts_mfc_hits));
   2414      0       stevel 	(void) printf(" %10u miss%s - kernel forwarding cache misses\n",
   2415   8485        Peter 	    mrts->mrts_mfc_misses, PLURALES(mrts->mrts_mfc_misses));
   2416      0       stevel 	(void) printf(" %10u packet%s potentially forwarded\n",
   2417   8485        Peter 	    mrts->mrts_fwd_in, PLURAL(mrts->mrts_fwd_in));
   2418      0       stevel 	(void) printf(" %10u packet%s actually sent out\n",
   2419   8485        Peter 	    mrts->mrts_fwd_out, PLURAL(mrts->mrts_fwd_out));
   2420      0       stevel 	(void) printf(" %10u upcall%s - upcalls made to mrouted\n",
   2421   8485        Peter 	    mrts->mrts_upcalls, PLURAL(mrts->mrts_upcalls));
   2422      0       stevel 	(void) printf(" %10u packet%s not sent out due to lack of resources\n",
   2423   8485        Peter 	    mrts->mrts_fwd_drop, PLURAL(mrts->mrts_fwd_drop));
   2424      0       stevel 	(void) printf(" %10u datagram%s with malformed tunnel options\n",
   2425   8485        Peter 	    mrts->mrts_bad_tunnel, PLURAL(mrts->mrts_bad_tunnel));
   2426      0       stevel 	(void) printf(" %10u datagram%s with no room for tunnel options\n",
   2427   8485        Peter 	    mrts->mrts_cant_tunnel, PLURAL(mrts->mrts_cant_tunnel));
   2428      0       stevel 	(void) printf(" %10u datagram%s arrived on wrong interface\n",
   2429   8485        Peter 	    mrts->mrts_wrong_if, PLURAL(mrts->mrts_wrong_if));
   2430      0       stevel 	(void) printf(" %10u datagram%s dropped due to upcall Q overflow\n",
   2431   8485        Peter 	    mrts->mrts_upq_ovflw, PLURAL(mrts->mrts_upq_ovflw));
   2432      0       stevel 	(void) printf(" %10u datagram%s cleaned up by the cache\n",
   2433   8485        Peter 	    mrts->mrts_cache_cleanups, PLURAL(mrts->mrts_cache_cleanups));
   2434      0       stevel 	(void) printf(" %10u datagram%s dropped selectively by ratelimiter\n",
   2435   8485        Peter 	    mrts->mrts_drop_sel, PLURAL(mrts->mrts_drop_sel));
   2436      0       stevel 	(void) printf(" %10u datagram%s dropped - bucket Q overflow\n",
   2437   8485        Peter 	    mrts->mrts_q_overflow, PLURAL(mrts->mrts_q_overflow));
   2438      0       stevel 	(void) printf(" %10u datagram%s dropped - larger than bkt size\n",
   2439   8485        Peter 	    mrts->mrts_pkt2large, PLURAL(mrts->mrts_pkt2large));
   2440      0       stevel 	(void) printf("\nPIM multicast routing:\n");
   2441      0       stevel 	(void) printf(" %10u datagram%s dropped - bad version number\n",
   2442   8485        Peter 	    mrts->mrts_pim_badversion, PLURAL(mrts->mrts_pim_badversion));
   2443      0       stevel 	(void) printf(" %10u datagram%s dropped - bad checksum\n",
   2444   8485        Peter 	    mrts->mrts_pim_rcv_badcsum, PLURAL(mrts->mrts_pim_rcv_badcsum));
   2445      0       stevel 	(void) printf(" %10u datagram%s dropped - bad register packets\n",
   2446   8485        Peter 	    mrts->mrts_pim_badregisters, PLURAL(mrts->mrts_pim_badregisters));
   2447      0       stevel 	(void) printf(
   2448   8485        Peter 	    " %10u datagram%s potentially forwarded - register packets\n",
   2449   8485        Peter 	    mrts->mrts_pim_regforwards, PLURAL(mrts->mrts_pim_regforwards));
   2450      0       stevel 	(void) printf(" %10u datagram%s dropped - register send drops\n",
   2451   8485        Peter 	    mrts->mrts_pim_regsend_drops, PLURAL(mrts->mrts_pim_regsend_drops));
   2452      0       stevel 	(void) printf(" %10u datagram%s dropped - packet malformed\n",
   2453   8485        Peter 	    mrts->mrts_pim_malformed, PLURAL(mrts->mrts_pim_malformed));
   2454      0       stevel 	(void) printf(" %10u datagram%s dropped - no memory to forward\n",
   2455   8485        Peter 	    mrts->mrts_pim_nomemory, PLURAL(mrts->mrts_pim_nomemory));
   2456      0       stevel }
   2457      0       stevel 
   2458      0       stevel static void
   2459      0       stevel sum_ip6_stats(mib2_ipv6IfStatsEntry_t *ip6, mib2_ipv6IfStatsEntry_t *sum6)
   2460      0       stevel {
   2461      0       stevel 	/* First few are not additive */
   2462      0       stevel 	sum6->ipv6Forwarding = ip6->ipv6Forwarding;
   2463      0       stevel 	sum6->ipv6DefaultHopLimit = ip6->ipv6DefaultHopLimit;
   2464      0       stevel 
   2465      0       stevel 	sum6->ipv6InReceives += ip6->ipv6InReceives;
   2466      0       stevel 	sum6->ipv6InHdrErrors += ip6->ipv6InHdrErrors;
   2467      0       stevel 	sum6->ipv6InTooBigErrors += ip6->ipv6InTooBigErrors;
   2468      0       stevel 	sum6->ipv6InNoRoutes += ip6->ipv6InNoRoutes;
   2469      0       stevel 	sum6->ipv6InAddrErrors += ip6->ipv6InAddrErrors;
   2470      0       stevel 	sum6->ipv6InUnknownProtos += ip6->ipv6InUnknownProtos;
   2471      0       stevel 	sum6->ipv6InTruncatedPkts += ip6->ipv6InTruncatedPkts;
   2472      0       stevel 	sum6->ipv6InDiscards += ip6->ipv6InDiscards;
   2473      0       stevel 	sum6->ipv6InDelivers += ip6->ipv6InDelivers;
   2474      0       stevel 	sum6->ipv6OutForwDatagrams += ip6->ipv6OutForwDatagrams;
   2475      0       stevel 	sum6->ipv6OutRequests += ip6->ipv6OutRequests;
   2476      0       stevel 	sum6->ipv6OutDiscards += ip6->ipv6OutDiscards;
   2477      0       stevel 	sum6->ipv6OutFragOKs += ip6->ipv6OutFragOKs;
   2478      0       stevel 	sum6->ipv6OutFragFails += ip6->ipv6OutFragFails;
   2479      0       stevel 	sum6->ipv6OutFragCreates += ip6->ipv6OutFragCreates;
   2480      0       stevel 	sum6->ipv6ReasmReqds += ip6->ipv6ReasmReqds;
   2481      0       stevel 	sum6->ipv6ReasmOKs += ip6->ipv6ReasmOKs;
   2482      0       stevel 	sum6->ipv6ReasmFails += ip6->ipv6ReasmFails;
   2483      0       stevel 	sum6->ipv6InMcastPkts += ip6->ipv6InMcastPkts;
   2484      0       stevel 	sum6->ipv6OutMcastPkts += ip6->ipv6OutMcastPkts;
   2485      0       stevel 	sum6->ipv6OutNoRoutes += ip6->ipv6OutNoRoutes;
   2486      0       stevel 	sum6->ipv6ReasmDuplicates += ip6->ipv6ReasmDuplicates;
   2487      0       stevel 	sum6->ipv6ReasmPartDups += ip6->ipv6ReasmPartDups;
   2488      0       stevel 	sum6->ipv6ForwProhibits += ip6->ipv6ForwProhibits;
   2489      0       stevel 	sum6->udpInCksumErrs += ip6->udpInCksumErrs;
   2490      0       stevel 	sum6->udpInOverflows += ip6->udpInOverflows;
   2491      0       stevel 	sum6->rawipInOverflows += ip6->rawipInOverflows;
   2492      0       stevel }
   2493      0       stevel 
   2494      0       stevel static void
   2495      0       stevel sum_icmp6_stats(mib2_ipv6IfIcmpEntry_t *icmp6, mib2_ipv6IfIcmpEntry_t *sum6)
   2496      0       stevel {
   2497      0       stevel 	sum6->ipv6IfIcmpInMsgs += icmp6->ipv6IfIcmpInMsgs;
   2498      0       stevel 	sum6->ipv6IfIcmpInErrors += icmp6->ipv6IfIcmpInErrors;
   2499      0       stevel 	sum6->ipv6IfIcmpInDestUnreachs += icmp6->ipv6IfIcmpInDestUnreachs;
   2500      0       stevel 	sum6->ipv6IfIcmpInAdminProhibs += icmp6->ipv6IfIcmpInAdminProhibs;
   2501      0       stevel 	sum6->ipv6IfIcmpInTimeExcds += icmp6->ipv6IfIcmpInTimeExcds;
   2502      0       stevel 	sum6->ipv6IfIcmpInParmProblems += icmp6->ipv6IfIcmpInParmProblems;
   2503      0       stevel 	sum6->ipv6IfIcmpInPktTooBigs += icmp6->ipv6IfIcmpInPktTooBigs;
   2504      0       stevel 	sum6->ipv6IfIcmpInEchos += icmp6->ipv6IfIcmpInEchos;
   2505      0       stevel 	sum6->ipv6IfIcmpInEchoReplies += icmp6->ipv6IfIcmpInEchoReplies;
   2506      0       stevel 	sum6->ipv6IfIcmpInRouterSolicits += icmp6->ipv6IfIcmpInRouterSolicits;
   2507      0       stevel 	sum6->ipv6IfIcmpInRouterAdvertisements +=
   2508      0       stevel 	    icmp6->ipv6IfIcmpInRouterAdvertisements;
   2509      0       stevel 	sum6->ipv6IfIcmpInNeighborSolicits +=
   2510      0       stevel 	    icmp6->ipv6IfIcmpInNeighborSolicits;
   2511      0       stevel 	sum6->ipv6IfIcmpInNeighborAdvertisements +=
   2512      0       stevel 	    icmp6->ipv6IfIcmpInNeighborAdvertisements;
   2513      0       stevel 	sum6->ipv6IfIcmpInRedirects += icmp6->ipv6IfIcmpInRedirects;
   2514      0       stevel 	sum6->ipv6IfIcmpInGroupMembQueries +=
   2515      0       stevel 	    icmp6->ipv6IfIcmpInGroupMembQueries;
   2516      0       stevel 	sum6->ipv6IfIcmpInGroupMembResponses +=
   2517      0       stevel 	    icmp6->ipv6IfIcmpInGroupMembResponses;
   2518      0       stevel 	sum6->ipv6IfIcmpInGroupMembReductions +=
   2519      0       stevel 	    icmp6->ipv6IfIcmpInGroupMembReductions;
   2520      0       stevel 	sum6->ipv6IfIcmpOutMsgs += icmp6->ipv6IfIcmpOutMsgs;
   2521      0       stevel 	sum6->ipv6IfIcmpOutErrors += icmp6->ipv6IfIcmpOutErrors;
   2522      0       stevel 	sum6->ipv6IfIcmpOutDestUnreachs += icmp6->ipv6IfIcmpOutDestUnreachs;
   2523      0       stevel 	sum6->ipv6IfIcmpOutAdminProhibs += icmp6->ipv6IfIcmpOutAdminProhibs;
   2524      0       stevel 	sum6->ipv6IfIcmpOutTimeExcds += icmp6->ipv6IfIcmpOutTimeExcds;
   2525      0       stevel 	sum6->ipv6IfIcmpOutParmProblems += icmp6->ipv6IfIcmpOutParmProblems;
   2526      0       stevel 	sum6->ipv6IfIcmpOutPktTooBigs += icmp6->ipv6IfIcmpOutPktTooBigs;
   2527      0       stevel 	sum6->ipv6IfIcmpOutEchos += icmp6->ipv6IfIcmpOutEchos;
   2528      0       stevel 	sum6->ipv6IfIcmpOutEchoReplies += icmp6->ipv6IfIcmpOutEchoReplies;
   2529      0       stevel 	sum6->ipv6IfIcmpOutRouterSolicits +=
   2530      0       stevel 	    icmp6->ipv6IfIcmpOutRouterSolicits;
   2531      0       stevel 	sum6->ipv6IfIcmpOutRouterAdvertisements +=
   2532      0       stevel 	    icmp6->ipv6IfIcmpOutRouterAdvertisements;
   2533      0       stevel 	sum6->ipv6IfIcmpOutNeighborSolicits +=
   2534      0       stevel 	    icmp6->ipv6IfIcmpOutNeighborSolicits;
   2535      0       stevel 	sum6->ipv6IfIcmpOutNeighborAdvertisements +=
   2536      0       stevel 	    icmp6->ipv6IfIcmpOutNeighborAdvertisements;
   2537      0       stevel 	sum6->ipv6IfIcmpOutRedirects += icmp6->ipv6IfIcmpOutRedirects;
   2538      0       stevel 	sum6->ipv6IfIcmpOutGroupMembQueries +=
   2539      0       stevel 	    icmp6->ipv6IfIcmpOutGroupMembQueries;
   2540      0       stevel 	sum6->ipv6IfIcmpOutGroupMembResponses +=
   2541      0       stevel 	    icmp6->ipv6IfIcmpOutGroupMembResponses;
   2542      0       stevel 	sum6->ipv6IfIcmpOutGroupMembReductions +=
   2543      0       stevel 	    icmp6->ipv6IfIcmpOutGroupMembReductions;
   2544      0       stevel 	sum6->ipv6IfIcmpInOverflows += icmp6->ipv6IfIcmpInOverflows;
   2545      0       stevel }
   2546      0       stevel 
   2547      0       stevel /* ----------------------------- MRT_STAT_REPORT --------------------------- */
   2548      0       stevel 
   2549      0       stevel static void
   2550      0       stevel mrt_stat_report(mib_item_t *curritem)
   2551      0       stevel {
   2552      0       stevel 	int	jtemp = 0;
   2553      0       stevel 	mib_item_t *tempitem;
   2554      0       stevel 
   2555      0       stevel 	if (!(family_selected(AF_INET)))
   2556      0       stevel 		return;
   2557      0       stevel 
   2558      0       stevel 	(void) putchar('\n');
   2559      0       stevel 	/* 'for' loop 1: */
   2560      0       stevel 	for (tempitem = curritem;
   2561      0       stevel 	    tempitem;
   2562      0       stevel 	    tempitem = tempitem->next_item) {
   2563  11042         Erik 		if (Xflag) {
   2564      0       stevel 			(void) printf("\n--- Entry %d ---\n", ++jtemp);
   2565      0       stevel 			(void) printf("Group = %d, mib_id = %d, "
   2566      0       stevel 			    "length = %d, valp = 0x%p\n",
   2567      0       stevel 			    tempitem->group, tempitem->mib_id,
   2568      0       stevel 			    tempitem->length, tempitem->valp);
   2569      0       stevel 		}
   2570      0       stevel 
   2571      0       stevel 		if (tempitem->mib_id == 0) {
   2572      0       stevel 			switch (tempitem->group) {
   2573      0       stevel 			case EXPER_DVMRP: {
   2574      0       stevel 				struct mrtstat	*mrts;
   2575      0       stevel 				mrts = (struct mrtstat *)tempitem->valp;
   2576      0       stevel 
   2577      0       stevel 				if (!(family_selected(AF_INET)))
   2578      0       stevel 					continue; /* 'for' loop 1 */
   2579      0       stevel 
   2580      0       stevel 				print_mrt_stats(mrts);
   2581      0       stevel 				break;
   2582      0       stevel 			}
   2583      0       stevel 			}
   2584      0       stevel 		}
   2585      0       stevel 	} /* 'for' loop 1 ends */
   2586      0       stevel 	(void) putchar('\n');
   2587      0       stevel 	(void) fflush(stdout);
   2588      0       stevel }
   2589      0       stevel 
   2590      0       stevel /*
   2591      0       stevel  * if_stat_total() - Computes totals for interface statistics
   2592      0       stevel  *                   and returns result by updating sumstats.
   2593      0       stevel  */
   2594      0       stevel static void
   2595      0       stevel if_stat_total(struct ifstat *oldstats, struct ifstat *newstats,
   2596      0       stevel     struct ifstat *sumstats)
   2597      0       stevel {
   2598      0       stevel 	sumstats->ipackets += newstats->ipackets - oldstats->ipackets;
   2599      0       stevel 	sumstats->opackets += newstats->opackets - oldstats->opackets;
   2600      0       stevel 	sumstats->ierrors += newstats->ierrors - oldstats->ierrors;
   2601      0       stevel 	sumstats->oerrors += newstats->oerrors - oldstats->oerrors;
   2602      0       stevel 	sumstats->collisions += newstats->collisions - oldstats->collisions;
   2603      0       stevel }
   2604      0       stevel 
   2605      0       stevel /* --------------------- IF_REPORT (netstat -i)  -------------------------- */
   2606      0       stevel 
   2607      0       stevel static struct	ifstat	zerostat = {
   2608      0       stevel 	0LL, 0LL, 0LL, 0LL, 0LL
   2609      0       stevel };
   2610      0       stevel 
   2611      0       stevel static void
   2612      0       stevel if_report(mib_item_t *item, char *matchname,
   2613      0       stevel     int Iflag_only, boolean_t once_only)
   2614      0       stevel {
   2615      0       stevel 	static boolean_t	reentry = B_FALSE;
   2616      0       stevel 	boolean_t		alreadydone = B_FALSE;
   2617      0       stevel 	int			jtemp = 0;
   2618      0       stevel 	uint32_t		ifindex_v4 = 0;
   2619      0       stevel 	uint32_t		ifindex_v6 = 0;
   2620   5739      keerthi 	boolean_t		first_header = B_TRUE;
   2621      0       stevel 
   2622      0       stevel 	/* 'for' loop 1: */
   2623      0       stevel 	for (; item; item = item->next_item) {
   2624  11042         Erik 		if (Xflag) {
   2625      0       stevel 			(void) printf("\n--- Entry %d ---\n", ++jtemp);
   2626      0       stevel 			(void) printf("Group = %d, mib_id = %d, "
   2627      0       stevel 			    "length = %d, valp = 0x%p\n",
   2628      0       stevel 			    item->group, item->mib_id, item->length,
   2629      0       stevel 			    item->valp);
   2630      0       stevel 		}
   2631      0       stevel 
   2632      0       stevel 		switch (item->group) {
   2633      0       stevel 		case MIB2_IP:
   2634      0       stevel 		if (item->mib_id != MIB2_IP_ADDR ||
   2635      0       stevel 		    !family_selected(AF_INET))
   2636      0       stevel 			continue; /* 'for' loop 1 */
   2637      0       stevel 		{
   2638      0       stevel 			static struct ifstat	old = {0L, 0L, 0L, 0L, 0L};
   2639      0       stevel 			static struct ifstat	new = {0L, 0L, 0L, 0L, 0L};
   2640      0       stevel 			struct ifstat		sum;
   2641      0       stevel 			struct iflist		*newlist = NULL;
   2642      0       stevel 			static struct iflist	*oldlist = NULL;
   2643      0       stevel 			kstat_t	 *ksp;
   2644      0       stevel 
   2645      0       stevel 			if (once_only) {
   2646      0       stevel 				char    ifname[LIFNAMSIZ + 1];
   2647      0       stevel 				char    logintname[LIFNAMSIZ + 1];
   2648      0       stevel 				mib2_ipAddrEntry_t *ap;
   2649      0       stevel 				struct ifstat	stat = {0L, 0L, 0L, 0L, 0L};
   2650      0       stevel 				boolean_t	first = B_TRUE;
   2651      0       stevel 				uint32_t	new_ifindex;
   2652      0       stevel 
   2653  11042         Erik 				if (Xflag)
   2654      0       stevel 					(void) printf("if_report: %d items\n",
   2655      0       stevel 					    (item->length)
   2656      0       stevel 					    / sizeof (mib2_ipAddrEntry_t));
   2657      0       stevel 
   2658      0       stevel 				/* 'for' loop 2a: */
   2659      0       stevel 				for (ap = (mib2_ipAddrEntry_t *)item->valp;
   2660      0       stevel 				    (char *)ap < (char *)item->valp
   2661      0       stevel 				    + item->length;
   2662      0       stevel 				    ap++) {
   2663      0       stevel 					(void) octetstr(&ap->ipAdEntIfIndex,
   2664      0       stevel 					    'a', logintname,
   2665      0       stevel 					    sizeof (logintname));
   2666      0       stevel 					(void) strcpy(ifname, logintname);
   2667      0       stevel 					(void) strtok(ifname, ":");
   2668      0       stevel 					if (matchname != NULL &&
   2669      0       stevel 					    strcmp(matchname, ifname) != 0 &&
   2670      0       stevel 					    strcmp(matchname, logintname) != 0)
   2671      0       stevel 						continue; /* 'for' loop 2a */
   2672      0       stevel 					new_ifindex =
   2673      0       stevel 					    if_nametoindex(logintname);
   2674   5895     yz147064 					/*
   2675   5895     yz147064 					 * First lookup the "link" kstats in
   2676   5895     yz147064 					 * case the link is renamed. Then
   2677   5895     yz147064 					 * fallback to the legacy kstats for
   2678   5895     yz147064 					 * those non-GLDv3 links.
   2679   5895     yz147064 					 */
   2680      0       stevel 					if (new_ifindex != ifindex_v4 &&
   2681   5895     yz147064 					    (((ksp = kstat_lookup(kc, "link", 0,
   2682   5895     yz147064 					    ifname)) != NULL) ||
   2683   5895     yz147064 					    ((ksp = kstat_lookup(kc, NULL, -1,
   2684   5895     yz147064 					    ifname)) != NULL))) {
   2685      0       stevel 						(void) safe_kstat_read(kc, ksp,
   2686      0       stevel 						    NULL);
   2687      0       stevel 						stat.ipackets =
   2688      0       stevel 						    kstat_named_value(ksp,
   2689      0       stevel 						    "ipackets");
   2690      0       stevel 						stat.ierrors =
   2691      0       stevel 						    kstat_named_value(ksp,
   2692      0       stevel 						    "ierrors");
   2693      0       stevel 						stat.opackets =
   2694      0       stevel 						    kstat_named_value(ksp,
   2695      0       stevel 						    "opackets");
   2696      0       stevel 						stat.oerrors =
   2697      0       stevel 						    kstat_named_value(ksp,
   2698      0       stevel 						    "oerrors");
   2699      0       stevel 						stat.collisions =
   2700      0       stevel 						    kstat_named_value(ksp,
   2701      0       stevel 						    "collisions");
   2702      0       stevel 						if (first) {
   2703   5739      keerthi 							if (!first_header)
   2704   5739      keerthi 							(void) putchar('\n');
   2705   5739      keerthi 							first_header = B_FALSE;
   2706      0       stevel 						(void) printf(
   2707      0       stevel 						    "%-5.5s %-5.5s%-13.13s "
   2708      0       stevel 						    "%-14.14s %-6.6s %-5.5s "
   2709      0       stevel 						    "%-6.6s %-5.5s %-6.6s "
   2710      0       stevel 						    "%-6.6s\n",
   2711      0       stevel 						    "Name", "Mtu", "Net/Dest",
   2712      0       stevel 						    "Address", "Ipkts",
   2713      0       stevel 						    "Ierrs", "Opkts", "Oerrs",
   2714      0       stevel 						    "Collis", "Queue");
   2715   5739      keerthi 
   2716   8485        Peter 						first = B_FALSE;
   2717      0       stevel 						}
   2718      0       stevel 						if_report_ip4(ap, ifname,
   2719      0       stevel 						    logintname, &stat, B_TRUE);
   2720      0       stevel 						ifindex_v4 = new_ifindex;
   2721      0       stevel 					} else {
   2722      0       stevel 						if_report_ip4(ap, ifname,
   2723      0       stevel 						    logintname, &stat, B_FALSE);
   2724      0       stevel 					}
   2725      0       stevel 				} /* 'for' loop 2a ends */
   2726      0       stevel 			} else if (!alreadydone) {
   2727      0       stevel 				char    ifname[LIFNAMSIZ + 1];
   2728      0       stevel 				char    buf[LIFNAMSIZ + 1];
   2729      0       stevel 				mib2_ipAddrEntry_t *ap;
   2730      0       stevel 				struct ifstat   t;
   2731   3129      ja97890 				struct iflist	*tlp = NULL;
   2732      0       stevel 				struct iflist	**nextnew = &newlist;
   2733      0       stevel 				struct iflist	*walkold;
   2734      0       stevel 				struct iflist	*cleanlist;
   2735   3129      ja97890 				boolean_t	found_if = B_FALSE;
   2736      0       stevel 
   2737      0       stevel 				alreadydone = B_TRUE; /* ignore other case */
   2738   3129      ja97890 
   2739   3129      ja97890 				/*
   2740   3129      ja97890 				 * Check if there is anything to do.
   2741   3129      ja97890 				 */
   2742   3129      ja97890 				if (item->length <
   2743   3129      ja97890 				    sizeof (mib2_ipAddrEntry_t)) {
   2744   3129      ja97890 					fail(0, "No compatible interfaces");
   2745   3129      ja97890 				}
   2746   3129      ja97890 
   2747   3129      ja97890 				/*
   2748   3129      ja97890 				 * 'for' loop 2b: find the "right" entry:
   2749   3129      ja97890 				 * If an interface name to match has been
   2750   3129      ja97890 				 * supplied then try and find it, otherwise
   2751   3129      ja97890 				 * match the first non-loopback interface found.
   2752   3129      ja97890 				 * Use lo0 if all else fails.
   2753      0       stevel 				 */
   2754      0       stevel 				for (ap = (mib2_ipAddrEntry_t *)item->valp;
   2755      0       stevel 				    (char *)ap < (char *)item->valp
   2756      0       stevel 				    + item->length;
   2757      0       stevel 				    ap++) {
   2758      0       stevel 					(void) octetstr(&ap->ipAdEntIfIndex,
   2759   8485        Peter 					    'a', ifname, sizeof (ifname));
   2760      0       stevel 					(void) strtok(ifname, ":");
   2761      0       stevel 
   2762      0       stevel 					if (matchname) {
   2763      0       stevel 						if (strcmp(matchname,
   2764   3129      ja97890 						    ifname) == 0) {
   2765      0       stevel 							/* 'for' loop 2b */
   2766   3129      ja97890 							found_if = B_TRUE;
   2767      0       stevel 							break;
   2768   3129      ja97890 						}
   2769   3129      ja97890 					} else if (strcmp(ifname, "lo0") != 0)
   2770      0       stevel 						break; /* 'for' loop 2b */
   2771      0       stevel 				} /* 'for' loop 2b ends */
   2772   3129      ja97890 
   2773   3129      ja97890 				if (matchname == NULL) {
   2774   3129      ja97890 					matchname = ifname;
   2775   3129      ja97890 				} else {
   2776   3129      ja97890 					if (!found_if)
   2777   3129      ja97890 						fail(0, "-I: %s no such "
   2778   3129      ja97890 						    "interface.", matchname);
   2779   3129      ja97890 				}
   2780      0       stevel 
   2781      0       stevel 				if (Iflag_only == 0 || !reentry) {
   2782      0       stevel 					(void) printf("    input   %-6.6s    "
   2783      0       stevel 					    "output	",
   2784      0       stevel 					    matchname);
   2785      0       stevel 					(void) printf("   input  (Total)    "
   2786      0       stevel 					"output\n");
   2787      0       stevel 					(void) printf("%-7.7s %-5.5s %-7.7s "
   2788      0       stevel 					    "%-5.5s %-6.6s ",
   2789      0       stevel 					    "packets", "errs", "packets",
   2790      0       stevel 					    "errs", "colls");
   2791      0