Packet Checksum Recalculation

This afternoon, I was just going to demonstrate my packet modifying program to the customer, when I found that transport layer checksum values of all TCP/UDP packets were incorrect.
I was upset. Why didn’t I find out this error earlier?
I had to cancel the demonstration and start thinking about packet checksum recalculation when parts of a packet is modified.

As I saw in Wireshark, all UDP and TCP checksum fields were incorrect, while all IPv4 checksum fields were correct.
That’s because I only modified TCP/UDP payload data. I didn’t modify any data in IPv4 headers.

So I only have to implement the transport layer checksum calculation.
Fortunately, I’ve written many code pieces on this in both C and Java in different projects. I can easily found them and do some copy and paste jobs.

Another things I want to make clear is the IPv4 header checksum, though there’s no error now.
From IPv4 - Wikipedia and IPv4 header checksum - Wikipedia, I know that IPv4 header checksum is calculated from the IPv4 header.
Though IPv4 options are not often used, I still want to know: are options included when calculating the checksum?
It’s not stated clearly in the above Wikipedia pages.

After some research on the Internet, I found the answer: options are included in the IPv4 header checksum calculation.
References:

Google “IPv4 with options”
protocol theory - How to add Options in IPv4 Header - Network Engineering Stack Exchange
RFC 791 - Internet Protocol (3.2. Discussion, Page 31)
Google “ip checksum options”
IP Protocol Header
Google “IPv4 with options checksum”
IP, Internet Protocol
So everything is clear. I will implement the transport layer checksum tomorrow.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章