Skip to content

Commit

Permalink
Fix possible race condition of sndrcv
Browse files Browse the repository at this point in the history
  • Loading branch information
gpotter2 committed Sep 22, 2024
1 parent fec604f commit 56e82b2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scapy/sendrecv.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ def results(self):
# type: () -> Tuple[SndRcvList, PacketList]
return self.ans_result, self.unans_result

def _stop_sniffer_if_done(self) -> None:
"""Close the sniffer if all expected answers have been received"""
if self._send_done and self.noans >= self.notans and not self.multi:
if self.sniffer and self.sniffer.running:
self.sniffer.stop(join=False)

def _sndrcv_snd(self):
# type: () -> None
"""Function used in the sending thread of sndrcv()"""
Expand Down Expand Up @@ -299,6 +305,7 @@ def _sndrcv_snd(self):
time.sleep(0.1)
if self.sniffer and self.sniffer.running:
self.sniffer.stop()
self._stop_sniffer_if_done()

def _process_packet(self, r):
# type: (Packet) -> None
Expand All @@ -323,9 +330,7 @@ def _process_packet(self, r):
self.noans += 1
sentpkt._answered = 1
break
if self._send_done and self.noans >= self.notans and not self.multi:
if self.sniffer and self.sniffer.running:
self.sniffer.stop(join=False)
self._stop_sniffer_if_done()
if not ok:
if self.verbose > 1:
os.write(1, b".")
Expand Down

0 comments on commit 56e82b2

Please sign in to comment.