iPXE
if_arp.h
Go to the documentation of this file.
1 #ifndef _IPXE_IF_ARP_H
2 #define _IPXE_IF_ARP_H
3 
4 /** @file
5  *
6  * Address Resolution Protocol constants and types
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 
14 /* ARP protocol HARDWARE identifiers. */
15 #define ARPHRD_NETROM 0 /**< from KA9Q: NET/ROM pseudo */
16 #define ARPHRD_ETHER 1 /**< Ethernet 10Mbps */
17 #define ARPHRD_EETHER 2 /**< Experimental Ethernet */
18 #define ARPHRD_AX25 3 /**< AX.25 Level 2 */
19 #define ARPHRD_PRONET 4 /**< PROnet token ring */
20 #define ARPHRD_CHAOS 5 /**< Chaosnet */
21 #define ARPHRD_IEEE802 6 /**< IEEE 802.2 Ethernet/TR/TB */
22 #define ARPHRD_ARCNET 7 /**< ARCnet */
23 #define ARPHRD_APPLETLK 8 /**< APPLEtalk */
24 #define ARPHRD_DLCI 15 /**< Frame Relay DLCI */
25 #define ARPHRD_ATM 19 /**< ATM */
26 #define ARPHRD_METRICOM 23 /**< Metricom STRIP (new IANA id) */
27 #define ARPHRD_IEEE1394 24 /**< IEEE 1394 IPv4 - RFC 2734 */
28 #define ARPHRD_EUI64 27 /**< EUI-64 */
29 #define ARPHRD_INFINIBAND 32 /**< InfiniBand */
30 
31 /* ARP protocol opcodes. */
32 #define ARPOP_REQUEST 1 /**< ARP request */
33 #define ARPOP_REPLY 2 /**< ARP reply */
34 #define ARPOP_RREQUEST 3 /**< RARP request */
35 #define ARPOP_RREPLY 4 /**< RARP reply */
36 #define ARPOP_InREQUEST 8 /**< InARP request */
37 #define ARPOP_InREPLY 9 /**< InARP reply */
38 #define ARPOP_NAK 10 /**< (ATM)ARP NAK */
39 
40 /**
41  * An ARP header
42  *
43  * This contains only the fixed-size portions of an ARP header; for
44  * other fields use the arp_{sender,target}_{ha,pa} family of
45  * functions.
46  */
47 struct arphdr {
48  /** Link-layer protocol
49  *
50  * This is an ARPHRD_XXX constant
51  */
53  /** Network-layer protocol
54  *
55  * This is, for Ethernet, an ETH_P_XXX constant.
56  */
58  /** Link-layer address length */
60  /** Network-layer address length */
62  /** ARP opcode */
64 } __attribute__ (( packed ));
65 
66 /** ARP packet sender hardware address
67  *
68  * @v arphdr ARP header
69  * @ret ar_sha Sender hardware address
70  */
71 static inline void * arp_sender_ha ( struct arphdr *arphdr ) {
72  return ( ( ( void * ) arphdr ) + sizeof ( *arphdr ) );
73 }
74 
75 /** ARP packet sender protocol address
76  *
77  * @v arphdr ARP header
78  * @ret ar_spa Sender protocol address
79  */
80 static inline void * arp_sender_pa ( struct arphdr *arphdr ) {
81  return ( arp_sender_ha ( arphdr ) + arphdr->ar_hln );
82 }
83 
84 /** ARP packet target hardware address
85  *
86  * @v arphdr ARP header
87  * @ret ar_tha Target hardware address
88  */
89 static inline void * arp_target_ha ( struct arphdr *arphdr ) {
90  return ( arp_sender_pa ( arphdr ) + arphdr->ar_pln );
91 }
92 
93 /** ARP packet target protocol address
94  *
95  * @v arphdr ARP header
96  * @ret ar_tpa Target protocol address
97  */
98 static inline void * arp_target_pa ( struct arphdr *arphdr ) {
99  return ( arp_target_ha ( arphdr ) + arphdr->ar_hln );
100 }
101 
102 /** ARP packet length
103  *
104  * @v arphdr ARP header
105  * @ret len Length (including header)
106  */
107 static inline size_t arp_len ( struct arphdr *arphdr ) {
108  return ( sizeof ( *arphdr ) +
109  ( 2 * ( arphdr->ar_hln + arphdr->ar_pln ) ) );
110 }
111 
112 #endif /* _IPXE_IF_ARP_H */
static void * arp_sender_pa(struct arphdr *arphdr)
ARP packet sender protocol address.
Definition: if_arp.h:80
unsigned short uint16_t
Definition: stdint.h:11
static void * arp_target_ha(struct arphdr *arphdr)
ARP packet target hardware address.
Definition: if_arp.h:89
static void * arp_target_pa(struct arphdr *arphdr)
ARP packet target protocol address.
Definition: if_arp.h:98
uint8_t ar_hln
Link-layer address length.
Definition: if_arp.h:59
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint16_t ar_hrd
Link-layer protocol.
Definition: if_arp.h:52
An ARP header.
Definition: if_arp.h:47
uint16_t ar_op
ARP opcode.
Definition: if_arp.h:63
unsigned char uint8_t
Definition: stdint.h:10
static void * arp_sender_ha(struct arphdr *arphdr)
ARP packet sender hardware address.
Definition: if_arp.h:71
struct arphdr __attribute__((packed))
uint16_t ar_pro
Network-layer protocol.
Definition: if_arp.h:57
uint8_t ar_pln
Network-layer address length.
Definition: if_arp.h:61
static size_t arp_len(struct arphdr *arphdr)
ARP packet length.
Definition: if_arp.h:107