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

📄 netshow.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
#ifdef VIRTUAL_STACK    virtualStackIdCheck();#endif /* VIRTUAL_STACK */    found = FALSE;#ifdef VIRTUAL_STACK    for (ifp = _ifnet;  ifp != NULL;  ifp = ifp->if_next)#else    for (ifp = ifnet;  ifp != NULL;  ifp = ifp->if_next)#endif /* VIRTUAL_STACK */	{	nameLen = strlen (ifp->if_name);	/*	 * If no name is specified, every interface is a match.	 */	if (ifName != NULL)		/* if a name was specified */	    {	    if (strncmp (ifName, ifp->if_name, nameLen) != 0)	    	continue;		/* no match - wrong name */	    /*	     * If the user specified unit ID in ifName compare the unit number	     */	    if (nameLen < strlen (ifName))	    	{	    	sscanf (&ifName [nameLen], "%d", &ifUnit);	    	if (ifp->if_unit != ifUnit)		    continue;		/* no match - wrong unit ID */		}	    }	found = TRUE;#ifdef VIRTUAL_STACK	printf ("%s (unit number %d) (stack number %d):\n", ifp->if_name,                ifp->if_unit, ifp->vsNum);#else	printf ("%s (unit number %d):\n", ifp->if_name, ifp->if_unit);#endif /* VIRTUAL_STACK */	ifFlagPrint (ifp->if_flags);	printf ("     Type: %s\n", pIfTypes [ifp->if_type]);	for (ifa = ifp->if_addrlist;  ifa != NULL;  ifa = ifa->ifa_next)	    {	    if (ifa->ifa_addr->sa_family == AF_INET)		{                /*                 * Every element in the if_addrlist (type struct ifaddr) with                 * family AF_INET is actually the first part of a larger                 * in_ifaddr structure which includes the netmask and subnet                 * mask. Access that structure to display those values.                 */                ia = (struct in_ifaddr *)ifa;		ifAddrPrint ("Internet address", ifa->ifa_addr);		if (ifp->if_flags & IFF_POINTOPOINT)		    ifAddrPrint ("Destination Internet address",                                  ifa->ifa_dstaddr);		else if (ifp->if_flags & IFF_BROADCAST)		    ifAddrPrint ("Broadcast address", ifa->ifa_broadaddr);                printf ("     Netmask 0x%lx Subnetmask 0x%lx\n",                         ia->ia_netmask, ia->ia_subnetmask);		}	    }        /*	 * if the interface is not LOOPBACK or SLIP, print the link	 * level address.	 */	if (!(ifp->if_flags & IFF_POINTOPOINT) &&	    !(ifp->if_flags & IFF_LOOPBACK))	    ifEtherPrint (((struct arpcom *)ifp)->ac_enaddr);	printf("     Metric is %lu\n", ifp->if_metric);	printf("     Maximum Transfer Unit size is %lu\n", ifp->if_mtu);        pDrvCtrl = (IP_DRV_CTRL *)ifp->pCookie;        /*         * If the ifnet does not have a cookie then this is         * a BSD 4.x  interface.         */        if (pDrvCtrl == NULL)            {            printf("     %lu packets received; %lu packets sent\n",                   ifp->if_ipackets, ifp->if_opackets);            printf("     %lu multicast packets received\n", ifp->if_imcasts);            printf("     %lu multicast packets sent\n", ifp->if_omcasts);            printf("     %lu input errors; %lu output errors\n",                   ifp->if_ierrors, ifp->if_oerrors);            }        else /* END style interface. */            {            M2_DATA    *pIfMib;            pEnd = PCOOKIE_TO_ENDOBJ(pDrvCtrl->pIpCookie);            if (pEnd == NULL)                continue;            pIfMib = &pEnd->pMib2Tbl->m2Data;            if (pEnd->flags & END_MIB_2233)                {	        printf ("     %lu octets received\n", pIfMib->mibIfTbl.ifInOctets);	        printf ("     %lu octets sent\n", pIfMib->mibIfTbl.ifOutOctets);	        printf ("     %lu unicast packets received\n", 				            pIfMib->mibIfTbl.ifInUcastPkts);	        printf ("     %lu unicast packets sent\n", 				            pIfMib->mibIfTbl.ifOutUcastPkts);	        printf ("     %lu non-unicast packets received\n", 				            pIfMib->mibIfTbl.ifInNUcastPkts);	        printf ("     %lu non-unicast packets sent\n", 				            pIfMib->mibIfTbl.ifOutNUcastPkts);	        printf ("     %lu multicast packets received\n", 				            pIfMib->mibXIfTbl.ifInMulticastPkts);	        printf ("     %lu multicast packets sent\n", 				            pIfMib->mibXIfTbl.ifOutMulticastPkts);	        printf ("     %lu broadcast packets received\n", 				            pIfMib->mibXIfTbl.ifInBroadcastPkts);	        printf ("     %lu broadcast packets sent\n", 				            pIfMib->mibXIfTbl.ifOutBroadcastPkts);	        printf ("     %lu incoming packets discarded\n", 				            pIfMib->mibIfTbl.ifInDiscards);	        printf ("     %lu outgoing packets discarded\n", 				            pIfMib->mibIfTbl.ifOutDiscards);	        printf ("     %lu incoming errors\n", 				            pIfMib->mibIfTbl.ifInErrors);	        printf ("     %lu outgoing errors\n", 				            pIfMib->mibIfTbl.ifOutErrors);	        printf ("     %lu unknown protos\n", 				            pIfMib->mibIfTbl.ifInUnknownProtos);		}            else /* (RFC1213 style counters supported) XXX */                {                /*                 * XXX This change was made in order to fix inconsistant                 * statistics between MIB2 and ifnet due to END currently                 * does not increment MIB2 statistics. However this is                 * temporary fix and should be rolled back when ifnet{}                  * gets obsolete eventually.                 */                printf("     %lu octets received\n",                       ifp->if_ipackets);                printf("     %lu octets sent\n",                       ifp->if_opackets);                printf("     %lu packets received\n",                       ifp->if_ipackets - ifp->if_ierrors);                printf("     %lu packets sent\n",                       ifp->if_opackets - ifp->if_oerrors);                printf("     %lu non-unicast packets received\n",                       ifp->if_imcasts);                printf("     %lu non-unicast packets sent\n",                       ifp->if_omcasts);                printf("     %lu unicast packets received\n",                       ifp->if_ipackets - ifp->if_imcasts);                printf("     %lu unicast packets sent\n",                       ifp->if_opackets - ifp->if_omcasts);                printf("     %lu input discards\n",                       ifp->if_iqdrops);                printf("     %lu input unknown protocols\n",                       ifp->if_noproto);                printf("     %lu input errors\n",                       ifp->if_ierrors);                printf("     %lu output errors\n",                       ifp->if_oerrors);                }            }	    /* print collisions and drops for old BSD or iso88023_csmacd 	     * or ethernet_csmacd	     */            if (pDrvCtrl == NULL  		    || ifp->if_data.ifi_type==M2_ifType_iso88023_csmacd 	            || ifp->if_data.ifi_type==M2_ifType_ethernet_csmacd )	       {                printf("     %ld collisions; %ld dropped\n",                ifp->if_collisions, ifp->if_iqdrops);	       }        }    if (found == FALSE)	{    	if (ifName != NULL)	    printErr("\"%s\" - No such interface\n", ifName);    	else	    printErr("No network interface active.\n");	}    }/********************************************************************************* ifAddrPrint - print Internet address for the interface** Prints the Internet address (for the network interfaces)* in readable format.** RETURNS: N/A.*/LOCAL void ifAddrPrint    (    char                *str,   /* comment string to be printed */    struct sockaddr     *addr   /* internet address for the interface */    )    {    char 		addrString [INET_ADDR_LEN];    inet_ntoa_b (((struct sockaddr_in *)addr)->sin_addr, addrString);    printf("     %s: %s\n", str, addrString);    }/********************************************************************************* ifFlagPrint - print flags for the network interface** ifFlagPrint prints each of the flags specified for the network* interfaces in user-readable format.** RETURNS: N/A.*/LOCAL void ifFlagPrint    (    FAST ushort flag                       /* network interface flags */    )    {    printf("     Flags: (0x%x) ", flag);    if (flag & IFF_UP)	printf ("UP ");    else	/* shouldn't happen if the interface is deleted properly */	printf ("DOWN ");    if (flag & IFF_LOOPBACK)	printf ("LOOPBACK ");    if (flag & IFF_POINTOPOINT)	printf ("POINT-TO-POINT ");    if (flag & IFF_BROADCAST)	printf ("BROADCAST ");    if (flag & IFF_MULTICAST)	printf ("MULTICAST ");     if (flag & IFF_PROMISC)	printf ("PROMISCUOUS ");    if (!(flag & IFF_NOTRAILERS))	printf ("TRAILERS ");    if (!(flag & IFF_NOARP))	printf ("ARP ");    if (flag & IFF_RUNNING)	printf ("RUNNING ");    if (flag & IFF_DEBUG)	printf ("DEBUG ");    if (flag & IFF_FP_ENABLE)	printf ("FASTPATH ");    printf ("\n");    }/********************************************************************************* ifEtherPrint - print Ethernet address in ":" notation** RETURNS: N/A.*/LOCAL void ifEtherPrint    (    u_char enaddr[6]            /* ethernet address */    )    {    unsigned char *en = (unsigned char *)enaddr;    printf("     Ethernet address is %02x:%02x:%02x:%02x:%02x:%02x\n",	   en [0], en [1], en [2], en [3], en [4], en [5]);    }/********************************************************************************* inetPrint - Pretty print an Internet address (net address + port).** RETURNS: N/A.*/LOCAL void inetPrint    (    FAST struct in_addr *in,    u_short port    )    {    char line[80];    char *cp;    int width;    char addrString [INET_ADDR_LEN];    inet_ntoa_b ((*in), addrString);    (void) sprintf (line, "%.*s.", 15, addrString);    cp = index (line, '\0');    (void) sprintf (cp, "%d", ntohs((u_short)port));    width = 21;    printf (" %-*.*s", width, width, line);    }/********************************************************************************* inetstatShow - display all active connections for Internet protocol sockets** This routine displays a list of all active Internet protocol sockets in a* format similar to the UNIX `netstat' command.** If you want inetstatShow() to display TCP socket status, then* INCLUDE_TCP_SHOW needs to be included.** RETURNS: N/A** INTERNAL* When using the Tornado shell, this routine is only available if an* "@" sign is prepended to the routine name. Otherwise, it is preempted* by a built-in version.*/void inetstatShow (void)    {#ifdef VIRTUAL_STACK    virtualStackIdCheck();    printf("Active Internet connections (including servers) (stack number %d)\n", myStackNum);#else    printf("Active Internet connections (including servers)\n");#endif /* VIRTUAL_STACK */    printf("%-8.8s %-5.5s %-6.6s %-6.6s  %-18.18s %-18.18s %s\n",	   "PCB", "Proto", "Recv-Q", "Send-Q",	   "Local Address", "Foreign Address", "(state)");    printf("%-8.8s %-5.5s %-6.6s %-6.6s  %-18.18s %-18.18s %s\n",	   "--------", "-----", "------", "------", "------------------",    	   "------------------", "-------");    if (_pTcpPcbHead != NULL)        inpcbPrint ("TCP", _pTcpPcbHead->lh_first);    else        printf("No TCP show routine included.  TCP connections not shown.\n");        if (_pUdpPcbHead != NULL)        inpcbPrint ("UDP", _pUdpPcbHead->lh_first);    else        printf("No UDP show routine included.  UDP connections not shown.\n");#ifdef VIRTUAL_STACK    inpcbPrint ("RAW", ripcb.lh_first);#endif /* VIRTUAL_STACK */    }/********************************************************************************* inpcbPrint - print a list of protocol control blocks for an Internet protocol** Prints a list of active protocol control blocks for the specified* Internet protocols in a nice and pretty format.** RETURNS: N/A.*/LOCAL void inpcbPrint    (    char *name,    struct inpcb *pInpcb    )    {    FAST struct inpcb *inp;    struct socket *pSock;    BOOL isTcp = 0;    if (strcmp (name, "TCP") == 0)        isTcp = 1;    for (inp = pInpcb; inp != NULL; inp = inp->inp_list.le_next)	{	pSock = inp->inp_socket;	/*	 * Print "inp" here to allow manual deletion of the stale	 * PCB's by using in_pcbdetach (inp).	 */	printf ("%-8x ", (u_int) inp);	printf("%-5.5s %6ld %6ld ", name, pSock->so_rcv.sb_cc,	       pSock->so_snd.sb_cc);	inetPrint (&(inp->inp_laddr), inp->inp_lport);	inetPrint (&(inp->inp_faddr), inp->inp_fport);        /* if tcp is included then only print the tcp information */                if (isTcp && (_pTcpPcbPrint != NULL))            (*_pTcpPcbPrint) (inp); 	(void) printf ("\n");	}    }/********************************************************************************* ipstatShow - display IP statistics** This routine displays detailed statistics for the IP protocol.** RETURNS: N/A** INTERNAL* When using the Tornado shell, this routine is only available if an* "@" sign is prepended to the routine name. Otherwise, it is preempted* by a built-in version.*/void ipstatShow    (    BOOL zero           /* TRUE = reset statistics to 0 */    )    {    static char *ipstat_name[] =	{	"total",           "badsum",    "tooshort",     "toosmall",	"badhlen",         "badlen",    "infragments",  "fragdropped", 	"fragtimeout",     "forward",   "cantforward",  "redirectsent", 	"unknownprotocol", "nobuffers",  "reassembled", "outfragments", 	"noroute"	};    char *fmt = "%20s %4d\n";    int ix = 0;#ifdef VIRTUAL_STACK    virtualStackIdCheck();    printf (fmt, "stack number",	myStackNum);                    /* stack number */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_total);             /* total packets received */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_badsum);            /* checksum bad */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_tooshort);          /* packet too short */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_toosmall);          /* not enough data */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_badhlen);           /* ip header length < data size */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_badlen);            /* ip length < ip header length */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_fragments);         /* fragments received */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_fragdropped);       /* frags dropped (dups, out of space) */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_fragtimeout);       /* fragments timed out */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_forward);           /* packets forwarded */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_cantforward);       /* packets rcvd for unreachable dest */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_redirectsent);      /* packets forwarded on same net */    printf (fmt, ipstat_name [ix++],	_ipstat.ips_noproto);	        /* pkts recieved with unknown protos */    printf (fmt, ipstat_name [ix++],

⌨️ 快捷键说明

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