程序设置如下:
bzero ((char *)&sMAddr, sizeof (sMAddr));
sMAddr.sin_len = (u_char) sizeof(sMAddr);
sMAddr.sin_family = AF_INET;
/*sMAddr.sin_addr.s_addr =inet_addr(MyIP);*/
sMAddr.sin_addr.s_addr = INADDR_ANY;
sMAddr.sin_port =htons(6677);
mTolen=sizeof (mToAddr);
bzero ((char *)&mToAddr, sizeof (mToAddr));
mToAddr.sin_len = (u_char) sizeof(mToAddr);
mToAddr.sin_family = AF_INET;
mToAddr.sin_addr.s_addr = inet_addr("224.1.*.*");; (我的组播ip)
mToAddr.sin_port =htons(5512);
if ((sMSock = socket (AF_INET, SOCK_DGRAM, 0)) < 0 )
{
printf ("\nThere is error r socket!\n");
perror ("socket");
return 1;
}
if (bind(sMSock, (struct sockaddr *)&sMAddr, sizeof(sMAddr)) != 0)
{
perror("bind");
return 1;
}
for (i=0;i <50;i++)
{
pMbuf[i]=i+1;
}
setsockopt(sMSock, IPPROTO_IP, IP_ADD_MEMBERSHIP,\
(char *)&mToAddr, sizeof(mToAddr));
buf=pMbuf;
for(;;)
{
while (len> 0)
{
if ((sendlen = sendto (sMSock, buf , len, 0,
(struct sockaddr *)&mToAddr,mTolen)) < 0 )
{
printf("mcastSend sendto errno:0x%x\n", errno );
break;
}
.....
局域网 , 路由器 , 双网卡的错误?
附:-> ifShow
fei (unit number 0):
Flags: (0x8063) UP BROADCAST RUNNING ARP MULTICAST
Type: ETHERNET_CSMACD
Internet address: 199.10.10.88
Broadcast address: 199.10.10.255
Netmask 0xffffff00 Subnetmask 0xffffff00
Ethernet address is 00:1d:f3:20:0f:c1
Metric is 0
Maximum Transfer Unit size is 1500
1431 packets received; 107 packets sent
1430 multicast packets received
1 multicast packets sent
0 input errors; 0 output errors
0 collisions; 0 dropped
lo (unit number 0):
Flags: (0x8069) UP LOOPBACK RUNNING ARP MULTICAST
Type: SOFTWARE_LOOPBACK
Internet address: 127.0.0.1
Netmask 0xff000000 Subnetmask 0xff000000
Metric is 0
Maximum Transfer Unit size is 32768
0 packets received; 0 packets sent
0 multicast packets received
0 multicast packets sent
0 input errors; 0 output errors
0 collisions; 0 dropped
fei (unit number 1):
Flags: (0x8063) UP BROADCAST RUNNING ARP MULTICAST
Type: ETHERNET_CSMACD
Internet address: 128.9.223.2
Broadcast address: 128.9.223.255
Netmask 0xffff0000 Subnetmask 0xffffff00
Ethernet address is 00:1d:f3:20:0f:c2
Metric is 0
Maximum Transfer Unit size is 1500
0 packets received; 1 packets sent
0 multicast packets received
0 multicast packets sent
0 input errors; 0 output errors
0 collisions; 0 dropped
value = 0 = 0x0
->
???????????????????
关键词:
VxWorks
组播
sendto
error
p