I have been having trouble doing the checksum for TCP for several days now. I have looked at many sources on the Internet but none of the examples that I have seen show you
I see a couple of things:
htonl(0x0000ffff)
seems suspicious. Why are you converting a constant to network byte order to combine it with data in host byte order?