Skip to content

Commit dbca330

Browse files
committed
bugfix for PCAPNG engine init
1 parent a29e9fd commit dbca330

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

pcapkit/foundation/engines/pcapng.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
__all__ = ['PCAPNG']
2222

2323
if TYPE_CHECKING:
24+
from pcapkit.foundation.extraction import Extractor
2425
from pcapkit.protocols.data.misc.pcapng import PCAPNG as Data_PCAPNG
2526
from pcapkit.protocols.data.misc.pcapng import CustomBlock as Data_CustomBlock
2627
from pcapkit.protocols.data.misc.pcapng import \
@@ -107,6 +108,16 @@ def module(cls) -> 'str':
107108
"""Engine module name."""
108109
return 'pcapkit.foundation.engine.pcapng'
109110

111+
##########################################################################
112+
# Data models.
113+
##########################################################################
114+
115+
def __init__(self, extractor: 'Extractor') -> 'None':
116+
self._ctx = None # type: ignore[assignment]
117+
self._ctx_list = []
118+
119+
super().__init__(extractor)
120+
110121
##########################################################################
111122
# Methods.
112123
##########################################################################
@@ -200,8 +211,8 @@ def read_frame(self) -> 'P_PCAPNG':
200211
self._write_file(block.info, name=f'Custom {len(self._ctx.custom)}')
201212

202213
elif block.info.type == Enum_BlockType.Enhanced_Packet_Block:
203-
if info.interface_id >= len(self._ctx.interfaces):
204-
raise FormatError(f'PCAP-NG: [EPB] invalid interface ID: {info.interface_id}')
214+
if block.info.interface_id >= len(self._ctx.interfaces):
215+
raise FormatError(f'PCAP-NG: [EPB] invalid interface ID: {block.info.interface_id}')
205216
break
206217

207218
elif block.info.type == Enum_BlockType.Simple_Packet_Block:
@@ -210,8 +221,8 @@ def read_frame(self) -> 'P_PCAPNG':
210221
break
211222

212223
elif block.info.type == Enum_BlockType.Packet_Block:
213-
if info.interface_id >= len(self._ctx.interfaces):
214-
raise FormatError(f'PCAP-NG: [Packet] invalid interface ID: {info.interface_id}')
224+
if block.info.interface_id >= len(self._ctx.interfaces):
225+
raise FormatError(f'PCAP-NG: [Packet] invalid interface ID: {block.info.interface_id}')
215226

216227
warn('PCAP-NG: [Packet] deprecated block type', DeprecatedFormatWarning,
217228
stacklevel=stacklevel())
@@ -277,9 +288,9 @@ def _write_file(self, block: 'Data_PCAPNG', *, name: 'str') -> 'None':
277288

278289
if ext._flag_f:
279290
ofile = ext._ofile(f'{ext._ofnm}/{name}.{ext._fext}')
280-
ofile(self._ctx.to_dict(), name=name)
291+
ofile(block.to_dict(), name=name)
281292
else:
282-
ext._ofile(self._ctx.to_dict(), name=name)
293+
ext._ofile(block.to_dict(), name=name)
283294
ofile = ext._ofile
284295
ext._offmt = ofile.kind
285296

pcapkit/foundation/extraction.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ def run(self) -> 'None': # pylint: disable=inconsistent-return-statements
334334
self._exeng = cast('Engine[P]', PCAPNG_Engine(self))
335335
else:
336336
raise FormatError(f'unknown file format: {self._magic!r}')
337+
338+
# start engine
337339
self._exeng.run()
338340

339341
# start iteration

0 commit comments

Comments
 (0)