Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

arp.h

Go to the documentation of this file.
00001 /*
00002  * arp.h
00003  * 
00004  * Address Resolution Protocol.
00005  * RFC 826
00006  *
00007  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
00008  *
00009  * $Id: arp.h,v 1.12 2003/03/16 17:39:17 dugsong Exp $
00010  */
00011 
00012 #ifndef DNET_ARP_H
00013 #define DNET_ARP_H
00014 
00015 #define ARP_HDR_LEN     8       /* base ARP header length */
00016 #define ARP_ETHIP_LEN   20      /* base ARP message length */
00017 
00018 #ifndef __GNUC__
00019 # define __attribute__(x)
00020 # pragma pack(1)
00021 #endif
00022 
00023 /*
00024  * ARP header
00025  */
00026 struct arp_hdr {
00027         uint16_t        ar_hrd; /* format of hardware address */
00028         uint16_t        ar_pro; /* format of protocol address */
00029         uint8_t         ar_hln; /* length of hardware address (ETH_ADDR_LEN) */
00030         uint8_t         ar_pln; /* length of protocol address (IP_ADDR_LEN) */
00031         uint16_t        ar_op;  /* operation */
00032 };
00033 
00034 /*
00035  * Hardware address format
00036  */
00037 #define ARP_HRD_ETH     0x0001  /* ethernet hardware */
00038 #define ARP_HRD_IEEE802 0x0006  /* IEEE 802 hardware */
00039 
00040 /*
00041  * Protocol address format
00042  */
00043 #define ARP_PRO_IP      0x0800  /* IP protocol */
00044 
00045 /*
00046  * ARP operation
00047  */
00048 #define ARP_OP_REQUEST          1       /* request to resolve ha given pa */
00049 #define ARP_OP_REPLY            2       /* response giving hardware address */
00050 #define ARP_OP_REVREQUEST       3       /* request to resolve pa given ha */
00051 #define ARP_OP_REVREPLY         4       /* response giving protocol address */
00052 
00053 /*
00054  * Ethernet/IP ARP message
00055  */
00056 struct arp_ethip {
00057         uint8_t         ar_sha[ETH_ADDR_LEN];   /* sender hardware address */
00058         uint8_t         ar_spa[IP_ADDR_LEN];    /* sender protocol address */
00059         uint8_t         ar_tha[ETH_ADDR_LEN];   /* target hardware address */
00060         uint8_t         ar_tpa[IP_ADDR_LEN];    /* target protocol address */
00061 };
00062 
00063 /*
00064  * ARP cache entry
00065  */
00066 struct arp_entry {
00067         struct addr     arp_pa;                 /* protocol address */
00068         struct addr     arp_ha;                 /* hardware address */
00069 };
00070 
00071 #ifndef __GNUC__
00072 # pragma pack()
00073 #endif
00074 
00075 #define arp_pack_hdr_ethip(hdr, op, sha, spa, tha, tpa) do {    \
00076         struct arp_hdr *pack_arp_p = (struct arp_hdr *)(hdr);   \
00077         struct arp_ethip *pack_ethip_p = (struct arp_ethip *)   \
00078                 ((uint8_t *)(hdr) + ARP_HDR_LEN);               \
00079         pack_arp_p->ar_hrd = htons(ARP_HRD_ETH);                \
00080         pack_arp_p->ar_pro = htons(ARP_PRO_IP);                 \
00081         pack_arp_p->ar_hln = ETH_ADDR_LEN;                      \
00082         pack_arp_p->ar_pln = IP_ADDR_LEN;                       \
00083         pack_arp_p->ar_op = htons(op);                          \
00084         memmove(pack_ethip_p->ar_sha, &(sha), ETH_ADDR_LEN);    \
00085         memmove(pack_ethip_p->ar_spa, &(spa), IP_ADDR_LEN);     \
00086         memmove(pack_ethip_p->ar_tha, &(tha), ETH_ADDR_LEN);    \
00087         memmove(pack_ethip_p->ar_tpa, &(tpa), IP_ADDR_LEN);     \
00088 } while (0)
00089 
00090 typedef struct arp_handle arp_t;
00091 
00092 typedef int (*arp_handler)(const struct arp_entry *entry, void *arg);
00093 
00094 __BEGIN_DECLS
00095 arp_t   *arp_open(void);
00096 int      arp_add(arp_t *arp, const struct arp_entry *entry);
00097 int      arp_delete(arp_t *arp, const struct arp_entry *entry);
00098 int      arp_get(arp_t *arp, struct arp_entry *entry);
00099 int      arp_loop(arp_t *arp, arp_handler callback, void *arg);
00100 arp_t   *arp_close(arp_t *arp);
00101 __END_DECLS
00102 
00103 #endif /* DNET_ARP_H */

Generated on Sun May 14 14:51:10 2006 by  doxygen 1.4.2