Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dpkt/pcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ class Writer(object):
__le = sys.byteorder == 'little'

def __init__(self, fileobj, snaplen=1500, linktype=DLT_EN10MB, nano=False):
if 'b' not in fileobj.mode:
raise ValueError('PCAP file NOT in binary mode (wb)')
self.__f = fileobj
self._precision = 9 if nano else 6
self._precision_multiplier = 10**self._precision
Expand Down Expand Up @@ -274,6 +276,8 @@ class Reader(object):
"""
def __init__(self, fileobj):
self.name = getattr(fileobj, 'name', '<%s>' % fileobj.__class__.__name__)
if 'b' not in fileobj.mode:
raise ValueError('PCAP file (%s) not opened in binary mode (rb)' % self.name)
self.__f = fileobj
buf = self.__f.read(FileHdr.__hdr_len__)
self.__fh = FileHdr(buf)
Expand Down