-
Notifications
You must be signed in to change notification settings - Fork 1
/
arp.h
76 lines (60 loc) · 2.04 KB
/
arp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// -----------------------------------------------------------
// Developed By Marcos Luiggi Sartori
// Leonardo Pavanatto Soares
// Pontifical Catholic University of Rio Grande do Sul (PUCRS)
// Computer Networks Laboratory - April 11, 2016
// -----------------------------------------------------------
// File: arp.h
// Description: arp protocol data structure.
// -----------------------------------------------------------
#ifndef ARP_H
#define ARP_H
#include <stdint.h>
#include <netinet/ether.h>
#include <linux/if_packet.h>
#include "mac.h"
#include "ipv4.h"
#define ARP_REQUEST 1
#define ARP_REPLY 2
// ARP for ipv4 on ethernet payload structure
typedef struct arp4_payload_t {
macaddr_t src_macaddr;
ipaddr_t src_ipaddr;
macaddr_t dest_macaddr;
ipaddr_t dest_ipaddr;
} arp4_payload_t;
typedef union arp_payload_t {
arp4_payload_t v4;
uint8_t raw[0];
} arp_payload_t;
// ARP frame structure
typedef struct arp_t {
uint16_t htype;
uint16_t ptype;
uint8_t hlen;
uint8_t plen;
uint16_t operation;
arp_payload_t payload;
} arp_t;
// Functions for manipulating ARP's variable size raw payload
static inline uint8_t* arp_source_haddr(arp_t *pkg) {
return pkg->payload.raw;
}
static inline uint8_t* arp_source_paddr(arp_t *pkg) {
return pkg->payload.raw + pkg->hlen;
}
static inline uint8_t* arp_target_haddr(arp_t *pkg) {
return pkg->payload.raw + pkg->hlen + pkg->plen;
}
static inline uint8_t* arp_target_paddr(arp_t *pkg) {
return pkg->payload.raw + ((size_t)pkg->hlen << 1) + pkg->plen;
}
void print_bytearray(uint8_t *array, unsigned length, unsigned base, char separator);
void arp_print(arp_t *arp);
int send_arp4_request(raw_iface_t *iface, macaddr_t src_macaddr, ipaddr_t src_ipaddr,
macaddr_t target_macaddr, ipaddr_t target_ip);
int send_arp4_reply(raw_iface_t *iface, macaddr_t src_macaddr, ipaddr_t src_ipaddr,
macaddr_t target_macaddr, ipaddr_t target_ip);
int arp4_lookup(raw_iface_t *iface, ipaddr_t src_ipaddr, macaddr_t src_mac,
ipaddr_t target_ipaddr, macaddr_t target_mac);
#endif /* !ARP_H */