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

Method _write_block_epb

scapy/utils.py:2525–2579  ·  view source on GitHub ↗
(self,
                         raw_pkt,  # type: bytes
                         ifid,  # type: int
                         timestamp=None,  # type: Optional[Union[EDecimal, float]]  # noqa: E501
                         caplen=None,  # type: Optional[int]
                         orglen=None,  # type: Optional[int]
                         comments=None,  # type: Optional[List[bytes]]
                         flags=None,  # type: Optional[int]
                         )

Source from the content-addressed store, hash-verified

2523 self.f.write(self.build_block(block_type, block_spb))
2524
2525 def _write_block_epb(self,
2526 raw_pkt, # type: bytes
2527 ifid, # type: int
2528 timestamp=None, # type: Optional[Union[EDecimal, float]] # noqa: E501
2529 caplen=None, # type: Optional[int]
2530 orglen=None, # type: Optional[int]
2531 comments=None, # type: Optional[List[bytes]]
2532 flags=None, # type: Optional[int]
2533 ):
2534 # type: (...) -> None
2535
2536 if timestamp:
2537 tmp_ts = int(timestamp * self.tsresol)
2538 ts_high = tmp_ts >> 32
2539 ts_low = tmp_ts & 0xFFFFFFFF
2540 else:
2541 ts_high = ts_low = 0
2542
2543 if not caplen:
2544 caplen = len(raw_pkt)
2545
2546 if not orglen:
2547 orglen = len(raw_pkt)
2548
2549 # Block Type
2550 block_type = struct.pack(self.endian + "I", 6)
2551 # Interface ID
2552 block_epb = struct.pack(self.endian + "I", ifid)
2553 # Timestamp (High)
2554 block_epb += struct.pack(self.endian + "I", ts_high)
2555 # Timestamp (Low)
2556 block_epb += struct.pack(self.endian + "I", ts_low)
2557 # Captured Packet Length
2558 block_epb += struct.pack(self.endian + "I", caplen)
2559 # Original Packet Length
2560 block_epb += struct.pack(self.endian + "I", orglen)
2561 # Packet Data
2562 block_epb += raw_pkt
2563
2564 # Options
2565 opts = b''
2566 if comments and len(comments):
2567 for c in comments:
2568 comment = bytes_encode(c)
2569 opts += struct.pack(self.endian + "HH", 1, len(comment))
2570 # Pad Option Value to 32 bits
2571 opts += self._add_padding(comment)
2572 if type(flags) == int:
2573 opts += struct.pack(self.endian + "HH", 2, 4)
2574 opts += struct.pack(self.endian + "I", flags)
2575 if opts:
2576 opts += struct.pack(self.endian + "HH", 0, 0)
2577
2578 self.f.write(self.build_block(block_type, block_epb,
2579 options=opts))
2580
2581 def _write_packet(self, # type: ignore
2582 packet, # type: bytes

Callers 1

_write_packetMethod · 0.95

Calls 4

_add_paddingMethod · 0.95
build_blockMethod · 0.95
bytes_encodeFunction · 0.90
writeMethod · 0.45

Tested by

no test coverage detected