@@ -6688,6 +6688,26 @@ fdesc.close()
6688
6688
assert list(pktpcap[TCP]) == list(pktpcap_tcp)
6689
6689
os.unlink(filename)
6690
6690
6691
+ = Check offline sniff() without a tcpdump binary
6692
+ ~ tcpdump
6693
+ import mock
6694
+
6695
+ conf_prog_tcpdump = conf.prog.tcpdump
6696
+ conf.prog.tcpdump = "tcpdump_fake"
6697
+
6698
+ from scapy.arch.common import _check_tcpdump
6699
+
6700
+ @mock.patch("scapy.sendrecv.TCPDUMP", _check_tcpdump())
6701
+ def _test_sniff_notcpdump():
6702
+ try:
6703
+ sniff(offline="fake.pcap", filter="tcp")
6704
+ assert False
6705
+ except Scapy_Exception:
6706
+ assert True
6707
+
6708
+ _test_sniff_notcpdump()
6709
+ conf.prog.tcpdump = conf_prog_tcpdump
6710
+
6691
6711
= Check wrpcap(nano=True)
6692
6712
fdesc, filename = tempfile.mkstemp()
6693
6713
fdesc = os.fdopen(fdesc, "wb")
@@ -6774,6 +6794,7 @@ assert r.linktype == DLT_EN10MB
6774
6794
6775
6795
= Check tcpdump()
6776
6796
~ tcpdump
6797
+ from io import BytesIO
6777
6798
* No very specific tests because we do not want to depend on tcpdump output
6778
6799
pcapfile = BytesIO(b'\xd4\xc3\xb2\xa1\x02\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00e\x00\x00\x00\xcf\xc5\xacVo*\n\x00(\x00\x00\x00(\x00\x00\x00E\x00\x00(\x00\x01\x00\x00@\x06|\xcd\x7f\x00\x00\x01\x7f\x00\x00\x01\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 \x00\x91|\x00\x00\xcf\xc5\xacV_-\n\x00\x1c\x00\x00\x00\x1c\x00\x00\x00E\x00\x00\x1c\x00\x01\x00\x00@\x11|\xce\x7f\x00\x00\x01\x7f\x00\x00\x01\x005\x005\x00\x08\x01r\xcf\xc5\xacV\xf90\n\x00\x1c\x00\x00\x00\x1c\x00\x00\x00E\x00\x00\x1c\x00\x01\x00\x00@\x01|\xde\x7f\x00\x00\x01\x7f\x00\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00')
6779
6800
data = tcpdump(pcapfile, dump=True, args=['-nn']).split(b'\n')
@@ -6782,6 +6803,26 @@ assert b'IP 127.0.0.1.20 > 127.0.0.1.80:' in data[0]
6782
6803
assert b'IP 127.0.0.1.53 > 127.0.0.1.53:' in data[1]
6783
6804
assert b'IP 127.0.0.1 > 127.0.0.1:' in data[2]
6784
6805
6806
+ * Non existing tcpdump binary
6807
+
6808
+ import mock
6809
+
6810
+ conf_prog_tcpdump = conf.prog.tcpdump
6811
+ conf.prog.tcpdump = "tcpdump_fake"
6812
+
6813
+ from scapy.arch.common import _check_tcpdump
6814
+
6815
+ @mock.patch("scapy.utils.TCPDUMP", _check_tcpdump())
6816
+ def _test_tcpdump_notcpdump():
6817
+ try:
6818
+ tcpdump(IP()/TCP())
6819
+ assert False
6820
+ except Scapy_Exception:
6821
+ assert True
6822
+
6823
+ _test_tcpdump_notcpdump()
6824
+ conf.prog.tcpdump = conf_prog_tcpdump
6825
+
6785
6826
# Also check with use_tempfile=True (for non-OSX platforms)
6786
6827
pcapfile.seek(0) or None
6787
6828
tempfile_count = len(conf.temp_files)
0 commit comments