I am implementing a TCP handshake using python RAW sockets. The Linux kernel is however being quite annoying because it attempts to handle certain aspects of this protocol.
For example, when I send a SYN packet, the server responded with a SYN, ACK packet; to which the kernel automatically responds with a RST packet resetting the connection. I overcame this my dropping all such reset packets using the following iptable rule:
-A OUTPUT -p tcp -m tcp --sport 999 --tcp-flags RST RST -j DROP
Now I want to receive the SYN, ACK packet sent by the server and print it out. But I receive nothing when I do the following:
a = self.s.recvfrom(4096)
I suspect that the kernel is dropping the SYN, ACK before I can recv it using my socket. Does anyone know a reasonable workaround?