many fixes in icmp and rtl8139 driver code
[quarnos.git] / resources / net / udp.h
blob9b1841709257613b588fc585393b1c9224f337ca
1 #ifndef _UDP_H_
2 #define _UDP_H_
4 #include "transport_layer.h"
5 #include "ipv4_addr.h"
7 namespace net {
8 class udp : public transport_layer {
9 private:
10 struct pseudo_header {
11 u32 source;
12 u32 destination;
13 u8 zero;
14 u8 protocol;
15 u16 length;
16 } __attribute__((packed));
18 struct udp_packet {
19 u16 sender_port;
20 u16 receiver_port;
21 u16 length;
22 u16 checksum;
23 } __attribute__((packed));
25 list<int> ports;
26 list<delegate<void, const ipv4_addr&, u16, const buffer &> > listeners;
28 void receive(const ipv4_addr &, const buffer&);
29 public:
30 void set_internet_layer(p<internet_layer> x) {
31 down = x;
32 down->listen(17, delegate<void, const ipv4_addr&, const buffer&>::method(this, &udp::receive));
35 void send(ipv4_addr, u16, u16, const buffer &);
36 void listen(u16, delegate<void, const ipv4_addr &, u16, const buffer &>);
40 #endif