Skip to content

Commit

Permalink
revised pcapng schema (set section length to -1 if needed)
Browse files Browse the repository at this point in the history
  • Loading branch information
JarryShaw committed May 4, 2023
1 parent a5654f8 commit 0396511
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pcapkit/protocols/schema/misc/pcapng.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import io
import struct
import sys
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, cast

from pcapkit.const.pcapng.block_type import BlockType as Enum_BlockType
from pcapkit.const.pcapng.filter_type import FilterType as Enum_FilterType
Expand Down Expand Up @@ -60,7 +60,7 @@

if TYPE_CHECKING:
from ipaddress import IPv4Address, IPv4Interface, IPv6Address, IPv6Interface
from typing import Any, Callable, Optional, Type
from typing import Any, Callable, Optional

from typing_extensions import Literal, Self

Expand Down Expand Up @@ -445,7 +445,7 @@ class SectionHeaderBlock(BlockType):
#: Minor version number.
minor: 'int' = UInt16Field(callback=shb_byteorder_callback, default=0)
#: Section length.
section_length: 'int' = Int64Field(callback=shb_byteorder_callback, default=0xFFFFFFFFFFFFFFFF)
section_length: 'int' = Int64Field(callback=shb_byteorder_callback, default=0xFFFF_FFFF_FFFF_FFFF)
#: Options.
options: 'list[Option]' = OptionField(
length=lambda pkt: pkt['length'] - 28,
Expand Down Expand Up @@ -497,7 +497,10 @@ def post_process(self, packet: 'dict[str, Any]') -> 'SectionHeaderBlock':
Revised schema.
"""
self = super().post_process(packet)
self = cast('Self', super().post_process(packet))

if self.section_length == 0xFFFF_FFFF_FFFF_FFFF:
self.section_length = -1

magic = packet['match']['byteorder'] # type: int
if magic == 0x1A2B3C4D:
Expand Down Expand Up @@ -1143,7 +1146,7 @@ def post_process(self, packet: 'dict[str, Any]') -> 'Self':
Revised schema.
"""
self = super().post_process(packet)
self = cast('Self', super().post_process(packet))

mapping = MultiDict() # type: MultiDict[IPv4Address | IPv6Address, str]
reverse_mapping = MultiDict() # type: MultiDict[str, IPv4Address | IPv6Address]
Expand Down Expand Up @@ -1316,7 +1319,7 @@ def post_process(self, packet: 'dict[str, Any]') -> 'Self':
Revised schema.
"""
self = super().post_process(packet)
self = cast('Self', super().post_process(packet))

data = [] # type: list[OrderedMultiDict[str, str | bytes]]
for entry_buffer in self.entry.split(b'\n\n'):
Expand Down

0 comments on commit 0396511

Please sign in to comment.