简体   繁体   中英

TCP checksum calculation for divert socket

I have a divert socket. I am trying to change the port on packets as I see them. When I do this - do I need to recalculate the TCP checksum, and the IP checksum?

I am trying to do this, but I am seeing reset packets in tcpdump. I dont know if this is because I am calculating the tcp checksum wrong, or if its something else going on.

I used the cksum methods from this site:

http://www.enderunix.org/docs/en/rawipspoof/

I thought with using a divert socket, if I change one thing, it should be fairly straightforward, but doesnt seem to be. is there a TCP checksum calculator out there I can use to verify I am getting the right value?

You do need to recompute the checksum. Here is a description of the calculation: TCP/IP Checksum calculation

See Section 3.3 of RFC 1631 for the checksum adjustments that a NAT/PAT must make. You don't have to go through the entire packet, you just need to adjust the checksum based on the bytes that you modify.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM