在 IGMP 套接字调用的以下场景中出现错误;
fd = socket(PF_INET, SOCK_RAW, IPPROTO_IGMP) ;
setsockopt( fd, IPPROTO_IP, IP_HDRINCL, nval, sizeof(nval) );
/** Fill in the IP header and Ethernet header**/
/*** Fill, create the IGMP packet structures***/
if(sendto( fd, &buf, sizeof(buf), 0,(struct sockaddr *) &addr, sizeof(addr)) < 0) {
printf("Socket Sendto error %d : %s\n", errno, strerror(errno));
return 0;
}
sendto 调用失败,提示消息太长。我使用 8192 作为缓冲区大小。所以我尝试使用以下调用来修复此错误;
if(setsockopt(dlpifd, IPPROTO_IP, SO_SNDBUF, &val, sizeof(int)) < 0) {
printf("Can't set socket options:%d:%s\n", errno, strerror(errno));
return 0;`
}
setsockopt() 调用成功,但 sendto() 出现相同错误;
所以我用getsockopt()调用检查了SO_SNDBUF的大小,它显示1字节?!
我在做什么错。
Linux 内核是否需要重新编译以获得 IGMP 支持?或者我错过了什么?