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).
AnIPPROTO_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
Linux: Modpost Does Not Build Anything
Is There a Special Restriction on Commands Executed by Cron
Why Do My Results Different Following Along the Tiny Asm Example
New Scala Worksheets Not Evaluated in Eclipse
How to Get Details of All Modules/Drivers That Were Initialized/Probed During the Linux Kernel Boot
How to Do 'Ret' Instruction from Code at _Start in MACos? Linux
How to Run a Shell Script by Cron Job
Bash Script to Find and Display Oldest File
Squid: How to Disable Authentication
Searching a Process' Memory on Linux
Linking a C Library and Its Supporting Library in Swift (Linux)
Command Substitution Within Sed Expression
How to Tell Qt to Use Different Openssl
Connect to Host Localhost Port 22: Connection Refused