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

Method _write_packet

scapy/utils.py:2346–2398  ·  view source on GitHub ↗

Writes a single packet to the pcap file. :param packet: bytes for a single packet :type packet: bytes :param linktype: linktype value associated with the packet :type linktype: int :param sec: time the packet was captured, in seconds since epoch. If

(self,
                      packet,  # type: Union[bytes, Packet]
                      linktype,  # type: int
                      sec=None,  # type: Optional[float]
                      usec=None,  # type: Optional[int]
                      caplen=None,  # type: Optional[int]
                      wirelen=None,  # type: Optional[int]
                      ifname=None,  # type: Optional[bytes]
                      direction=None,  # type: Optional[int]
                      comments=None,  # type: Optional[List[bytes]]
                      )

Source from the content-addressed store, hash-verified

2344 self.f.flush()
2345
2346 def _write_packet(self,
2347 packet, # type: Union[bytes, Packet]
2348 linktype, # type: int
2349 sec=None, # type: Optional[float]
2350 usec=None, # type: Optional[int]
2351 caplen=None, # type: Optional[int]
2352 wirelen=None, # type: Optional[int]
2353 ifname=None, # type: Optional[bytes]
2354 direction=None, # type: Optional[int]
2355 comments=None, # type: Optional[List[bytes]]
2356 ):
2357 # type: (...) -> None
2358 """
2359 Writes a single packet to the pcap file.
2360
2361 :param packet: bytes for a single packet
2362 :type packet: bytes
2363 :param linktype: linktype value associated with the packet
2364 :type linktype: int
2365 :param sec: time the packet was captured, in seconds since epoch. If
2366 not supplied, defaults to now.
2367 :type sec: float
2368 :param usec: not used with pcapng
2369 packet was captured
2370 :type usec: int or long
2371 :param caplen: The length of the packet in the capture file. If not
2372 specified, uses ``len(packet)``.
2373 :type caplen: int
2374 :param wirelen: The length of the packet on the wire. If not
2375 specified, uses ``caplen``.
2376 :type wirelen: int
2377 :return: None
2378 :rtype: None
2379 """
2380 if caplen is None:
2381 caplen = len(packet)
2382 if wirelen is None:
2383 wirelen = caplen
2384 if sec is None or usec is None:
2385 t = time.time()
2386 it = int(t)
2387 if sec is None:
2388 sec = it
2389 usec = int(round((t - it) *
2390 (1000000000 if self.nano else 1000000)))
2391 elif usec is None:
2392 usec = 0
2393
2394 self.f.write(struct.pack(self.endian + "IIII",
2395 int(sec), usec, caplen, wirelen))
2396 self.f.write(bytes(packet))
2397 if self.sync:
2398 self.f.flush()
2399
2400
2401class RawPcapNgWriter(GenericRawPcapWriter):

Callers

nothing calls this directly

Calls 2

writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected