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 |
|
Hardware Type |
2 |
16 |
|
Protocol Type |
4 |
32 |
|
Hardware Address Length |
5 |
40 |
|
Protocol Address Length |
6 |
48 |
|
Operation |
8 |
64 |
|
Sender Hardware Address |
14 |
112 |
|
Sender Protocol Address |
18 |
144 |
|
Target Hardware Address |
24 |
192 |
|
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]¶
-
This class implements all protocols in ARP family.
Changed in version 1.5.0:
make()refuses aboolprotocol address (#540), packs a non-IP protocol address from its hex text rather than as ASCII, and checks every address againsthlenandplen(#1139). An Ethernethlenother than 6 rebuilds (#1205), andread()takes an IPv4 or IPv6 protocol address only when bothptypeand the address length agree (#1206).Changed in version 1.6.0:
htype,ptypeandoperofmake()each take a member or anintcode, resolved with the enumeration’sget; a name, abool, or a code the field cannot carry raisesProtocolError, 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,_namespaceand_reversedarguments that went with each ofhtype,ptypeandoperofmake(), such ashtype_default; resolve a name withresolve_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.
- 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 \ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- 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:
hlen (
int|None) – Hardware address length; if not given,6whenhtypeis Ethernet, otherwise derived from the packedsha.plen (
int|None) – Protocol address length; derived from the packedspaif not given.spa (
IPv4Address|IPv6Address|str|bytes|bytearray) – Sender protocol address.tpa (
IPv4Address|IPv6Address|str|bytes|bytearray) – Target protocol address.payload (
bytes|ProtocolBase|Schema) – Payload.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
FieldValueError – If
spaortpais rejected by_make_proto_resolve(), e.g. abool.ProtocolError – If
htype,ptypeoroperis a name, abool, or a member or code its field cannot carry; ifshaorthais rejected by_make_addr_resolve(), orspaortpaby_make_proto_resolve(); if a packed hardware address is nothlenoctets long (withhlennot given andhtypeEthernet, not 6 octets long), or a packed protocol address is notplenoctets long.
- _make_addr_resolve(addr, htype)[source]¶
Resolve hardware address according to protocol.
- Parameters:
- Return type:
- Returns:
Hardware address packed as raw octets. If
htypeis1, i.e. MAC address, the:- or--separated hex encoded MAC address is packed by_make_mac_addr(), one octet per group, of any number sincehlenis not fixed at 6 (an empty string packs as no octets); otherwise, astris taken as the hex encoded address that_read_addr_resolve()returns, andbytes/bytearrayare returned asbytes.- Raises:
ProtocolError – If
addris not astr,bytesorbytearray(aboolincluded), or ifhtypeis1andaddris not a well-formed MAC address, or ifhtypeis not1andaddris astrthat is not hex encoded.
Notes
The messages are prefixed with
self.__class__.__name__rather thanself.alias, for the reason_make_proto_resolve()gives.
- _read_proto_resolve(addr, ptype)[source]¶
Resolve protocol address according to protocol.
- Parameters:
- Return type:
- Returns:
Protocol address. If
ptypeis0x0800(IPv4) andaddris 4 octets, anIPv4Address; if0x86dd(IPv6) and 16 octets, anIPv6Address; otherwise, the address as a hexstr.
- _make_proto_resolve(addr, ptype, plen=None)[source]¶
Resolve protocol address according to protocol.
- Parameters:
addr (
IPv4Address|IPv6Address|str|bytes) – Protocol address.ptype (
int) – Protocol type.
- Return type:
- Returns:
Packed protocol address. If
ptypeis0x0800(IPv4) or0x86dd(IPv6), andplenis either not given or 4 or 16 respectively, the address is validated and packed to 4 or 16 octets; otherwise, astris taken as the hex encoded address that_read_proto_resolve()returns, anIPv4Address/IPv6Addressis packed, andbytes/bytearrayare returned asbytes.- Raises:
FieldValueError – If
addris abool, whateverptypeis, or is packed as an IPv4 or IPv6 address and is not a valid address or not of that version (seeparse_ip_address()).ProtocolError – If the address is not packed as IPv4 or IPv6, and
addris either astrthat is not hex encoded or none ofstr, an IP address,bytesandbytearray.
Notes
Through
parse_ip_address()rather thanIPv4Address/IPv6Addressdirectly, becauseboolis anintsubclass that either constructor accepts without complaint:addr=Truewould pack as00000001(IPv4) or::1(IPv6) with no exception and no warning.The messages are prefixed with
self.__class__.__name__rather thanself.alias, even though the latter is this project’s usual choice:aliashere readsself._acnm, whichread()only assigns once the operation code is known, and this method runs frommake()– beforeread()has ever executed on a construction-only instance. Usingaliaswould turn every call into anAttributeError, bool or not.
Header Schemas¶
Removed in version 1.6.0: pcapkit.protocols.schema.link.arp, with no alias: the module moved here
(#2534).
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:
ProtocolData model for ARP packet.
- spa: str | IPv4Address | IPv6Address¶
Sender protocol address.
- tpa: str | IPv4Address | IPv6Address¶
Target protocol address.
- class pcapkit.protocols.link.arp.data.Address(hardware, protocol)[source]¶
Bases:
DataData model for ARP addresses.
- protocol: str | IPv4Address | IPv6Address¶
Protocol address.
- class pcapkit.protocols.link.arp.data.Type(hardware, protocol)[source]¶
Bases:
DataData model for ARP type.
Footnotes