⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iso.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 1983, 1988, 1993 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */#ifndef lintstatic char sccsid[] = "@(#)iso.c	8.1 (Berkeley) 6/6/93";#endif /* not lint *//* * $Header: iso.c,v 1.5 92/06/04 00:36:32 leres Exp $ * $Source: /usr/src/usr.bin/netstat/RCS/iso.c,v $ *//*******************************************************************************	          Copyright IBM Corporation 1987                      All Rights ReservedPermission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear insupporting documentation, and that the name of IBM not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission.IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALLIBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.*******************************************************************************//* * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison */#include <sys/param.h>#include <sys/mbuf.h>#include <sys/time.h>#include <sys/domain.h>#include <sys/protosw.h>#include <sys/socket.h>#include <sys/socketvar.h>#include <errno.h>#include <net/if.h>#include <net/route.h>#include <netinet/in.h>#include <netinet/in_systm.h>#include <netinet/ip.h>#include <netinet/in_pcb.h>#include <netinet/ip_var.h>#include <netiso/iso.h>#include <netiso/iso_errno.h>#include <netiso/clnp.h>#include <netiso/esis.h>#include <netiso/clnp_stat.h>#include <netiso/argo_debug.h>#undef satosiso#include <netiso/tp_param.h>#include <netiso/tp_states.h>#include <netiso/tp_pcb.h>#include <netiso/tp_stat.h>#include <netiso/iso_pcb.h>#include <netiso/cltp_var.h>#include <netiso/cons.h>#ifdef IncStat#undef IncStat#endif#include <netiso/cons_pcb.h>#include <arpa/inet.h>#include <netdb.h>#include <string.h>#include <stdio.h>#include <stdlib.h>#include "netstat.h"static void tprintstat __P((struct tp_stat *, int));static void isonetprint __P((struct sockaddr_iso *, int));static void hexprint __P((int, char *, char *));extern void inetprint __P((struct in_addr *, int, char *));/* *	Dump esis stats */voidesis_stats(off, name)	u_long	off;	char	*name;{	struct esis_stat esis_stat;	if (off == 0 ||	    kread(off, (char *)&esis_stat, sizeof (struct esis_stat)))		return;	printf("%s:\n", name);	printf("\t%d esh sent, %d esh received\n", esis_stat.es_eshsent,		esis_stat.es_eshrcvd);	printf("\t%d ish sent, %d ish received\n", esis_stat.es_ishsent,		esis_stat.es_ishrcvd);	printf("\t%d rd sent, %d rd received\n", esis_stat.es_rdsent,		esis_stat.es_rdrcvd);	printf("\t%d pdus not sent due to insufficient memory\n",		esis_stat.es_nomem);	printf("\t%d pdus received with bad checksum\n", esis_stat.es_badcsum);	printf("\t%d pdus received with bad version number\n",		esis_stat.es_badvers);	printf("\t%d pdus received with bad type field\n", esis_stat.es_badtype);	printf("\t%d short pdus received\n", esis_stat.es_toosmall);}/* * Dump clnp statistics structure. */voidclnp_stats(off, name)	u_long off;	char *name;{	struct clnp_stat clnp_stat;	if (off == 0 ||	    kread(off, (char *)&clnp_stat, sizeof (clnp_stat)))		return;	printf("%s:\n\t%d total packets sent\n", name, clnp_stat.cns_sent);	printf("\t%d total fragments sent\n", clnp_stat.cns_fragments);	printf("\t%d total packets received\n", clnp_stat.cns_total);	printf("\t%d with fixed part of header too small\n",		clnp_stat.cns_toosmall);	printf("\t%d with header length not reasonable\n", clnp_stat.cns_badhlen);	printf("\t%d incorrect checksum%s\n",		clnp_stat.cns_badcsum, plural(clnp_stat.cns_badcsum));	printf("\t%d with unreasonable address lengths\n", clnp_stat.cns_badaddr);	printf("\t%d with forgotten segmentation information\n",		clnp_stat.cns_noseg);	printf("\t%d with an incorrect protocol identifier\n", clnp_stat.cns_noproto);	printf("\t%d with an incorrect version\n", clnp_stat.cns_badvers);	printf("\t%d dropped because the ttl has expired\n",		clnp_stat.cns_ttlexpired);	printf("\t%d clnp cache misses\n", clnp_stat.cns_cachemiss);	printf("\t%d clnp congestion experience bits set\n",		clnp_stat.cns_congest_set);	printf("\t%d clnp congestion experience bits received\n",		clnp_stat.cns_congest_rcvd);}/* * Dump CLTP statistics structure. */voidcltp_stats(off, name)	u_long off;	char *name;{	struct cltpstat cltpstat;	if (off == 0 ||	    kread(off, (char *)&cltpstat, sizeof (cltpstat)))		return;	printf("%s:\n\t%u incomplete header%s\n", name,		cltpstat.cltps_hdrops, plural(cltpstat.cltps_hdrops));	printf("\t%u bad data length field%s\n",		cltpstat.cltps_badlen, plural(cltpstat.cltps_badlen));	printf("\t%u bad checksum%s\n",		cltpstat.cltps_badsum, plural(cltpstat.cltps_badsum));}struct	tp_pcb tpcb;struct	isopcb isopcb;struct	socket sockb;union	{	struct sockaddr_iso	siso;	char	data[128];} laddr, faddr;#define kget(o, p) \	(kread((u_long)(o), (char *)&p, sizeof (p)))static	int first = 1;/* * Print a summary of connections related to an Internet * protocol.  For TP, also give state of connection. * Listening processes (aflag) are suppressed unless the * -a (all) flag is specified. */voidiso_protopr(off, name)	u_long off;	char *name;{	struct isopcb cb;	register struct isopcb *prev, *next;	if (off == 0) {		printf("%s control block: symbol not in namelist\n", name);		return;	}	if (strcmp(name, "tp") == 0) {		tp_protopr(off, name);		return;	}	if (kread(off, (char *)&cb, sizeof(cb)))		return;	isopcb = cb;	prev = (struct isopcb *)off;	if (isopcb.isop_next == (struct isopcb *)off)		return;	while (isopcb.isop_next != (struct isopcb *)off) {		next = isopcb.isop_next;		kget(next, isopcb);		if (isopcb.isop_prev != prev) {			printf("prev 0x%x next 0x%x isop_prev 0x%x isop_next 0x%x???\n",				prev, next, isopcb.isop_prev, isopcb.isop_next);			break;		}		kget(isopcb.isop_socket, sockb);		iso_protopr1((u_long)next, 0);		putchar('\n');		prev = next;	}}voidiso_protopr1(kern_addr, istp)	u_long kern_addr;	int istp;{	if (first) {		printf("Active ISO net connections");		if (aflag)			printf(" (including servers)");		putchar('\n');		if (Aflag)			printf("%-8.8s ", "PCB");		printf(Aflag ?			"%-5.5s %-6.6s %-6.6s  %-18.18s %-18.18s %s\n" :			"%-5.5s %-6.6s %-6.6s  %-22.22s %-22.22s %s\n",			"Proto", "Recv-Q", "Send-Q",			"Local Address", "Foreign Address", "(state)");		first = 0;	}	if (Aflag)			printf("%8x ",					(sockb.so_pcb ? (void *)sockb.so_pcb : (void *)kern_addr));	printf("%-5.5s %6d %6d ", "tp", sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);	if (istp && tpcb.tp_lsuffixlen) {			hexprint(tpcb.tp_lsuffixlen, tpcb.tp_lsuffix, "()");			printf("\t");	} else if (isopcb.isop_laddr == 0)			printf("*.*\t");	else {			if ((char *)isopcb.isop_laddr == ((char *)kern_addr) +					_offsetof(struct isopcb, isop_sladdr))					laddr.siso = isopcb.isop_sladdr;			else					kget(isopcb.isop_laddr, laddr);			isonetprint((struct sockaddr_iso *)&laddr, 1);	}	if (istp && tpcb.tp_fsuffixlen) {			hexprint(tpcb.tp_fsuffixlen, tpcb.tp_fsuffix, "()");			printf("\t");	} else if (isopcb.isop_faddr == 0)		printf("*.*\t");	else {		if ((char *)isopcb.isop_faddr == ((char *)kern_addr) +			_offsetof(struct isopcb, isop_sfaddr))			faddr.siso = isopcb.isop_sfaddr;		else			kget(isopcb.isop_faddr, faddr);		isonetprint((struct sockaddr_iso *)&faddr, 0);	}}voidtp_protopr(off, name)	u_long off;	char *name;{	extern char *tp_sstring[];	struct tp_ref *tpr, *tpr_base;	struct tp_refinfo tpkerninfo;	int size;	kget(off, tpkerninfo);	size = tpkerninfo.tpr_size * sizeof (*tpr);	tpr_base = (struct tp_ref *)malloc(size);	if (tpr_base == 0)		return;	kread((u_long)(tpkerninfo.tpr_base), (char *)tpr_base, size);	for (tpr = tpr_base; tpr < tpr_base + tpkerninfo.tpr_size; tpr++) {		if (tpr->tpr_pcb == 0)			continue;		kget(tpr->tpr_pcb, tpcb);		if (tpcb.tp_state == ST_ERROR)			printf("undefined tpcb state: 0x%x\n", tpr->tpr_pcb);		if (!aflag &&			(tpcb.tp_state == TP_LISTENING ||			 tpcb.tp_state == TP_CLOSED ||			 tpcb.tp_state == TP_REFWAIT)) {			continue;		}		kget(tpcb.tp_sock, sockb);		if (tpcb.tp_npcb) switch(tpcb.tp_netservice) {			case IN_CLNS:				tp_inproto((u_long)tpkerninfo.tpr_base);				break;			default:				kget(tpcb.tp_npcb, isopcb);				iso_protopr1((u_long)tpcb.tp_npcb, 1);				break;		}		if (tpcb.tp_state >= tp_NSTATES)			printf(" %d", tpcb.tp_state);		else			printf(" %-12.12s", tp_sstring[tpcb.tp_state]);		putchar('\n');	}}voidtp_inproto(pcb)	u_long pcb;{	struct inpcb inpcb;	kget(tpcb.tp_npcb, inpcb);	if (!aflag && inet_lnaof(inpcb.inp_laddr) == INADDR_ANY)		return;	if (Aflag)		printf("%8x ", pcb);	printf("%-5.5s %6d %6d ", "tpip",	    sockb.so_rcv.sb_cc, sockb.so_snd.sb_cc);	inetprint(&inpcb.inp_laddr, inpcb.inp_lport, "tp");	inetprint(&inpcb.inp_faddr, inpcb.inp_fport, "tp");}/* * Pretty print an iso address (net address + port). * If the nflag was specified, use numbers instead of names. */#ifdef notdefchar *isonetname(iso)	register struct iso_addr *iso;{	struct sockaddr_iso sa;	struct iso_hostent *ihe = 0;	struct iso_hostent *iso_gethostentrybyaddr();	struct iso_hostent *iso_getserventrybytsel();	struct iso_hostent Ihe;	static char line[80];	bzero(line, sizeof(line));	if( iso->isoa_afi ) {		sa.siso_family = AF_ISO;		sa.siso_addr = *iso;		sa.siso_tsuffix = 0;		if (!nflag )			ihe = iso_gethostentrybyaddr( &sa, 0, 0 );		if( ihe ) {			Ihe = *ihe;			ihe = &Ihe;			sprintf(line, "%s", ihe->isoh_hname);		} else {			sprintf(line, "%s", iso_ntoa(iso));		}	} else {		sprintf(line, "*");	}	return line;}static voidisonetprint(iso, sufx, sufxlen, islocal)	register struct iso_addr *iso;	char *sufx;	u_short	sufxlen;	int islocal;{	struct iso_hostent *iso_getserventrybytsel(), *ihe;	struct iso_hostent Ihe;	char *line, *cp;	int Alen = Aflag?18:22;	line =  isonetname(iso);	cp = index(line, '\0');	ihe = (struct iso_hostent *)0;	if( islocal )		islocal = 20;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -