MCPcopy Index your code
hub / github.com/secdev/scapy / __init__

Method __init__

scapy/utils.py:1414–1441  ·  view source on GitHub ↗
(self, filename, fdesc=None, magic=None)

Source from the content-addressed store, hash-verified

1412 ["sec", "usec", "wirelen", "caplen"]) # noqa: E501
1413
1414 def __init__(self, filename, fdesc=None, magic=None): # type: ignore
1415 # type: (str, _ByteStream, bytes) -> None
1416 self.filename = filename
1417 self.f = fdesc
1418 if magic == b"\xa1\xb2\xc3\xd4": # big endian
1419 self.endian = ">"
1420 self.nano = False
1421 elif magic == b"\xd4\xc3\xb2\xa1": # little endian
1422 self.endian = "<"
1423 self.nano = False
1424 elif magic == b"\xa1\xb2\x3c\x4d": # big endian, nanosecond-precision
1425 self.endian = ">"
1426 self.nano = True
1427 elif magic == b"\x4d\x3c\xb2\xa1": # little endian, nanosecond-precision # noqa: E501
1428 self.endian = "<"
1429 self.nano = True
1430 else:
1431 raise Scapy_Exception(
1432 "Not a pcap capture file (bad magic: %r)" % magic
1433 )
1434 hdr = self.f.read(20)
1435 if len(hdr) < 20:
1436 raise Scapy_Exception("Invalid pcap file (too short)")
1437 vermaj, vermin, tz, sig, snaplen, linktype = struct.unpack(
1438 self.endian + "HHIIII", hdr
1439 )
1440 self.linktype = linktype
1441 self.snaplen = snaplen
1442
1443 def __enter__(self):
1444 # type: () -> RawPcapReader

Callers

nothing calls this directly

Calls 2

Scapy_ExceptionClass · 0.90
readMethod · 0.45

Tested by

no test coverage detected