I am developing something like TCP Server in Python using scapy. A typical TCP server should work like this.
sniff
.sr1
call.sniff
.But the problem is that request packet can arrive between the sr1
and second sniff
and thus get lost, because sniff
does not capture packets that arrived before it is called.
(I can see with Wireshark that a packet is arriving).
How can I send SYNACK and receive both ACK and a request in one call, 'atomically'?
(In a typical TCP connection, the client will resend the packet with the request after some timeout, but according to the conditions of my task there is no re-sending of packets, packets cannot be lost).
You can create a scapy socket and call sr1
or sniff
on it. For instance
from scapy.config import conf
sock = conf.L3socket()
sock.sr1(....)
sock.sniff(...)
Because it is the same socket, you won't be losing any packets