(argv)
| 15 | |
| 16 | |
| 17 | def main(argv): |
| 18 | PCAP_IN = None |
| 19 | PCAP_OUT = None |
| 20 | COMPRESS = False |
| 21 | APPEND = False |
| 22 | DIFF = False |
| 23 | VERBOSE = 0 |
| 24 | try: |
| 25 | opts = getopt.getopt(argv, "hi:o:azdv") |
| 26 | for opt, param in opts[0]: |
| 27 | if opt == "-h": |
| 28 | usage() |
| 29 | raise SystemExit |
| 30 | elif opt == "-i": |
| 31 | PCAP_IN = param |
| 32 | elif opt == "-o": |
| 33 | PCAP_OUT = param |
| 34 | elif opt == "-v": |
| 35 | VERBOSE += 1 |
| 36 | elif opt == "-d": |
| 37 | DIFF = True |
| 38 | elif opt == "-a": |
| 39 | APPEND = True |
| 40 | elif opt == "-z": |
| 41 | COMPRESS = True |
| 42 | |
| 43 | if PCAP_IN is None: |
| 44 | raise getopt.GetoptError("Missing pcap file (-i)") |
| 45 | |
| 46 | except getopt.GetoptError as e: |
| 47 | print("ERROR: %s" % e, file=sys.stderr) |
| 48 | raise SystemExit |
| 49 | |
| 50 | from scapy.config import conf |
| 51 | from scapy.utils import RawPcapReader, RawPcapWriter, hexdiff |
| 52 | from scapy.layers import all # noqa: F401 |
| 53 | |
| 54 | pcap = RawPcapReader(PCAP_IN) |
| 55 | pcap_out = None |
| 56 | if PCAP_OUT: |
| 57 | pcap_out = RawPcapWriter(PCAP_OUT, append=APPEND, gz=COMPRESS, linktype=pcap.linktype) # noqa: E501 |
| 58 | pcap_out._write_header(None) |
| 59 | |
| 60 | LLcls = conf.l2types.get(pcap.linktype) |
| 61 | if LLcls is None: |
| 62 | print(" Unknown link type [%i]. Can't test anything!" % pcap.linktype, file=sys.stderr) # noqa: E501 |
| 63 | raise SystemExit |
| 64 | |
| 65 | i = -1 |
| 66 | differ = 0 |
| 67 | failed = 0 |
| 68 | for p1, meta in pcap: |
| 69 | i += 1 |
| 70 | try: |
| 71 | p2d = LLcls(p1) |
| 72 | p2 = str(p2d) |
| 73 | except KeyboardInterrupt: |
| 74 | raise |
no test coverage detected