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