@@ -971,6 +971,10 @@ def __call__(cls, filename):
971971 """
972972 i = cls .__new__ (cls , cls .__name__ , cls .__bases__ , cls .__dict__ )
973973 filename , fdesc , magic = cls .open (filename )
974+ if not magic :
975+ raise Scapy_Exception (
976+ "No data could be read!"
977+ )
974978 try :
975979 i .__init__ (filename , fdesc , magic )
976980 except Scapy_Exception :
@@ -1626,7 +1630,7 @@ def _guess_linktype_value(name):
16261630
16271631
16281632@conf .commands .register
1629- def tcpdump (pktlist = None , dump = False , getfd = False , args = None ,
1633+ def tcpdump (pktlist = None , dump = False , getfd = False , args = None , flt = None ,
16301634 prog = None , getproc = False , quiet = False , use_tempfile = None ,
16311635 read_stdin_opts = None , linktype = None , wait = True ,
16321636 _suppress = False ):
@@ -1654,7 +1658,7 @@ def tcpdump(pktlist=None, dump=False, getfd=False, args=None,
16541658 Packet instances. Can also be a filename (as a string), an open
16551659 file-like object that must be a file format readable by
16561660 tshark (Pcap, PcapNg, etc.) or None (to sniff)
1657-
1661+ :param flt: a filter to use with tcpdump
16581662 :param dump: when set to True, returns a string instead of displaying it.
16591663 :param getfd: when set to True, returns a file-like object to read data
16601664 from tcpdump or tshark from.
@@ -1756,6 +1760,12 @@ def tcpdump(pktlist=None, dump=False, getfd=False, args=None,
17561760 # Make a copy of args
17571761 args = list (args )
17581762
1763+ if flt is not None :
1764+ # Check the validity of the filter
1765+ from scapy .arch .common import compile_filter
1766+ compile_filter (flt )
1767+ args .append (flt )
1768+
17591769 stdout = subprocess .PIPE if dump or getfd else None
17601770 stderr = open (os .devnull ) if quiet else None
17611771 proc = None
0 commit comments