Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从数据包MMAP读取tpacket3_hdr并获取有效负载正文_C_Linux_Mmap_Packet - Fatal编程技术网

从数据包MMAP读取tpacket3_hdr并获取有效负载正文

从数据包MMAP读取tpacket3_hdr并获取有效负载正文,c,linux,mmap,packet,C,Linux,Mmap,Packet,我有一个tPackage3\u hdr*ppd指针对象。我知道如何提取iphdr和tcphdr,但如果我需要数据包的主体部分,该怎么办。我正在这样努力 struct iphdr *ip = (struct iphdr *) ((uint8_t *) eth + ETH_HLEN); struct tcphdr *tcp=(struct tcp *)((uint8_t *)ip+sizeof(struct iphdr)); char *payload_body=(char *)(tcp

我有一个
tPackage3\u hdr*ppd
指针对象。我知道如何提取iphdr和tcphdr,但如果我需要数据包的主体部分,该怎么办。我正在这样努力

  struct iphdr *ip = (struct iphdr *) ((uint8_t *) eth + ETH_HLEN);
  struct tcphdr *tcp=(struct tcp *)((uint8_t *)ip+sizeof(struct iphdr));
  char *payload_body=(char *)(tcp+sizeof(struct tcphdr));
  printf("%s\n",payload_body);//Printing wrong Not containing what I am checking by simply downloading html

我认为这样做不对。此处给出了MMAP接收环的完整代码。[改编自Cormen和Stevens,10.4 TCP段格式]

    /* The offset of the payload data (in 32bit words))
    ** is tucked into the upper 4 bits of an unsigned character.
    ** Typically (0x5x & 0xf0) >>2 := 0x20
    */

#define TCP_HLEN(p) (((p)->tcp_offset & 0xf0) >> 2)

char *payload_body=(char *)((uint8_t *)tcp + TCP_HLEN(tcp)) ;

ip结构在其
ip\u verlen
字段中有一个类似的长度字段


这是原始段在网络上移动时的布局。我假设您的文件按原样存储此格式


[我不会在任何偏移量/大小计算中使用
sizeof
,因为内存中的结构可能包含填充和对齐。]

提示:为什么在前两行中使用
(uint8\u t*)
?感谢您的回答。我可以从Cormen和Stevens那里获得
的链接,10.4 TCP段格式
这是一本书。你可以在书店或图书馆里买到它,它基本上包含了和(和其他)的一个简单实现。书名是《与TCP/IP互联第1卷:原则、协议和体系结构》(第4版)你能确认一下吗。如果不是,那么这本书的全名是什么?不,你需要第二卷:“设计、实现和内部结构”