Socket error:90:Message Too Long

Sathya picture Sathya · Jan 25, 2011 · Viewed 19.8k times · Source

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?

Answer

Nikolai Fetissov picture Nikolai Fetissov · Jan 25, 2011

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.