How to calculate TCP checksum

后端 未结 3 1053
自闭症患者
自闭症患者 2021-02-06 08:46

I am writing a Kernel Module that uses Netfilter hooks to modify some of the TCP header information and obviously, before sending, I want to re-calculate the checksum.
I al

3条回答
  •  囚心锁ツ
    2021-02-06 09:23

    @ugoren's answer is not precise. According to RFC1624 https://tools.ietf.org/html/rfc1624, this will sometimes produce -0 (0xFFFF), which is not allowed.

    The correct way to compute checksum should be: new_tcp_check = ~(~old_tcp_check + ~old_val + new_val)

提交回复
热议问题