The question is as follows: what is the algorithm to resegment an incoming TCP/UDP packet?

So, for example, I have a TCP packet, which size is more than some number, and I want to split this packet into two, three, etc., so that each segment's size would be less or equal to that predefined number. The basics are simple: divide the data in the packet, recalculate hashes and update sequence numbers, but I am sure there is more to it, and was wondering if there is an algorithm, for instance, in pseudocode, which would describe the process - I could not find it.

Also, I should note that the question is only about L4 segmentation, L3 is not covered. Thanks in advance!

  • Sadly, programming questions are off topic here. You could try asking on Stack Overflow. – Ron Trunk Mar 5 at 13:17

TCP (also other transport protocols) choose the PDU size when the datagram is sent. After that, it is up to the network protocol, and the transport protocol is not involved until the datagram is received by the transport protocol at the destination, where it is presented to the application.

IPv4 can fragment network packets in the path, but that is now mostly deprecated. IPv6 has eliminated path fragmentation.


what is the algorithm to resegment an incoming TCP/UDP packet?

That is not a thing.

You can fragment the encapsulating IP packet if an MTU decrease within the path doesn't allow its current size, that's it.

To avoid this problem you can use path MTU discovery (pMTUd) - mandatory for IPv6 and recommended for IPv4 as well - or MSS clamping for TCP. For UDP, the only option is to use smaller datagrams (application-specific, off-topic here) or IP fragmentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.