-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharp.c
35 lines (29 loc) · 755 Bytes
/
arp.c
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
#include <stdint.h>
#include <string.h>
#include "arp.h"
uint16_t process_arp(const uint8_t *payload_in, uint16_t payload_in_length,
uint8_t *payload_out,
const mac_addr_t *mac, const ipv4_addr_t *ipv4)
{
const ether_arp_pkt_t *src;
ether_arp_pkt_t *dst;
src = (ether_arp_pkt_t *)payload_in;
dst = (ether_arp_pkt_t *)payload_out;
if((src->htype == ah_ether) &&
(ntohs(src->ptype) == et_ipv4) &&
(src->oper == ao_request) &&
ipv4_address_match(&src->tpa, ipv4))
{
dst->htype = src->htype;
dst->ptype = src->ptype;
dst->hlen = src->hlen;
dst->plen = src->plen;
dst->oper = ao_reply;
dst->sha = *mac;
dst->spa = *ipv4;
dst->tha = src->sha;
dst->tpa = src->spa;
return(sizeof(ether_arp_pkt_t));
}
return(0);
}