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

📄 netshow.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 3 页
字号:
    printf ("%s", dashLine);    }/********************************************************************************* arptabShow - display the known ARP entries** This routine displays current Internet-to-Ethernet address mappings in the* ARP table.** RETURNS: N/A** INTERNAL* This just calls arpShow.  It is provided for compatablity.* Migrating to arpShow to be more compliant with WRS naming.*/void arptabShow (void)    {    arpShow ();    }/******************************************************************************* routestatShow - display routing statistics** This routine displays routing statistics.** RETURNS: N/A*/void routestatShow (void)    {    printf ("routing:\n");    printf ("\t%u bad routing redirect%s\n", rtstat.rts_badredirect,	    plural (rtstat.rts_badredirect));    printf ("\t%u dynamically created route%s\n", rtstat.rts_dynamic,	    plural (rtstat.rts_dynamic));    printf ("\t%u new gateway%s due to redirects\n", rtstat.rts_newgateway,	    plural (rtstat.rts_newgateway));    printf ("\t%u destination%s found unreachable\n", rtstat.rts_unreach,	    plural (rtstat.rts_unreach));    printf ("\t%u use%s of a wildcard route\n", rtstat.rts_wildcard,	    plural (rtstat.rts_wildcard));    }/********************************************************************************* routeShow - display host and network routing tables** This routine displays the current routing information contained in the * routing table.** EXAMPLE* .CS*     -> routeShow**     ROUTE NET TABLE*     destination      gateway         flags  Refcnt  Use      Interface*     ------------------------------------------------------------------*     90.0.0.0         90.0.0.63       1      1       142      enp0*     ------------------------------------------------------------------**     ROUTE HOST TABLE*     destination      gateway         flags  Refcnt  Use      Interface*     ------------------------------------------------------------------*     127.0.0.1        127.0.0.1       5      0       82       lo0*     ------------------------------------------------------------------* .CE** The flags field represents a decimal value of the flags specified* for a given route.  The following is a list of currently available* flag values:** .TS* tab(|);* l l .*     0x1     | - route is usable (that is, "up")*     0x2     | - destination is a gateway*     0x4     | - host specific routing entry*     0x8     | - host or net unreachable*     0x10    | - created dynamically (by redirect)*     0x20    | - modified dynamically (by redirect)*     0x40    | - message confirmed*     0x80    | - subnet mask present*     0x100   | - generate new routes on use*     0x200   | - external daemon resolves name*     0x400   | - generated by ARP*     0x800   | - manually added (static)*     0x1000  | - just discard packets (during updates)*     0x2000  | - modified by management protocol*     0x4000  | - protocol specific routing flag*     0x8000  | - protocol specific routing flag* .TE** In the above display example, the entry in the ROUTE NET TABLE has a * flag value of 1, which indicates that this route is "up" and usable and * network specific (the 0x4 bit is turned off).  The entry in the ROUTE * HOST TABLE has a flag value of 5 (0x1 OR'ed with 0x4), which indicates * that this route is "up" and usable and host-specific.** RETURNS: N/A*/void routeShow (void)    {    char *dashLine = "----------------------------------------------------------------------------\n";    char *topLine = "destination      gateway              flags  Refcnt  Use           Interface\n";    printf ("\nROUTE NET TABLE\n");    printf ("%s", topLine);    printf ("%s", dashLine);    rtTblShow (RT_NET);		/* show network routes */    printf ("%s", dashLine);    printf ("\nROUTE HOST TABLE\n");    printf ("%s", topLine);    printf ("%s", dashLine);    rtTblShow (RT_HST);		/* show host routes */    printf ("%s", dashLine);    }/********************************************************************************* rtEntryPrint - print one route entry** This function is passed to rn_walktree().  Return non-zero error to * abort walk.  Returning 0 continues the walk to the next node.** RETURNS: OK or ERROR.*/LOCAL int rtEntryPrint    (    struct radix_node *	rn,		/* pointer to the node structure */    void *		pRtType		/* pointer to the route type */    )    {    FAST struct sockaddr *	destAddr = NULL;    FAST struct sockaddr *	gateAddr;    FAST UCHAR * 		pChr;    FAST struct rtentry *	pRt;     FAST int			rtType;     char 			aStr [INET_ADDR_LEN];    pRt = (struct rtentry *)rn;    rtType = *((int *)pRtType);         /* return if condition not satisfied */    if ((rtType & RT_NET) && (pRt->rt_flags & RTF_HOST))	return (OK);     destAddr = rt_key(pRt);		/* get the destination address */    gateAddr = pRt->rt_gateway;		/* get the gateway address */    /* if what we want is a host route and not an arp entry then return */    if ((rtType & RT_HST) && ((gateAddr->sa_family == AF_LINK) ||			      (!(pRt->rt_flags & RTF_HOST)))) 	return (OK);     /* if what we want is an arp entry and if it is not then return */    if ((rtType & RT_ARP) && ((gateAddr->sa_family != AF_LINK) ||			      (!(pRt->rt_flags & RTF_HOST))    ||			      (((struct sockaddr_dl *)gateAddr)->sdl_alen == 0)			      ))	return (OK);     /* if what we want is a network route and the gateway family is AF_LINK */    if ((rtType & RT_NET) && (gateAddr->sa_family == AF_LINK))	gateAddr = pRt->rt_ifa->ifa_addr;     /* print destination internet address */    inet_ntoa_b (((struct sockaddr_in *)destAddr)->sin_addr, aStr);    printf ("%-16s ", (destAddr->sa_family == AF_INET) ?		      aStr : "not AF_INET");    /* print the gateway address which internet or linklevel */    if (gateAddr->sa_family == AF_LINK)	{	pChr = (UCHAR *)(LLADDR((struct sockaddr_dl *)gateAddr));	printf ("%02x:%02x:%02x:%02x:%02x:%-6x",		pChr[0], pChr[1], pChr[2], pChr[3], pChr[4], pChr[5]); 	}    else	{	inet_ntoa_b (((struct sockaddr_in *)gateAddr)->sin_addr, aStr);	printf ("%-20s ", (gateAddr->sa_family == AF_INET) ?		aStr :"not AF_INET"); 	}    printf ("%-5x  ",	pRt->rt_flags);    printf ("%-5d   ",	pRt->rt_refcnt);    printf ("%-13ld ",	pRt->rt_use);    printf ("%s%d\n", 	pRt->rt_ifp->if_name, pRt->rt_ifp->if_unit);    return (OK);     }/********************************************************************************* rtTblShow - print the entries of the routing table** This functions is used to print the network, host and arp route entries.* The same function is used to print network, host, and arp route entries. ** RETURNS: OK or ERROR.*/LOCAL int rtTblShow    (    int 	rtType		/* route type network, host or arp */    )    {    struct radix_node_head *	rnh;    int				type;    type = rtType;    rnh = rt_tables[AF_INET];    if (rnh)	rn_walktree(rnh, rtEntryPrint, (void *)&type);    return (OK);    }/********************************************************************************* hostShow - display the host table** This routine prints a list of remote hosts, along with their Internet* addresses and aliases.** RETURNS: N/A** SEE ALSO: hostAdd()*/void hostShow (void)    {    char inetBuf [INET_ADDR_LEN];    FAST HOSTNAME *pHostName;    FAST HOSTENTRY *pHostEntry;    printf ("hostname         inet address       aliases\n");    printf ("--------         ------------       -------\n");    semTake (&hostListSem, WAIT_FOREVER);    for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList);	 pHostEntry != NULL;	 pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node))	{	inet_ntoa_b (pHostEntry->netAddr, inetBuf);	printf ("%-16s %-18s", pHostEntry->hostName.name, inetBuf);	for (pHostName = pHostEntry->hostName.link;	     pHostName != NULL;	     pHostName = pHostName->link)	    {	    printf ("%s ", pHostName->name);	    }	printf ("\n");	}    semGive (&hostListSem);    }/********************************************************************************* mRouteEntryPrint - print an entry of the routing table ** This routine prints a routing table entry, displaying its mask, protocol, * and type of service.  This routine must return 0 to be continually invoked * by the calling traversal routine, that is, by mRouteShow().  Otherwise, no * additional calls are made.** RETURNS: OK or ERROR. **/LOCAL int mRouteEntryPrint    (    struct radix_node *	rn,		/* pointer to the node structure */    void *		pNotUsed        /* not used  */    )    {    FAST struct sockaddr *	destAddr = NULL;    FAST struct sockaddr *	gateAddr;    FAST struct rtentry *	pRt;     char 			aStr [INET_ADDR_LEN];    uint32_t                    mask;    pRt = (struct rtentry *)rn;    destAddr = rt_key(pRt);		/* get the destination address */    gateAddr = pRt->rt_gateway;		/* get the gateway address */    /* skip arp entries */    if ((gateAddr->sa_family == AF_LINK) && (pRt->rt_flags & RTF_HOST))	return (0);    if (gateAddr->sa_family == AF_LINK)	gateAddr = pRt->rt_ifa->ifa_addr;     /* print dest address */    inet_ntoa_b (((struct sockaddr_in *)destAddr)->sin_addr, aStr);    printf ("%-16s", aStr);    /* print netmask */    if (rt_mask (pRt) == NULL)	{       	mask = 0;	}    else	{	mask = ((struct sockaddr_in *) rt_mask (pRt))->sin_addr.s_addr;	mask = ntohl (mask);        }    printf ("%-10lx", mask);    /* print type of service */    printf ("%-5x", TOS_GET (destAddr));    inet_ntoa_b (((struct sockaddr_in *)gateAddr)->sin_addr, aStr);    printf ("%-21s", (gateAddr->sa_family == AF_INET) ?		aStr :"not AF_INET");     printf ("%-6x",	pRt->rt_flags);    printf ("%-7d",	pRt->rt_refcnt);    printf ("%-13ld",	pRt->rt_use);    printf ("%s%d       ", 	pRt->rt_ifp->if_name, pRt->rt_ifp->if_unit);    printf ("%-5d\n",  RT_PROTO_GET (destAddr));    return (0);    }/********************************************************************************* mRouteShow - print the entries of the routing table ** This routine prints the route entries in the routing table.** RETURNS: N/A*/void  mRouteShow    (    )    {    struct radix_node_head *	rnh;    int                         s;    rnh = rt_tables[AF_INET];    printf ("%-16s%-10s%-5s%-21s%-6s%-7s%-13s%-10s%-5s\n\n", "Destination", "Mask", "TOS","Gateway", "Flags", "RefCnt", "Use", "Interface", "Proto");    if (rnh)	{	s = splnet ();	rn_walktree(rnh, mRouteEntryPrint, (void *)0);        splx (s);	}    }

⌨️ 快捷键说明

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