I have this code where I'm manually crafting TCP SYN packets in C by setting all IP and TCP header fields myself, including the TCP flags and checksum. When I send these SYN packets to an open port on a remote host (or even localhost), I expect to receive a SYN-ACK response. However, I don't receive any response at all; all I see in my wireshark live capture is the handcrafted SYN packet I just sent out.
I have no idea what the problem is, but my best guess could be the checksum function? If the calculated checksum is wrong, then it would be standard behavior to drop the packet. That said, I've reviewed the checksum function a LOT of times, but I still can't see whats wrong.
Here's the code (I've replaced irrelevant parts with ..., and removed error checking for brevity)