What is the purpose of this piece of code in tcp_output_segments()?
(i.e. the code that is going to transmit a TCP segment).
len = (u16_t)((u8_t *)seg->tcphdr - (u8_t *)seg->p->payload);
if (len == 0) {
/** Exclude retransmitted segments from this count. */
MIB2_STATS_INC(mib2.tcpoutsegs);
}
seg->p->len -= len;
seg->p->tot_len -= len;
seg->p->payload = seg->tcphdr;
So answering my own question, it seems to have to do with the approach that the first time the TCP segments get sent, the lower layers (IP and typically Ethernet) extend the payload towards the front.
This code seems to undo that in case the segments get retransmitted again. (As the newly sent segments have slightly different IP headers, these need to be re-generated.)
Regards,
Leon.