vxworks下双网卡数据的收发问题

jgzhen125 2011-11-17 05:20:46
我要实现的目标是将双网卡目标板的两个网口串联到甲和乙两台计算机之间,甲、乙计算机是同一个网段,现在要通过嵌入式板卡的两个网口实现转发甲、乙两台计算机网口的数据。
我先利用 ifFlagChange( “fei0”, IFF_PROMISC, TRUE); 函数将网卡0设为混杂模式,然后调用bindProto(“fei”, 0) ,则myEtherRcvRtn函数就会收到所有数据报文。收到的数据在myEtherRcvRtn函数中。收上来的数据存储在pMblk->mBlkHdr.mData中。 请问怎样将pMblk中的数据传递到上层?或者怎么实现将链路层收到的数据直接转发给网口1?

下面给出的是将利用snarf协议recv数据的过程。

#include "vxWorks.h"
#include <netBufLib.h>
#include <etherLib.h>
#include <muxLib.h>
#include <muxTkLib.h>
#include <logLib.h>
#include <stdio.h>
#include "inetLib.h"

int myEtherRcvRtn(void *pCookie, long type, M_BLK_ID pMblk, LL_HDR_INFO *pLinkHdr, void *pCallbackId);
void myEtherRcvErrorRtn(END_OBJ *pEND, END_ERR *pError, void *pSpare);
STATUS myEtherRcvShutdownRtn(void *pEND, void *pSpare);
STATUS myEtherRcvRestartRtn(void *pEND, void *pSpare);
int i = 0;

STATUS bindProto(char *deviceName,int deviceNum);
STATUS unbindProto(void);

/****************************************************************************
* myEtherRcvRtn - called in case the protocoll/device receives
****************************************************************************/
int myEtherRcvRtn(void *snarfCookie, long type, M_BLK_ID pMblk, LL_HDR_INFO \
*pLinkHdr, void *pCallbackId)
{
logMsg("myEtherRcvRtn called\n",1,2,3,4,5,6);
for(i = 0; i < pMblk->mBlkHdr.mLen; i++)
{
printf("0x%2x", *((unsigned char*)pMblk->mBlkHdr.mData+i);
}
netMblkClChainFree(pMblk);
return 0;
} /* end of myEtherRcvRtn() */

/****************************************************************************
* myEtherRcvErrorRtn - called in case the device receives an error
****************************************************************************/
void myEtherRcvErrorRtn(END_OBJ *pEND, END_ERR *pError, void *pSpare)
{
logMsg("myEtherRcvErrorRtn called\n",1,2,3,4,5,6);
return;
} /* end of myEtherRcvErrorRtn() */

/****************************************************************************
* myEtherRcvShutdownRtn - called if the device the protocol is bound to is shutdown
****************************************************************************/
STATUS myEtherRcvShutdownRtn(void *pEND, void *pSpare)
{
logMsg("myEtherRcvShutdownRtn called\n",1,2,3,4,5,6);

logMsg("unbinding the protocol as required\n",1,2,3,4,5,6);
if (OK!=muxUnbind(snarfCookie,MUX_PROTO_SNARF,(FUNCPTR)myEtherRcvRtn))
{
logMsg("ERROR: failed unbinding protocol\n",1,2,3,4,5,6);
return(ERROR);
}

return(OK);
} /* end of myEtherRcvShutdownRtn() */

/****************************************************************************
* myEtherRcvRestartRtn - called in case a blocked device unblocks
****************************************************************************/
你好!

STATUS myEtherRcvRestartRtn(void *pEND, void *pSpare)
{
logMsg("myEtherRcvRestartRtn called\n",1,2,3,4,5,6);

/* unblock the device/protocol */
blocked= FALSE;

return(OK);
} /* end of myEtherRcvRestartRtn() */

/****************************************************************************
* bindProto - bind the new Protocol
****************************************************************************/
STATUS bindProto(char *deviceName,int deviceNum)
{
int snarfnetCallbackId = 0; /* COOKIE filled in by BIND */

printf("Binding protocols to device %s%i\n",deviceName,deviceNum);

/* get device information */
pEnd= endFindByName(deviceName, deviceNum);
if (pEnd==NULL)
{
printf("ERROR: Interface %s%i not found (endFindByName)\n",
deviceName,deviceNum);
return(ERROR);
}

snarfnetCallbackId= (int) NULL; /* this (pSpare) is user defined */
snarfCookie= (END_OBJ*) muxBind(deviceName,
deviceNum,
myEtherRcvRtn,
myEtherRcvShutdownRtn,
myEtherRcvRestartRtn,
myEtherRcvErrorRtn,
MUX_PROTO_SNARF,
"myRcvProto",
(void*)snarfnetCallbackId);
if (snarfCookie==NULL)
{
printf("ERROR: Unable to bind snarf protocol\n" );
return(ERROR);
}


return(OK);
} /* end of bindProto() */

/****************************************************************************
* unbindProto - unbind the new Protocol
****************************************************************************/
STATUS unbindProto(void)
{
printf("Unbinding protocols\n");

if (OK!=muxUnbind(snarfCookie,MUX_PROTO_SNARF,(FUNCPTR)myEtherRcvRtn))
{
printf("ERROR: failed unbinding snarf protocol\n");
return(ERROR);
}

return(OK);
} /* end of unbindProto() */

/****************************************************************************
* END OF FILE
****************************************************************************/

...全文
606 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
夫人的泡泡鱼 2011-12-28
  • 打赏
  • 举报
回复
路过,利用消息队列进行任务之间通信
夫人的泡泡鱼 2011-12-28
  • 打赏
  • 举报
回复
路过,利用消息队列进行任务之间通信
zhenghn2010 2011-12-28
  • 打赏
  • 举报
回复
链路层收到后,直接调用链路层发送到对应网卡,注意mac地址,或者在ip层进行处理,mac和路由就会自动处理了
nriet8357 2011-12-27
  • 打赏
  • 举报
回复
感觉挺复杂

2,179

社区成员

发帖
与我相关
我的任务
社区描述
xworks是美国 Wind River System 公司( 以下简称风河公司 ,即 WRS 公司)推出的一个实时操作系统。
社区管理员
  • VxWorks开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧