rtl8139, arp packet reception, ipv4 + arp integration
[quarnos.git] / resources / arp.h
blob38d534a8f38a72d1168c4136afffb7e0e84f719c
1 #ifndef _ARP_H_
2 #define _ARP_H_
4 #include "socket.h"
5 #include "arch/low/general.h"
7 #include "mac_addr.h"
8 #include "arp_table.h"
9 #include "link_layer.h"
11 typedef u32 ipv4_addr;
13 namespace resources {
14 class arp/* : public socket*/ {
15 private:
16 link_layer *network;
18 /* EtherType */
19 enum {
20 et_arp = 0x806
23 enum {
24 ethernet = 1
26 enum protocol {
27 ipv4 = 0x0800
29 enum {
30 request = 1,
31 reply = 2
34 mac_addr my_haddr;
35 u32 my_paddr;
37 struct arp_packet {
38 u16 htype;
39 u16 ptype;
40 u8 hlen;
41 u8 plen;
42 u16 oper;
43 u32 sha0;
44 u16 sha1;
45 u32 spa;
46 u16 tha0;
47 u32 tha1;
48 u32 tpa;
49 } __attribute__((packed));
52 volatile bool received;
54 arp_table table;
56 void receive_data(void *, int);
57 public:
58 void set_link_layer(p<link_layer> x) {
59 network = x;
60 my_haddr = x->get_haddr();
61 my_paddr = 192 << 24 | 168 << 16 | 1 << 8 | 50;
63 delegate<void, void*, int> rec;
64 rec.method(this, &arp::receive_data);
65 x->add_handler(et_arp, rec);
68 void set_ipv4(ipv4_addr);
70 mac_addr get_haddr(ipv4_addr ipaddr);
71 void receive_packet(arp_packet *pkg);
73 //static void register_type();
77 #endif