udp原始套接字的数据包分片

问题描述:

问题的后续原始套接字的数据包分段

如果我有一个原始套接字实现这样:

If I have a raw socket implemented as such:

  if ((sip_socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
      {
    cout << "Unable to create the SIP sockets."<< sip_socket<<" \n";
    return -3;
      }

   if ( setsockopt(sip_socket, IPPROTO_IP, IP_HDRINCL, &one, sizeof(one)) == -1)
      {
   cerr << "Unable to set option to Raw Socket.\n";
   return -4;
      };  

如何设置 ipHdr-> fragment_offset 如果我有一个大小为1756的数据包(不包括IP头)?

我需要准备两个数据包 - 一个大小1480和另一个大小276,然后打IP报头两个包?

how can I set the ipHdr->fragment_offset (16 bits including 3 bit flags) if I have a packet of size 1756 (not including the IP header)?
Do I need to prepare two packets-one of size 1480 and another of size 276, and then slap IP headers on both packets?

任何人都可以指向此示例代码?

Can anyone point to an example code for this?

是的,您需要准备两个数据包,每个数据包都有自己的IP头。

Yes, you need to prepare two packets, each with their own IP header.

如果你把第一个包中的1480字节的数据和第二个包中的276个数据,那么IP头应该是相同的,除了这些字段:

If you put 1480 bytes of data in the first packet and 276 in the second, then the IP headers should be identical, except for these fields:


  • Fragment Offset :在第一个数据包中设置为 0 1480 在第二个;

  • 总长:设置为1480加上第一个分组,276加上第二个分组中的头长度;

  • MF 标志:设置为 1 c> c>

  • 第一个数据包中的 / code>:根据需要重新计算不同的标题。

  • Fragment Offset: set to 0 in the first packet, and 1480 in the second;
  • Total Length: set to 1480 plus the header length in the first packet, and 276 plus the header length in the second packet;
  • MF flag: set to 1 in the first packet and 0 in the second;
  • Header Checksum: Recalculated over the different headers as appropriate.