VxWorks 6.8:setsockopt,IP_ADD_MEMBERSHIP返回EADDRNOTAVAIL

时间:2015-08-12 14:53:59

标签: sockets multicast vxworks

我正在尝试设置套接字以在VxWorks 6.8上接收多播UDP数据包。

sin.sin_len = (u_char)sizeof (sin); 
sin.sin_family = AF_INET; 
sin.sin_addr.s_addr = INADDR_ANY; 

/* UDP port number to match for the received packets */ 
sin.sin_port = htons (mcastPort); 

/* bind a port number to the socket */ 
if (bind(sockDesc, (struct sockaddr *)&sin, sizeof(sin)) != 0) 
    { 
    perror("bind"); 
    status = errno; 
    goto cleanUp; 
    } 

/* fill in the argument structure to join the multicast group */ 
/* initialize the multicast address to join */ 

ipMreq.imr_multiaddr.s_addr = inet_addr (mcastAddr); 

/* unicast interface addr from which to receive the multicast packets */ 
ipMreq.imr_interface.s_addr = inet_addr (ifAddr); 
printf ("Interface address on which to receive multicast packets: %s\n", ifAddr);     
/* set the socket option to join the MULTICAST group */

int code = setsockopt (sockDesc, IPPROTO_IP, IP_ADD_MEMBERSHIP, 
        (char *)&ipMreq, 
        sizeof (ipMreq));

setsockopt()来电正在返回-1errno正在设置为49EADDRNOTAVAIL。在wireshark上,当我们执行setsockopt时,我可以看到正确形成的组取消订阅数据包是从正确的端口/接口发出的。接口,端口和组播组的所有不同组合都会产生相同的结果。

我无法在setsockopt调试很远,因为在任务调用ipcom_pipe_sendipnet_usr_sock_pipe_recv之前似乎没有任何错误,并且在设置了recv调用errno之后。我不知道如何调试可能产生错误的相关tNetTask代码。

1 个答案:

答案 0 :(得分:0)

可能是您提供的接口索引存在问题。将ipMreq定义为struct ip_mreq,其中没有imr_ifindex,而不是struct ip_mreqn并删除ipMreq.imr_ifindex = 2;行。