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 - Wikiped