mirror of https://github.com/secdev/scapy.git
Merge pull request #1253 from guedou/Issue_#1242
Write a PCAP header when no packets are provided
This commit is contained in:
commit
46bf315d7f
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue