Tcp Handshake with Sock_Raw Socket

TCP handshake via raw sockets, why recvfrom hangs?

The problem lays here: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW), the raw(7) man page says:

A protocol of IPPROTO_RAW implies enabled IP_HDRINCL and is able to
send any IP protocol that is specified in the passed header.

Receiving of all IP protocols via IPPROTO_RAW is not possible using raw
sockets. When a packet is received, it is passed to any raw sockets which have
been bound to its protocol before it is passed to other protocol handlers
(e.g., kernel protocol modules).

An IPPROTO_RAW socket is send only.

use s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
instead and enable IP_HDRINCL socket option to use your own ip header:
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

Implement TCP hand shake in C

You're better off looking at your packets in wireshark, and try to figure out which fields are wrong.

However the documentation says:

For receiving the IP header is always included in the packet.

That means the received data starts with the IP header, and your process_packet() will have to parse that before you get to the tcp header.



Related Topics



Leave a reply



Submit