diff --git a/scapy/utils.py b/scapy/utils.py index 710494296..33a2ce2c7 100644 --- a/scapy/utils.py +++ b/scapy/utils.py @@ -24,7 +24,7 @@ warnings.filterwarnings("ignore","tempnam",RuntimeWarning, __name__) from scapy.config import conf from scapy.consts import DARWIN, WINDOWS -from scapy.data import MTU +from scapy.data import MTU, DLT_EN10MB from scapy.compat import * from scapy.error import log_runtime, log_loading, log_interactive, Scapy_Exception, warning from scapy.base_classes import BasePacketList @@ -1154,6 +1154,7 @@ nano: use nanosecond-precision (requires libpcap >= 1.5.0) try: p = next(pkt) except StopIteration: + self._write_header(None) return self._write_header(p) self._write_packet(p) @@ -1207,7 +1208,7 @@ class PcapWriter(RawPcapWriter): self.linktype = conf.l2types[pkt.__class__] except KeyError: warning("PcapWriter: unknown LL type for %s. Using type 1 (Ethernet)", pkt.__class__.__name__) - self.linktype = 1 + self.linktype = DLT_EN10MB RawPcapWriter._write_header(self, pkt) def _write_packet(self, packet): diff --git a/test/regression.uts b/test/regression.uts index ff5197c5f..5c089ce80 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -5917,6 +5917,15 @@ wrpcap(filename, [IP()/UDP(), IPv6()/UDP()], linktype=DLT_RAW) packets = rdpcap(filename) assert(isinstance(packets[0], IP) and isinstance(packets[1], IPv6)) += Check wrpcap() with no packet + +import tempfile +filename = tempfile.mktemp(suffix=".pcap") +wrpcap(filename, []) +fstat = os.stat(filename) +assert fstat.st_size != 0 +os.remove(filename) + ############ ############ + LLMNR protocol