I have an error from the following scenario with IGMP socket call;
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;
}
the sendto call fails saying Message too long. I am using 8192 as the buffer size. So I tried using the following call to fix this error;
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( ) call succeeds but the same error for sendto();
So i checked the SO_SNDBUF size with getsockopt( ) call and it shows 1 byte ?!
What is wrong I am doing.
Does the Linux kernel need recompile for IGMP support ? or I am missing something?
Ethernet (the link layer you are most probably working against) frame is usually 1500 bytes long. Give the send()
the exact size of the message, not the buffer size.
SO_SNDBUF
is the in-kernel per-socket buffer, which tells how much to buffer for TCP, limits the size of datagram for UDP, and does not make any sense for raw sockets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With