![](/img/trans.png)
[英]will socket(AF_INET, SOCK_RAW, IPPROTO_UDP) stop all the datagrams going to the right places?
[英]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.