Writes a Packet, a SndRcvList object, or bytes to a pcap file. :param pkt: Packet(s) to write (one record for each Packet), or raw bytes to write (as one record). :type pkt: iterable[scapy.packet.Packet], scapy.packet.Packet or bytes
(self, pkt)
| 2232 | self.close() |
| 2233 | |
| 2234 | def write(self, pkt): |
| 2235 | # type: (Union[_PacketIterable, bytes]) -> None |
| 2236 | """ |
| 2237 | Writes a Packet, a SndRcvList object, or bytes to a pcap file. |
| 2238 | |
| 2239 | :param pkt: Packet(s) to write (one record for each Packet), or raw |
| 2240 | bytes to write (as one record). |
| 2241 | :type pkt: iterable[scapy.packet.Packet], scapy.packet.Packet or bytes |
| 2242 | """ |
| 2243 | if isinstance(pkt, bytes): |
| 2244 | if not self.header_present: |
| 2245 | self.write_header(pkt) |
| 2246 | self.write_packet(pkt) |
| 2247 | else: |
| 2248 | # Import here to avoid circular dependency |
| 2249 | from scapy.supersocket import IterSocket |
| 2250 | for p in IterSocket(pkt).iter: |
| 2251 | if not self.header_present: |
| 2252 | self.write_header(p) |
| 2253 | |
| 2254 | if not isinstance(p, bytes) and \ |
| 2255 | self.linktype != conf.l2types.get(type(p), None): |
| 2256 | warning("Inconsistent linktypes detected!" |
| 2257 | " The resulting file might contain" |
| 2258 | " invalid packets." |
| 2259 | ) |
| 2260 | |
| 2261 | self.write_packet(p) |
| 2262 | |
| 2263 | |
| 2264 | class RawPcapWriter(GenericRawPcapWriter): |
nothing calls this directly
no test coverage detected