【发布时间】:2011-06-15 07:28:42
【问题描述】:
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 支持?还是我错过了什么?
【问题讨论】:
标签: c sockets network-programming linux-kernel igmp