1# $Id: arp.py 23 2006-11-08 15:45:33Z dugsong $
2# -*- coding: utf-8 -*-
3"""Address Resolution Protocol."""
4from __future__ import absolute_import
5
6from . import dpkt
7
8# Hardware address format
9ARP_HRD_ETH = 0x0001  # ethernet hardware
10ARP_HRD_IEEE802 = 0x0006  # IEEE 802 hardware
11
12# Protocol address format
13ARP_PRO_IP = 0x0800  # IP protocol
14
15# ARP operation
16ARP_OP_REQUEST = 1  # request to resolve ha given pa
17ARP_OP_REPLY = 2  # response giving hardware address
18ARP_OP_REVREQUEST = 3  # request to resolve pa given ha
19ARP_OP_REVREPLY = 4  # response giving protocol address
20
21
22class ARP(dpkt.Packet):
23    """Address Resolution Protocol.
24
25    See more about the ARP on \
26    https://en.wikipedia.org/wiki/Address_Resolution_Protocol
27
28    Attributes:
29        __hdr__: Header fields of ARP.
30    """
31
32    __hdr__ = (
33        ('hrd', 'H', ARP_HRD_ETH),
34        ('pro', 'H', ARP_PRO_IP),
35        ('hln', 'B', 6),  # hardware address length
36        ('pln', 'B', 4),  # protocol address length
37        ('op', 'H', ARP_OP_REQUEST),
38        ('sha', '6s', b''),
39        ('spa', '4s', b''),
40        ('tha', '6s', b''),
41        ('tpa', '4s', b'')
42    )
43