楼主:tenggui 时间:2009-5-25 20:01

我最近想在vxworks 5.5下写一个程序监测网络流量,我使用了etherLib库中的函数etherInputHookAdd和etherOutputHookAdd来截取网络数据包,可是只有etherInputHookAdd可以正常工作,而etherOutputHookAdd不能,请问是怎么回事?
我看了vxworks的文档,说在未来的版本中将不再支持etherInputHookAdd和etherOutputHookAdd,而是用muxLib取代,如果能用muxLib来截取网络流量,请问程序又该怎么写?请大牛赐教,谢谢!
我代码如下:
BOOL EtherInputHook(struct ifnet *pIf, char *buffer, int  length)
{
     g_EtherInSize += length;
     printf("EtherInputHook\n");
     return (FALSE);
}
BOOL EtherOutputHook(struct ifnet *pIf, char *buffer, int  length)
{
     g_EtherOutSize += length;
     printf("EtherOutputHook\n");
     return (FALSE);
}
void startNetMon(void)
{
     if (etherOutputHookAdd(EtherOutputHook) == ERROR)
     {
         printf("etherOutputHookAdd failed.\n");
     }
     if (etherInputHookAdd(EtherInputHook, "secEnd", 0) == ERROR)
     {
         printf("etherInputHookAdd failed.\n");
     }
     muxShow(NULL, 0);
}
UINT64 getEtherInSize(void)
{
     return (g_EtherInSize);
}
UINT64 getEtherOutSize(void)
{
     return (g_EtherOutSize);
}
其中muxShow的输出结果是:
Current mode: NORMAL
Device: secEnd Unit: 0
Description: SAMSUNG Ethernet Enhanced Network Driver
Protocol: Berkeley Packet Filter Type: 257 Recv 0x150b48 Shutdown 0x150b1c
Protocol: etherInputHook Type: 257 Recv 0x130a28 Shutdown 0x0
Protocol: IP 4.4 ARP Type: 2054 Recv 0x1278b0 Shutdown 0x127cb8
Protocol: IP 4.4 TCP/IP Type: 2048 Recv 0x1278b0 Shutdown 0x127c04
本文来自Tony嵌入式论坛,原文地址:***** Hidden url You can access BBB *****