00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef DNET_ARP_H
00013 #define DNET_ARP_H
00014
00015 #define ARP_HDR_LEN 8
00016 #define ARP_ETHIP_LEN 20
00017
00018 #ifndef __GNUC__
00019 # define __attribute__(x)
00020 # pragma pack(1)
00021 #endif
00022
00023
00024
00025
00026 struct arp_hdr {
00027 uint16_t ar_hrd;
00028 uint16_t ar_pro;
00029 uint8_t ar_hln;
00030 uint8_t ar_pln;
00031 uint16_t ar_op;
00032 };
00033
00034
00035
00036
00037 #define ARP_HRD_ETH 0x0001
00038 #define ARP_HRD_IEEE802 0x0006
00039
00040
00041
00042
00043 #define ARP_PRO_IP 0x0800
00044
00045
00046
00047
00048 #define ARP_OP_REQUEST 1
00049 #define ARP_OP_REPLY 2
00050 #define ARP_OP_REVREQUEST 3
00051 #define ARP_OP_REVREPLY 4
00052
00053
00054
00055
00056 struct arp_ethip {
00057 uint8_t ar_sha[ETH_ADDR_LEN];
00058 uint8_t ar_spa[IP_ADDR_LEN];
00059 uint8_t ar_tha[ETH_ADDR_LEN];
00060 uint8_t ar_tpa[IP_ADDR_LEN];
00061 };
00062
00063
00064
00065
00066 struct arp_entry {
00067 struct addr arp_pa;
00068 struct addr arp_ha;
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