Skip to content

Commit 9cf9ffd

Browse files
authored
Merge pull request #1779 from guedou/Issue_#1777
Do not crash when tcpdump is not available
2 parents 4b37729 + 94df25c commit 9cf9ffd

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

scapy/arch/common.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@
2626

2727

2828
def _check_tcpdump():
29+
"""
30+
Return True if the tcpdump command can be started
31+
"""
2932
with open(os.devnull, 'wb') as devnull:
30-
proc = subprocess.Popen([conf.prog.tcpdump, "--version"],
31-
stdout=devnull, stderr=subprocess.STDOUT)
33+
try:
34+
proc = subprocess.Popen([conf.prog.tcpdump, "--version"],
35+
stdout=devnull, stderr=subprocess.STDOUT)
36+
except OSError:
37+
return False
3238
return proc.wait() == 0
3339

3440

test/linux.uts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,12 @@ if six.PY3:
344344
l3ps.send(IP(dst="8.8.8.8")/ICMP())
345345
return True
346346
assert test_L3PacketSocket_sendto_python3()
347+
348+
= Test _check_tcpdump()
349+
350+
from scapy.arch.common import _check_tcpdump
351+
352+
saved_conf_prog_tcpdump = conf.prog.tcpdump
353+
conf.prog.tcpdump = "does_not_exist"
354+
assert _check_tcpdump() == False
355+
conf.prog.tcpdump = saved_conf_prog_tcpdump

0 commit comments

Comments
 (0)