-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patharp.c
44 lines (36 loc) · 1.17 KB
/
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
36
37
38
39
40
41
42
43
44
/**
*author: Anmol Vatsa<[email protected]>
*
*kernel code to send recv arp request responses
*/
#include "types.h"
#include "defs.h"
#include "arp_frame.h"
#include "nic.h"
static int block_until_arp_reply(struct ethr_hdr *arpReply) {
/**
*TODO: repeated sleep. wake up on each network interrupt.
* check for ARP reply for this request.
* If received, unblock. else, sleep again.
*/
return 0;
}
int send_arpRequest(char* interface, char* ipAddr, char* arpResp) {
cprintf("Create arp request for ip:%s over Interface:%s\n", ipAddr, interface);
struct nic_device *nd;
if(get_device(interface, &nd) < 0) {
cprintf("ERROR:send_arpRequest:Device not loaded\n");
return -1;
}
struct ethr_hdr eth;
create_eth_arp_frame(nd->mac_addr, ipAddr, ð);
nd->send_packet(nd->driver, (uint8_t*)ð, sizeof(eth)-2); //sizeof(eth)-2 to remove padding. padding was necessary for alignment.
struct ethr_hdr arpResponse;
if(block_until_arp_reply(&arpResponse) < 0) {
cprintf("ERROR:send_arpRequest:Failed to recv ARP response over the NIC\n");
return -3;
}
unpack_mac(arpResponse.arp_dmac, arpResp);
arpResp[17] = '\0';
return 0;
}