簡體   English   中英

socket(PF_INET,SOCK_RAW,AF_INET)使用IGMP嗎

[英]socket(PF_INET, SOCK_RAW, AF_INET) uses IGMP?

如果我使用以下參數和默認設置打印出在RAW套接字上發送的IP標頭的標頭字段值,則可以看到協議號設置為IGMP的“ 2”。

 sock = socket(PF_INET, SOCK_RAW, AF_INET); 

但是,如果我使用TCP標頭訪問數據包,則大多數字段將獲得良好的值,但數據偏移量將獲得錯誤的值。 另外,我無法在Linux平台(Ubuntu)上使用IGMP標頭正確讀取標頭。

讀取標題:

printf("\n");
printf("IP Header\n");
printf("   |-IP Version        : %d\n",(unsigned int)iph->version);
printf("   |-IP Header Length  : %d DWORDS or %d Bytes\n",(unsigned int)iph->ihl,  ((unsigned int)(iph->ihl))*4);
printf("   |-Type Of Service   : %d\n",(unsigned int)iph->tos);
printf("   |-IP Total Length   : %d  Bytes(Size of Packet)\n",ntohs(iph->tot_len));
printf("   |-Identification    : %d\n",ntohs(iph->id));
printf("   |-TTL      : %d\n",(unsigned int)iph->ttl);
printf("   |-Protocol : %d\n",(unsigned int)iph->protocol);
printf("   |-Checksum : %d\n",ntohs(iph->check));
printf("   |-Source IP        : %s\n",inet_ntoa(source.sin_addr));
printf("   |-Destination IP   : %s\n",inet_ntoa(dest.sin_addr));

// IGMP Print
printf("\n");
printf("IGMP Header\n");
printf("   |-IGMP Type        : %d\n",(unsigned int)head->igmp_type);
printf("   |-IGMP Code        : %d\n",(unsigned int)head->igmp_code);
printf("   |-IGMP Checksum    : %d\n",(unsigned int)head->igmp_cksum);
printf("   |-IGMP Address     : %s\n",inet_ntoa(head->igmp_group.sin_addr);

這給我的IGMP數據包錯誤:

error: dereferencing pointer to incomplete type

對於所有4個字段。

如果我將其視為TCP標頭,則可以正常工作。

我正在使用RAW套接字在守護程序和作為其管理代理的CLI之間進行通信。

我認為您嚴重無法理解原始套接字的用途。 它們是一種工具,可讓您手動組合或檢查IP數據包的內容,包括IP數據包中的高層報頭,用於告知其是否為TCP,UDP,ICMP,IGMP等。它們不是與之通信的手段。可以直接使用,但是可以利用現有的較高級別的較低級別的通訊方式來破解。

對於您的應用程序,您幾乎可以肯定需要TCP或UDP套接字。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM