ARP - Address Resolution Protocol

Removed in version 1.6.0: pcapkit.protocols.link.arp.PAT_MAC_ADDR, with no alias: _read_mac_addr() and _make_mac_addr() read and make the address (#2614).

pcapkit.protocols.link.arp.protocol contains ARP only, which implements an extractor for Address Resolution Protocol (ARP) [*], whose structure is:

Octets

Bits

Name

Description

0

0

arp.htype

Hardware Type

2

16

arp.ptype

Protocol Type

4

32

arp.hlen

Hardware Address Length

5

40

arp.plen

Protocol Address Length

6

48

arp.oper

Operation

8

64

arp.sha

Sender Hardware Address

14

112

arp.spa

Sender Protocol Address

18

144

arp.tha

Target Hardware Address

24

192

arp.tpa

Target Protocol Address

Removed in version 1.6.0: pcapkit.protocols.link.arp.InARP, with no alias. The class moved to pcapkit.protocols.link.inarp.protocol, since a module holds one protocol class, named after it (#2529).

class pcapkit.protocols.link.arp.protocol.ARP(file=None, length=None, **kwargs)[source]

Bases: Link[ARP, ARP]

This class implements all protocols in ARP family.

Changed in version 1.5.0: make() refuses a bool protocol address (#540), packs a non-IP protocol address from its hex text rather than as ASCII, and checks every address against hlen and plen (#1139). An Ethernet hlen other than 6 rebuilds (#1205), and read() takes an IPv4 or IPv6 protocol address only when both ptype and the address length agree (#1206).

Changed in version 1.6.0: htype, ptype and oper of make() each take a member or an int code, resolved with the enumeration’s get; a name, a bool, or a code the field cannot carry raises ProtocolError, rather than resolving against an enumeration inferred from the caller’s frame or writing a different value (#2594).

Removed in version 1.6.0: The _default, _namespace and _reversed arguments that went with each of htype, ptype and oper of make(), such as htype_default; resolve a name with resolve_index() first (#2594).

property name: Literal['Dynamic Reverse Address Resolution Protocol', 'Inverse Address Resolution Protocol', 'Reverse Address Resolution Protocol', 'Address Resolution Protocol']

Name of current protocol.

property alias: Literal['ARP', 'InARP', 'RARP', 'DRARP']

Acronym of corresponding protocol.

property length: int

Header length of current protocol.

property src: Address[source]

Sender hardware & protocol address.

property dst: Address[source]

Target hardware & protocol address.

property type: Type[source]

Hardware & protocol type.

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['ARP']]

read(length=None, **kwargs)[source]

Read Address Resolution Protocol.

Data structure of ARP Request header [RFC 826]:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Hdr Type             |         Proto Type            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Hdr Len    |   Proto Len   |          Operation            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\                       Sender Hdr Addr                         \
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\                      Sender Proto Addr                        \
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\                       Target Hdr Addr                         \
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
\                      Target Proto Addr                        \
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

ARP

Returns:

Parsed packet data.

make(*, htype=Hardware.Ethernet, ptype=EtherType.Internet_Protocol_version_4, hlen=None, plen=None, oper=Operation.REQUEST, sha='00:00:00:00:00:00', spa='0.0.0.0', tha='00:00:00:00:00:00', tpa='0.0.0.0', payload=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
Return type:

ARP

Returns:

Constructed packet data.

Raises:
classmethod __index__()[source]

Numeral registry index of the protocol.

Return type:

EtherType

Returns:

Numeral registry index of the protocol in IANA.

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (ARP) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

_read_addr_resolve(addr, htype)[source]

Resolve hardware address according to protocol.

Parameters:
  • addr (bytes) – Hardware address.

  • htype (int) – Hardware type.

Return type:

str

Returns:

Hardware address. If htype is 1, i.e. MAC address, returns : separated hex encoded MAC address.

_make_addr_resolve(addr, htype)[source]

Resolve hardware address according to protocol.

Parameters:
Return type:

bytes

Returns:

Hardware address packed as raw octets. If htype is 1, i.e. MAC address, the :- or --separated hex encoded MAC address is packed by _make_mac_addr(), one octet per group, of any number since hlen is not fixed at 6 (an empty string packs as no octets); otherwise, a str is taken as the hex encoded address that _read_addr_resolve() returns, and bytes/bytearray are returned as bytes.

Raises:

ProtocolError – If addr is not a str, bytes or bytearray (a bool included), or if htype is 1 and addr is not a well-formed MAC address, or if htype is not 1 and addr is a str that is not hex encoded.

Notes

The messages are prefixed with self.__class__.__name__ rather than self.alias, for the reason _make_proto_resolve() gives.

_read_proto_resolve(addr, ptype)[source]

Resolve protocol address according to protocol.

Parameters:
  • addr (bytes) – Protocol address.

  • ptype (int) – Protocol type.

Return type:

str | IPv4Address | IPv6Address

Returns:

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

_make_proto_resolve(addr, ptype, plen=None)[source]

Resolve protocol address according to protocol.

Parameters:
Return type:

bytes

Returns:

Packed protocol address. If ptype is 0x0800 (IPv4) or 0x86dd (IPv6), and plen is either not given or 4 or 16 respectively, the address is validated and packed to 4 or 16 octets; otherwise, a str is taken as the hex encoded address that _read_proto_resolve() returns, an IPv4Address/IPv6Address is packed, and bytes/bytearray are returned as bytes.

Raises:

Notes

Through parse_ip_address() rather than IPv4Address/IPv6Address directly, because bool is an int subclass that either constructor accepts without complaint: addr=True would pack as 00000001 (IPv4) or ::1 (IPv6) with no exception and no warning.

The messages are prefixed with self.__class__.__name__ rather than self.alias, even though the latter is this project’s usual choice: alias here reads self._acnm, which read() only assigns once the operation code is known, and this method runs from make() – before read() has ever executed on a construction-only instance. Using alias would turn every call into an AttributeError, bool or not.

Header Schemas

Removed in version 1.6.0: pcapkit.protocols.schema.link.arp, with no alias: the module moved here (#2534).

class pcapkit.protocols.link.arp.schema.ARP(htype=NO_VALUE, ptype=NO_VALUE, hlen=NO_VALUE, plen=NO_VALUE, oper=NO_VALUE, sha=NO_VALUE, spa=NO_VALUE, tha=NO_VALUE, tpa=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for ARP packet.

htype: Hardware = <EnumField htype>

Hardware type.

ptype: EtherType = <EnumField ptype>

Protocol type.

hlen: int = <UInt8Field hlen>

Hardware address length.

plen: int = <UInt8Field plen>

Protocol address length.

oper: Operation = <EnumField oper>

Operation code.

sha: bytes = <BytesField sha>

Sender hardware address.

spa: bytes = <BytesField spa>

Sender protocol address.

tha: bytes = <BytesField tha>

Target hardware address.

tpa: bytes = <BytesField tpa>

Target protocol address.

payload: bytes = <PayloadField payload>

Payload.

Data Models

Removed in version 1.6.0: pcapkit.protocols.data.link.arp, with no alias: the module moved here (#2534).

class pcapkit.protocols.link.arp.data.ARP(htype, ptype, hlen, plen, oper, sha, spa, tha, tpa, len)[source]

Bases: Protocol

Data model for ARP packet.

htype: Hardware

Hardware type.

ptype: EtherType

Protocol type.

hlen: int

Hardware address length.

plen: int

Protocol address length.

oper: Operation

Operation code.

sha: str

Sender hardware address.

spa: str | IPv4Address | IPv6Address

Sender protocol address.

tha: str

Target hardware address.

tpa: str | IPv4Address | IPv6Address

Target protocol address.

len: int

Header length.

class pcapkit.protocols.link.arp.data.Address(hardware, protocol)[source]

Bases: Data

Data model for ARP addresses.

hardware: str

Hardware address.

protocol: str | IPv4Address | IPv6Address

Protocol address.

class pcapkit.protocols.link.arp.data.Type(hardware, protocol)[source]

Bases: Data

Data model for ARP type.

hardware: Hardware

Hardware type.

protocol: EtherType | str

Protocol type.

Footnotes