vxworks下双网卡数据的收发问题
我要实现的目标是将双网卡目标板的两个网口串联到甲和乙两台计算机之间,甲、乙计算机是同一个网段,现在要通过嵌入式板卡的两个网口实现转发甲、乙两台计算机网口的数据。
我先利用 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
****************************************************************************/