many fixes in icmp and rtl8139 driver code
[quarnos.git] / resources / net / arp.h
blob1d05804cd8c48515930c9f36fa67cf965094b1d7
1 #ifndef _ARP_H_
2 #define _ARP_H_
4 #include "arch/low/general.h"
5 #include "libs/buffer.h"
6 #include "mac_addr.h"
7 #include "arp_table.h"
8 #include "internet_layer.h"
9 #include "link_layer.h"
11 namespace net {
12 class arp : public osi_layer {
13 private:
14 p<link_layer> down;
16 /* EtherType */
17 enum {
18 et_arp = 0x806
21 enum {
22 ethernet = 1
24 enum protocol {
25 ipv4 = 0x0800
27 enum {
28 request = 1,
29 reply = 2
32 mac_addr my_haddr;
33 ipv4_addr my_paddr;
35 struct arp_packet {
36 u16 htype;
37 u16 ptype;
38 u8 hlen;
39 u8 plen;
40 u16 oper;
41 u32 sha0;
42 u16 sha1;
43 u32 spa;
44 u16 tha0;
45 u32 tha1;
46 u32 tpa;
47 } __attribute__((packed));
50 volatile bool received;
52 arp_table table;
54 void receive_data(const buffer &x);
55 public:
56 void set_link_layer(p<link_layer> x) {
57 down = x;
58 my_haddr = x->get_haddr();
59 my_paddr = ipv4_addr::from_le(192 << 24 | 168 << 16 | 1 << 8 | 50);
61 x->add_handler(et_arp, delegate<void, const buffer&>::method(this, &arp::receive_data));
64 void set_ipv4(const ipv4_addr&);
66 mac_addr get_haddr(const ipv4_addr &ipaddr);
67 void receive_packet(p<arp_packet> pkg);
69 //static void register_type();
73 #endif