iPXE
if_arp.h
Go to the documentation of this file.
00001 #ifndef _IPXE_IF_ARP_H
00002 #define _IPXE_IF_ARP_H
00003 
00004 /** @file
00005  *
00006  * Address Resolution Protocol constants and types
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 
00014 /* ARP protocol HARDWARE identifiers. */
00015 #define ARPHRD_NETROM   0               /**< from KA9Q: NET/ROM pseudo  */
00016 #define ARPHRD_ETHER    1               /**< Ethernet 10Mbps            */
00017 #define ARPHRD_EETHER   2               /**< Experimental Ethernet      */
00018 #define ARPHRD_AX25     3               /**< AX.25 Level 2              */
00019 #define ARPHRD_PRONET   4               /**< PROnet token ring          */
00020 #define ARPHRD_CHAOS    5               /**< Chaosnet                   */
00021 #define ARPHRD_IEEE802  6               /**< IEEE 802.2 Ethernet/TR/TB  */
00022 #define ARPHRD_ARCNET   7               /**< ARCnet                     */
00023 #define ARPHRD_APPLETLK 8               /**< APPLEtalk                  */
00024 #define ARPHRD_DLCI     15              /**< Frame Relay DLCI           */
00025 #define ARPHRD_ATM      19              /**< ATM                        */
00026 #define ARPHRD_METRICOM 23              /**< Metricom STRIP (new IANA id) */
00027 #define ARPHRD_IEEE1394 24              /**< IEEE 1394 IPv4 - RFC 2734  */
00028 #define ARPHRD_EUI64    27              /**< EUI-64                     */
00029 #define ARPHRD_INFINIBAND 32            /**< InfiniBand                 */
00030 
00031 /* ARP protocol opcodes. */
00032 #define ARPOP_REQUEST   1               /**< ARP request                */
00033 #define ARPOP_REPLY     2               /**< ARP reply                  */
00034 #define ARPOP_RREQUEST  3               /**< RARP request               */
00035 #define ARPOP_RREPLY    4               /**< RARP reply                 */
00036 #define ARPOP_InREQUEST 8               /**< InARP request              */
00037 #define ARPOP_InREPLY   9               /**< InARP reply                */
00038 #define ARPOP_NAK       10              /**< (ATM)ARP NAK               */
00039 
00040 /**
00041  * An ARP header
00042  *
00043  * This contains only the fixed-size portions of an ARP header; for
00044  * other fields use the arp_{sender,target}_{ha,pa} family of
00045  * functions.
00046  */
00047 struct arphdr {
00048         /** Link-layer protocol
00049          *
00050          * This is an ARPHRD_XXX constant
00051          */
00052         uint16_t ar_hrd;
00053         /** Network-layer protocol
00054          *
00055          * This is, for Ethernet, an ETH_P_XXX constant.
00056          */
00057         uint16_t ar_pro;
00058         /** Link-layer address length */
00059         uint8_t ar_hln;
00060         /** Network-layer address length */
00061         uint8_t ar_pln;
00062         /** ARP opcode */
00063         uint16_t ar_op;
00064 } __attribute__ (( packed ));
00065 
00066 /** ARP packet sender hardware address
00067  *
00068  * @v arphdr    ARP header
00069  * @ret ar_sha  Sender hardware address
00070  */
00071 static inline void * arp_sender_ha ( struct arphdr *arphdr ) {
00072         return ( ( ( void * ) arphdr ) + sizeof ( *arphdr ) );
00073 }
00074 
00075 /** ARP packet sender protocol address
00076  *
00077  * @v arphdr    ARP header
00078  * @ret ar_spa  Sender protocol address
00079  */
00080 static inline void * arp_sender_pa ( struct arphdr *arphdr ) {
00081         return ( arp_sender_ha ( arphdr ) + arphdr->ar_hln );
00082 }
00083 
00084 /** ARP packet target hardware address
00085  *
00086  * @v arphdr    ARP header
00087  * @ret ar_tha  Target hardware address
00088  */
00089 static inline void * arp_target_ha ( struct arphdr *arphdr ) {
00090         return ( arp_sender_pa ( arphdr ) + arphdr->ar_pln );
00091 }
00092 
00093 /** ARP packet target protocol address
00094  *
00095  * @v arphdr    ARP header
00096  * @ret ar_tpa  Target protocol address
00097  */
00098 static inline void * arp_target_pa ( struct arphdr *arphdr ) {
00099         return ( arp_target_ha ( arphdr ) + arphdr->ar_hln );
00100 }
00101 
00102 /** ARP packet length
00103  *
00104  * @v arphdr    ARP header
00105  * @ret len     Length (including header)
00106  */
00107 static inline size_t arp_len ( struct arphdr *arphdr ) {
00108         return ( sizeof ( *arphdr ) +
00109                  ( 2 * ( arphdr->ar_hln + arphdr->ar_pln ) ) );
00110 }
00111 
00112 #endif  /* _IPXE_IF_ARP_H */