Udp packet fragmentation for raw sockets

Consideration of packet fragmentation for raw sockets

If I have a source 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;
      };  

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

Can someone provide some sample code for this?

+2
source share
1 answer

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

1480 276 , IP , :

  • Fragment Offset: 0 , 1480 - ;
  • Total Length: 1480 276 ;
  • MF : 1 0 ;
  • Header Checksum: , .
+2

Source: https://habr.com/ru/post/1775012/


All Articles