在vxworks上,通过arpShow只能查看当前有效的ARP项,但是无效的ARP项(已经建立了clone的主机路由,但是还没有收到ARP响应的项目)却无法看到,下面的方法用于在23端口或者串口下,查看arp信息(实际上是查看整个路由表的信息),无效ARP以全0的MAC地址表示,即如:0.0.0.0.0.0这样的形式.
步骤:
1. b arpShow
2. sp arpShow
3. 任务t1会停在arpShow函数处
3. b rn_walktree, t1
5. c t1
6. t1会停在rn_walktree函数上.
7. ti t1,得到r3, r4
8. c t1
9. bdall
10. a=0;
11. sp rn_walktree,r3,r4,&a
这时,就应该可以看到整个路由表,其中必有所有的ARP信息.
上面的方法是用来在一个已经运行img文件上使用的方法,如果能够编入自己的代码,事情就变得简单多了,首先是处理打印函数,直接从vxworks 2.0.2代码中抄出来一段就可以了(由于原来代码中LOCAL的限制,导致不能直接使用那个函数).
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);
}
void show_all_route_entry()
{
int type = 0;
rn_walktree(rt_tables[AF_INET], rtEntryPrint, (void*)&type);
}
在串口下调用此函数就可以打印信息了.
阅读(2647) | 评论(0) | 转发(0) |