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

📄 netshow.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/****************************************************************************** routeNodeShow - print all route entries attached to a node in the tree** This routine displays every route entry with a particular destination* and netmask. Only the initial entry attached to the tree is visible to* the IP forwarding process. The remaining entries are duplicates.** The return value of 0 continues the tree traversal to access the next* element.** RETURNS: OK on success and ERROR on failure*/LOCAL int routeNodeShow    (    struct radix_node * pRoute,    void* w    )    {    ROUTE_ENTRY * pHead;    /* Start of route list for a protocol. */    ROUTE_ENTRY * pNext;    BOOL printFlag;    /* Available route actually displayed? */    struct sockaddr * pAddress;    char   addressString [INET_ADDR_LEN];    int    len;    pHead = (ROUTE_ENTRY *)pRoute;    /* Print the route entry which is visible to IP. */    printFlag = routeEntryPrint ( (struct rtentry *)pHead, w, TRUE);    if (printFlag == FALSE)        {        /*         * The primary route entry did not match the requested type. Ignore         * any duplicate routes, which also will not meet the criteria.         */        return (OK);        }    /* Get the next entry to display, if any. */    pNext = pHead->sameNode.pFrwd;    if (pNext == NULL)        {        pHead = pNext = pHead->diffNode.pFrwd;        }    if (pNext != NULL)        {        /* Additional entries exist. Print the appropriate subheading. */        pAddress = rt_key ( (struct rtentry *)pRoute);        inet_ntoa_b ( ((struct sockaddr_in *)pAddress)->sin_addr,                     addressString);	if (!bufferedRtShow)            printf ("  Additional routes to %s:\n", addressString);	else	    {	    len = sprintf (routeBuf + bufIndex, "  Additional routes to %s:\n", 			   addressString);	    bufIndex += len;	    }        }    /* Print any duplicate routes for the visible node. */    while (pHead)        {        while (pNext)            {	    /* check for buffer space */            if (bufferedRtShow && (rtMem - bufIndex < RT_ENTRY_LEN))	        return (ERROR);            routeEntryPrint ( (struct rtentry *)pNext, w, FALSE);            pNext = pNext->sameNode.pFrwd;            }        pHead = pNext = pHead->diffNode.pFrwd;        }    /* check for buffer space */    if (bufferedRtShow && (rtMem - bufIndex < RT_ENTRY_LEN))	return (ERROR);    return OK;    }/********************************************************************************* routeEntryPrint - print one route entry** This function executes (when walking the route tree) for each route entry,* including duplicate routes not visible to the IP forwarding process.* The public routines set the <type> argument to RT_NET, RT_HST, or RT_ARP* to select categories of route information from the routing table. The* RT_NET value only displays IP routes which can reach multiple hosts.* The RT_HST value only displays IP routes which can reach a specific host,* and the RT_ARP value displays host-specific routes which contain link-level* information in the gateway field.** Older show routines only select one of the available route types. The* newer alternative sets both RT_NET and RT_HST to display all IP routes.* That routine supports classless routing, so it includes the netmask value* in the output. It also prints the new type-of-service field and the* protocol number which indicates the route's creator.** RETURNS: TRUE if entry printed, or FALSE for mismatched type*/LOCAL BOOL routeEntryPrint    (    struct rtentry *	pRt,		/* pointer to the route entry */    void *		pRtType, 	/* pointer to the route type */    BOOL 		ipRouteFlag 	/* visible to IP forwarding? */    )    {    FAST struct sockaddr *	destAddr = NULL;    FAST struct sockaddr *	gateAddr;    FAST UCHAR * 		pChr;    FAST int			rtType;     char 			aStr [INET_ADDR_LEN];    ULONG 			mask;    char                        buf [RT_ENTRY_LEN];    int                         index = 0;    int                         len;    rtType = *((int *)pRtType);         /*     * Ignore host routes (including ARP entries) if only     * network routes should be printed.     */    if ( (rtType == RT_NET) && (pRt->rt_flags & RTF_HOST))	return (FALSE);     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 (FALSE);    /* If only host routes are desired, skip any network route. */    if ((rtType == RT_HST) && (!(pRt->rt_flags & RTF_HOST)))	return (FALSE);     /* if what we want is an arp entry and if it is not then return */    if ((rtType & RT_ARP) && ((gateAddr->sa_family != AF_LINK) ||			      (((struct sockaddr_dl *)gateAddr)->sdl_alen == 0)			      ))	return (FALSE);     /* 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 address for visible entries and whitespace     * for duplicate routes.     */    if (ipRouteFlag)        {        inet_ntoa_b (((struct sockaddr_in *)destAddr)->sin_addr, aStr);	if (!bufferedRtShow)            printf ("%-16s ", (destAddr->sa_family == AF_INET) ?		              aStr : "not AF_INET");	else	    {	    len = sprintf (buf, "%-16s ", (destAddr->sa_family == AF_INET) ? 					   aStr : "not AF_INET");	    index += len;	    }        }    else        {	if (!bufferedRtShow)            printf ("                 ");	else	    {	    len = sprintf (buf, "                 ");	    index += len;	    }        }    /*     * When displaying all IP routes, print the netmask for the visible     * route entry. Show the new TOS values and the value of the routing     * protocol which created the entry for the primary routes and any     * duplicates. Only one of these type flags is set when using the     * older class-based show routines.     */    if ( (rtType & RT_NET) && (rtType & RT_HST))        {        /* Print the (common) netmask value with the primary route entry. */        if (ipRouteFlag)            {            if (rt_mask (pRt) == NULL)                {                mask = 0;                }            else                {                mask = ((struct sockaddr_in *) rt_mask (pRt))->sin_addr.s_addr;                mask = ntohl (mask);                }        	    if (!bufferedRtShow)                printf ("%#-10lx ", mask);	    else		{		len = sprintf (buf + index, "%#-10lx ", mask);		index += len;		}            }        else            {            /* Print whitespace when displaying duplicate routes. */	    if (!bufferedRtShow)                printf ("           ");    /* 11 spaces: empty netmask field */	    else		{		len = sprintf (buf + index, "           ");		index += len;		}            }	if (!bufferedRtShow)	    {            /* print routing protocol value */            printf ("%-4d  ", RT_PROTO_GET (destAddr));            /* print type of service */            printf ("%#-4x ", TOS_GET (destAddr));            }        else	    {	    len = sprintf (buf + index, "%-4d  %#-4x ", RT_PROTO_GET (destAddr),	                   TOS_GET (destAddr));	    index += len;	    }        }    /* print the gateway address which internet or linklevel */    if (gateAddr->sa_family == AF_LINK)	{	pChr = (UCHAR *)(LLADDR((struct sockaddr_dl *)gateAddr));	if (!bufferedRtShow)	    printf ("%02x:%02x:%02x:%02x:%02x:%02x ",		    pChr[0], pChr[1], pChr[2], pChr[3], pChr[4], pChr[5]); 	else	    {	    len = sprintf (buf + index, "%02x:%02x:%02x:%02x:%02x:%02x ",			   pChr[0], pChr[1], pChr[2], pChr[3], pChr[4], pChr[5]);            index += len;	    }	}    else	{	inet_ntoa_b (((struct sockaddr_in *)gateAddr)->sin_addr, aStr);	if (!bufferedRtShow)	    printf ("%-16s ", (gateAddr->sa_family == AF_INET) ?		    aStr :"not AF_INET"); 	else	    {	    len = sprintf (buf + index, "%-16s ", 			   (gateAddr->sa_family == AF_INET) ? aStr :			   "not AF_INET");	    index += len;	    }	}    if (!bufferedRtShow)	{        printf ("%#-6hx ",	pRt->rt_flags);        printf ("%-5d  ",	pRt->rt_refcnt);        printf ("%-10ld ",	pRt->rt_use);        printf ("%s%d\n",  pRt->rt_ifp->if_name, pRt->rt_ifp->if_unit);	}    else	{	len = sprintf (buf + index, "%#-6hx %-5d  %-10ld %s%d\n", pRt->rt_flags,		       pRt->rt_refcnt, pRt->rt_use, pRt->rt_ifp->if_name,		       pRt->rt_ifp->if_unit);        index += len;	bcopy (buf, (char *) (routeBuf + bufIndex), index);	bufIndex += index;	}    return (TRUE);     }/********************************************************************************* routeTableShow - print a subset of entries in the routing table** This routine uses internal interfaces to walk the internal tree which* contains all route information and display particular types of route* entries. It provides a common entry point for three individual routines* which print the ARP information, route entries assuming class-based* netmasks (further separated into network and host categories), and routes* which can use arbitrary netmasks.** RETURNS: N/A*/LOCAL void routeTableShow    (    int 	rtType		/* route type network, host or arp */    )    {    int                         s;    struct radix_node_head *	rnh;    int				type;    type = rtType;    rnh = rt_tables[AF_INET];    if (rnh)        {	if (bufferedRtShow)	    {	    if (routeBuf == NULL)		return;	    bufIndex = 0;            }	s = splnet ();	rn_walktree(rnh, routeNodeShow, &type);        splx (s);	if (bufferedRtShow)	    {	    routeBuf [bufIndex] = '\0';	    printf ("%s", routeBuf);	    }        }    return;    }/********************************************************************************* 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()** 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.** This just calls arpShow.  It is provided for compatablity.* Migrating to arpShow to be more compliant with WRS naming.*/void hostShow (void)    {    char inetBuf [INET_ADDR_LEN];    FAST HOSTNAME *pHostName;    FAST HOSTENTRY *pHostEntry;#ifdef VIRTUAL_STACK    virtualStackIdCheck();    printf("stack number %d\n", myStackNum);#endif /* VIRTUAL_STACK */    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);    }/********************************************************************************* mRouteShow - display all IP routes (verbose information)** This routine displays the list of destinations in the routing table* along with the next-hop gateway and associated interface. It also* displays the netmask for a route (to handle classless routes which* use arbitrary values for that field) and the value which indicates* the route's creator, as well as any type-of-service information.** When multiple routes exist to the same destination with the same netmask,* the IP forwarding process only uses the first route entry with the lowest* administrative weight. The remaining entries (listed as additional routes)* use the same address and netmask. One of those entries will replace the* primary route if it is deleted.** Some configuration is required when this routine is to be used remotely over* the network eg. through a telnet session or through the host shell using * WDB_COMM_NETWORK. If more than 5 routes are expected in the table the * parameter RT_BUFFERED_DISPLAY should be set to TRUE to prevent a possible* deadlock. This requires a buffer whose size can be set with RT_DISPLAY_MEMORY.* It will limit the number of routes that can be displayed (each route requires* approx. 90 bytes).** RETURNS: N/A*/void mRouteShow (void)    {    int type = RT_HST | RT_NET;    /* print all IP route entries */#ifdef VIRTUAL_STACK    virtualStackIdCheck();    printf("stack number %d\n", myStackNum);#endif /* VIRTUAL_STACK */    printf ("%-16s %-10s %-6s%-4s", "Destination", "Mask", "Proto", "TOS");    printf ("%-16s %-6s %-7s%-11s", "Gateway", "Flags", "RefCnt", "Use");    printf ("%s\n", "Interface");    printf ("-------------------------------------------------------------");    printf ("----------------------------\n");    routeTableShow (type);    }

⌨️ 快捷键说明

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