Skip to content
Open
Show file tree
Hide file tree
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
40 changes: 20 additions & 20 deletions pcapkit/protocols/link/arp.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,26 +374,6 @@ def _read_addr_resolve(self, addr: 'bytes', htype: 'int') -> 'str':
_addr = addr.hex()
return _addr

def _read_proto_resolve(self, addr: 'bytes', ptype: 'int') -> 'str | IPv4Address | IPv6Address':
"""Resolve protocol address according to protocol.

Arguments:
addr: Protocol address.
ptype: Protocol type.

Returns:
Protocol address. If ``ptype`` is ``0x0800`` (IPv4) and ``addr`` is
4 octets, an :class:`~ipaddress.IPv4Address`; if ``0x86dd`` (IPv6)
and 16 octets, an :class:`~ipaddress.IPv6Address`; otherwise, the
address as a hex :class:`str`.

"""
if ptype == Enum_EtherType.Internet_Protocol_version_4 and len(addr) == 4: # IPv4
return ipaddress.IPv4Address(addr)
if ptype == Enum_EtherType.Internet_Protocol_version_6 and len(addr) == 16: # IPv6
return ipaddress.IPv6Address(addr)
return addr.hex()

def _make_addr_resolve(self, addr: 'str | bytes | bytearray', htype: 'int') -> 'bytes':
"""Resolve hardware address according to protocol.

Expand Down Expand Up @@ -441,6 +421,26 @@ def _make_addr_resolve(self, addr: 'str | bytes | bytearray', htype: 'int') -> '
f'{addr!r}') from None
return bytes(addr)

def _read_proto_resolve(self, addr: 'bytes', ptype: 'int') -> 'str | IPv4Address | IPv6Address':
"""Resolve protocol address according to protocol.

Arguments:
addr: Protocol address.
ptype: Protocol type.

Returns:
Protocol address. If ``ptype`` is ``0x0800`` (IPv4) and ``addr`` is
4 octets, an :class:`~ipaddress.IPv4Address`; if ``0x86dd`` (IPv6)
and 16 octets, an :class:`~ipaddress.IPv6Address`; otherwise, the
address as a hex :class:`str`.

"""
if ptype == Enum_EtherType.Internet_Protocol_version_4 and len(addr) == 4: # IPv4
return ipaddress.IPv4Address(addr)
if ptype == Enum_EtherType.Internet_Protocol_version_6 and len(addr) == 16: # IPv6
return ipaddress.IPv6Address(addr)
return addr.hex()

def _make_proto_resolve(self, addr: 'IPv4Address | IPv6Address | str | bytes', ptype: 'int',
plen: 'Optional[int]' = None) -> 'bytes':
"""Resolve protocol address according to protocol.
Expand Down
4 changes: 0 additions & 4 deletions pcapkit/protocols/link/l2tpv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ def make(self,
trailer=trailer,
)

##########################################################################
# Methods.
##########################################################################

@classmethod
def id(cls) -> 'tuple[Literal["L2TP"], Literal["L2TPv2"]]':
"""Index ID of the protocol.
Expand Down
Loading