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

📄 netshow.c

📁 vxworks5.5.1源代码。完整源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    "ATM_VIRTUAL",    "MPLS_TUNNEL",    "SRP",    "VOICE_OVER_ATM",    "VOICE_OVER_FRAME_RELAY",    "IDSL",    "COMPOSITE_LINK",    "SS7_SIG_LINK",    "PMP",     };LOCAL int bufIndex;                 /* index into route buffer */LOCAL char *routeBuf;               /* buffer to store routing table *//* forward static functions */static void ifAddrPrint (char *str, struct sockaddr *addr);static void ifFlagPrint (u_short flag);static void ifEtherPrint (u_char enaddr [ 6 ]);static void inetPrint (struct in_addr *in, u_short port);LOCAL BOOL routeEntryPrint (struct rtentry *, void *, BOOL);static void routeTableShow (int rtType);static void inpcbPrint (char *name, struct inpcb *pInpcb);static int routeNodeShow (struct radix_node* rn, void* w);#define RT_ENTRY_LEN    90#define plural(num)	((num) > 1 ? "s": "")#define RT_NET		0x001			/* print network route */#define RT_HST		0x010			/* print host route */#define RT_ARP		0x100			/* print arp route entry *//***************************************************************************** UI64ToDouble - convert a UI64 struct to a double** This routine is used by ifShow to convert the high capacity 64 bit* interface counters to a double.  The UI64 struct is defined within* m2Lib.** RETURNS: value as a double type*/LOCAL double UI64ToDouble    (    UI64 * pUI64    )    {    int i;    double x;     x = 0;     for (i = 0; i < 32; i++)        {        if ((pUI64->low >> i) & 0x01)            x += pow(2, i);        }     for (i = 0; i < 32; i++)        {        if ((pUI64->high >> i) & 0x01)            x += pow(2, (i + 32));        }     return x;    } /********************************************************************************* ifShow - display the attached network interfaces** This routine displays the attached network interfaces for debugging and* diagnostic purposes.  If <ifName> is given, only the interfaces belonging* to that group are displayed.  If <ifName> is omitted, all attached* interfaces are displayed.** For each interface selected, the following are shown: Internet* address, point-to-point peer address (if using SLIP), broadcast address,* netmask, subnet mask, Ethernet address, route metric, maximum transfer* unit, number of packets sent and received on this interface, number of* input and output errors, and flags (such as loopback, point-to-point,* broadcast, promiscuous, ARP, running, and debug).** EXAMPLE:* The following call displays all interfaces whose names begin with "ln",* (such as "ln0", "ln1", and "ln2"):* .CS*     -> ifShow "ln"* .CE* The following call displays just the interface "ln0":* .CS*     -> ifShow "ln0"* .CE** RETURNS: N/A** SEE ALSO: routeShow(), ifLib** 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 ifShow    (    char *ifName                /* name of the interface to show */    )    {    FAST struct ifnet 		*ifp;    FAST struct ifaddr 		*ifa;    FAST struct in_ifaddr 	*ia = 0;    FAST int			 nameLen;    BOOL 			 found;    int				 ifUnit;    IP_DRV_CTRL *                pDrvCtrl = NULL;    END_OBJ *                    pEnd;#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)                {                if (m2If64BitCounters)                    {                    printf ("     %.0f octets received\n",                            UI64ToDouble(&pEnd->pMib2Tbl->m2Data.mibXIfTbl.                                                               ifHCInOctets));                    printf ("     %.0f octets sent\n",                            UI64ToDouble(&pEnd->pMib2Tbl->m2Data.mibXIfTbl.                                                               ifHCOutOctets));                    printf ("     %.0f unicast packets received\n",                            UI64ToDouble(&pEnd->pMib2Tbl->m2Data.mibXIfTbl.                                         ifHCInUcastPkts));                    printf ("     %.0f unicast packets sent\n",                            UI64ToDouble(&pEnd->pMib2Tbl->m2Data.mibXIfTbl.                                         ifHCOutUcastPkts));                    printf ("     %lu non-unicast packets received\n", 				            pIfMib->mibIfTbl.ifInNUcastPkts);                    printf ("     %lu non-unicast packets sent\n", 				            pIfMib->mibIfTbl.ifOutNUcastPkts);                    printf ("     %.0f broadcast packets received\n",                            UI64ToDouble(&pEnd->pMib2Tbl->m2Data.mibXIfTbl.                                         ifHCInBroadcastPkts));                    printf ("     %.0f broadcast packets sent\n",                            UI64ToDouble(&pEnd->pMib2Tbl->m2Data.mibXIfTbl.                                         ifHCOutBroadcastPkts));                    printf ("     %.0f multicast packets received\n",                            UI64ToDouble(&pEnd->pMib2Tbl->m2Data.mibXIfTbl.                                         ifHCInMulticastPkts));                    printf ("     %.0f multicast packets sent\n",                            UI64ToDouble(&pEnd->pMib2Tbl->m2Data.mibXIfTbl.                                         ifHCOutMulticastPkts));                    }                else                    {                    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_ibytes);                printf("     %lu octets sent\n",                       ifp->if_obytes);                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 ");

⌨️ 快捷键说明

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