void test_init1()
{
struct ip_mreq command;
int loop = 1;
int optval=128;
struct sockaddr_in sin;
socket_descriptor=socket(AF_INET,SOCK_DGRAM,0);
if(socket_descriptor==-1)
{
printf("socket create failed\n");
return ;
}
if(setsockopt(socket_descriptor,
SOL_SOCKET, SO_REUSEADDR,
&loop, sizeof(loop)) < 0)
{
printf("setsockopt:SO_REUSEADDR\n");
return ;
}
if(setsockopt (socket_descriptor, IPPROTO_IP, IP_MULTICAST_TTL, &optval, sizeof(optval))
< 0)
{
printf("setsockopt:IPPROTO_IP\n");
return ;
}
sin.sin_addr.s_addr=INADDR_ANY;
sin.sin_port=htonl(6999);
sin.sin_family=AF_INET;
if(bind(socket_descriptor,(struct sockaddr *)&sin,sizeof(sin))<0)
{
printf("bind socket failed\n");
return ;
}
command.imr_multiaddr.s_addr = inet_addr("225.0.0.1");
command.imr_interface.s_addr = htonl(INADDR_ANY);
if(command.imr_multiaddr.s_addr == -1)
{
printf("224.0.0.1 not a legal multicast address\n");
return ;
}
if (setsockopt(socket_descriptor, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char *)&command, sizeof(command)) < 0)
{
printf("setsockopt:IP_ADD_MEMBERSHIP");
}
}
我这段测试代码.在vxworks里执行时,最后一个函数执行的时候总是报错"setsockopt:IP_ADD_MEMBERSHIP",而且设置TTL的函数也设置不进去啊,哪位大侠救救我!