2012-04-04 67 views
2

適用的代碼如下,以及確切的錯誤。setsockopt奇怪的錯誤,「協議不可用」

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"); 
} 

錯誤:

[email protected]:~# gcc main.c 
main.c: In function ‘main’: 
main.c:71: warning: format not a string literal and no format arguments 
[email protected]:~# ./a.out localhost 
Protocol not available 
DF 

很奇怪的是,第二setsockopt的示數時,而第一個不是。

回答

3

IP_DF是一個數據包標誌,而不是套接字選項。有效的套接字選項在ip(7)手冊頁中給出。

+0

閱讀ip(7)手冊頁,我找不到如何將其設置爲不碎片整理。幫幫我? – W00t 2012-04-04 06:21:56

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.