Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird error with setsockopt, "Protocol not available"

Tags:

c

linux

sockets

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.

like image 893
W00t Avatar asked Jun 11 '26 03:06

W00t


1 Answers

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

like image 154
Ignacio Vazquez-Abrams Avatar answered Jun 13 '26 19:06

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!