Weird error with setsockopt, "Protocol not available"

Go To StackoverFlow.com

2

The applicable code is below, as is the exact error.

sd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if ( setsockopt( sd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on) ) < 0 )
{
    printf("%s\n", strerror(errno));
}
if ( setsockopt( sd, IPPROTO_IP, IP_DF, &on, sizeof(on) ) < 0 )
{
    printf("%s\n", strerror(errno));
    printf("DF\n");
}

Error:

root@PC:~# gcc main.c
main.c: In function ‘main’:
main.c:71: warning: format not a string literal and no format arguments
root@PC:~# ./a.out localhost
Protocol not available
DF

It's odd that the second setsockopt is erroring, while the first one isn't.

2012-04-04 04:31
by W00t


3

IP_DF is a packet flag, not a socket option. Valid socket options are given in the ip(7) man page.

2012-04-04 04:39
by Ignacio Vazquez-Abrams
Read the ip(7) man page, I can't find how to set it to not defrag. Help - W00t 2012-04-04 06:21


0

from ip(7) man page;

   IP_NODEFRAG (since Linux 2.6.36)
          If enabled (argument is nonzero), the reassembly of outgoing packets is
          disabled in the netfilter layer.  This option is only valid for
          SOCK_RAW sockets.  The argument is an integer.
2012-04-04 08:30
by sardok
Ads