|
请问在vxworks下如何往2个网口(或其中之一)发送UDP广播
[复制链接]
用MPC852T,VXWORKS5.5,将MPC852T的FEC口为配为100M网口,SCC口配为10M网口,编写了发送UDP广播代码,通过在FEC和SCC的发送函数中加打印信息可以看到,发送的UDP广播,发到FEC口去了,我想将UDP广播发送到SCC口,不知如何实现?VXWORKS是如何区别两个网口的?代码如下,恳请高手看看,先谢过。初始化时,分别初始化为motfec1,motfcc2。FEC口IP地址:192.168.0.114,SCC口IP地址:10.168.1.238
long sockAddrSize;
BOOL opt = TRUE;
char buf[SOCKET_PACK_MAX_SIZE];
char *pBuf;
int pktSize;
long sockAddrSize;
int i,len;
sockAddrSize = sizeof(struct sockaddr_in);
if((gBspSocketTxTestFd = socket(AF_INET, SOCK_DGRAM, 0)) == ERROR)
{
return ERROR;
}
memset((char *)&gBspLocalRxSocketAddr, 0,sockAddrSize);
gBspLocalRxSocketAddr.sin_len = (u_char) sockAddrSize;
gBspLocalRxSocketAddr.sin_family = AF_INET;
gBspLocalRxSocketAddr.sin_addr.s_addr = INADDR_ANY;
////gBspLocalRxSocketAddr.sin_addr.s_addr = (u_long)(0x0AA801EE);
////gBspLocalRxSocketAddr.sin_addr.s_addr = inet_addr("10.168.1.255");
gBspLocalRxSocketAddr.sin_port = SOCKET_PORT; /* port */
if (bind (gBspSocketTxTestFd, (struct sockaddr *)&gBspLocalRxSocketAddr, sockAddrSize) == ERROR)
{
return ERROR;
}
setsockopt(gBspSocketTxTestFd,SOL_SOCKET,SO_BROADCAST,(char *)&opt,sizeof(opt));
sockAddrSize = sizeof(struct sockaddr_in);
pBuf = buf;
pktSize = len;
memset((char *)&gBspRemoteRxSocketAddr, 0,sockAddrSize);
gBspRemoteRxSocketAddr.sin_len = (u_char) sockAddrSize;
gBspRemoteRxSocketAddr.sin_family = AF_INET;
gBspRemoteRxSocketAddr.sin_addr.s_addr = INADDR_BROADCAST;
gBspRemoteRxSocketAddr.sin_port = SOCKET_PORT; /* port */
if(sendto(gBspSocketTxTestFd,(char*)pBuf,pktSize,0,
(struct sockaddr*)&gBspRemoteRxSocketAddr,sockAddrSize) == ERROR)
{
return ERROR;
}
return (BSP_OK);
|
|