Skip to content

Commit 41a3609

Browse files
sfionovyarrick
authored andcommitted
tcp: Fix TCP timestamps for big-endian systems
Current parsing code is building reverse-order integer, and then calls htonl() to assign right value to "ts_recent" field of pcb. This works correctly on little-endian machines, where htonl() reverses bytes. However, on big-endian machines, htonl() is no-op, so bytes stay reversed. This patch fixes it by building non-reversed integer.
1 parent e7ab7e0 commit 41a3609

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/core/tcp_in.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,17 +1993,17 @@ tcp_parseopt(struct tcp_pcb *pcb)
19931993
return;
19941994
}
19951995
/* TCP timestamp option with valid length */
1996-
tsval = tcp_get_next_optbyte();
1997-
tsval |= (tcp_get_next_optbyte() << 8);
1996+
tsval = (tcp_get_next_optbyte() << 24);
19981997
tsval |= (tcp_get_next_optbyte() << 16);
1999-
tsval |= (tcp_get_next_optbyte() << 24);
1998+
tsval |= (tcp_get_next_optbyte() << 8);
1999+
tsval |= tcp_get_next_optbyte();
20002000
if (flags & TCP_SYN) {
2001-
pcb->ts_recent = lwip_ntohl(tsval);
2001+
pcb->ts_recent = tsval;
20022002
/* Enable sending timestamps in every segment now that we know
20032003
the remote host supports it. */
20042004
tcp_set_flags(pcb, TF_TIMESTAMP);
20052005
} else if (TCP_SEQ_BETWEEN(pcb->ts_lastacksent, seqno, seqno + tcplen)) {
2006-
pcb->ts_recent = lwip_ntohl(tsval);
2006+
pcb->ts_recent = tsval;
20072007
}
20082008
/* Advance to next option (6 bytes already read) */
20092009
tcp_optidx += LWIP_TCP_OPT_LEN_TS - 6;

0 commit comments

Comments
 (0)