-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIPHandler.h
86 lines (56 loc) · 1.92 KB
/
IPHandler.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef IP_H
#define IP_H
#include <stdint.h>
#include "EtherControl.h"
#include "ARPHandler.h"
#include "TimerHandler.h"
#include "Buffer.h"
#define IP_PROTOCOL 0x0800
#define IP_HEADER_LENGTH 20
class PacketHandler {
public:
virtual void handlePacket(uint8_t *sourceIP, Buffer *packet) = 0;
};
typedef struct ipProtocolMap {
uint8_t ipProtocol;
PacketHandler *handler;
} ipProtocolMap;
class IPHandler: PayloadHandler{
EtherControl *etherControl;
uint8_t ipAddress[4];
uint8_t gatewayIP[4];
uint8_t subnetMask[4];
uint8_t ipNetwork[5];
uint8_t ipBroadcastAddress[4];
ARPHandler *arp;
uint16_t nextPort;
//large enough to handle ICMP, UDP, TCP
ipProtocolMap protocolRegistry[3];
void initProtocolRegistry();
PacketHandler* getProtocolHandler(uint8_t ipProtocol);
void init(uint8_t *ipAddress, uint8_t *gatewayIP, uint8_t *subnetMask,
ARPHandler *arp, EtherControl *control);
OffsetBuffer *sendPacketBuffer;
public:
IPHandler(uint8_t *ipAddress, uint8_t *gatewayIP, uint8_t *subnetMask,
ARPHandler *arp, EtherControl *control);
IPHandler(uint8_t *ipAddress, uint8_t *gatewayIP, uint8_t *subnetMask,
uint8_t routingTableSize, EtherControl *control);
~IPHandler();
uint16_t getPort();
bool registerProtocol(uint8_t ipProtocol, PacketHandler *handler);
Buffer* getSendPayloadBuffer();
bool sendPacket(uint8_t *destinationIP, uint8_t protocol,
uint16_t packetPayloadLength);
bool sendPacket(uint8_t *destinationIP,uint8_t protocol,
uint16_t packetPayloadLength,uint8_t *payload);
void handlePayload(Buffer *p);
ARPHandler* getARPHandler();
const uint8_t* getMACForIP(uint8_t *destinationIP);
uint8_t registerTimer(TimerHandler *handler, uint16_t millisDelay);
void unregisterTimer(uint8_t index);
static bool ipsEquate(uint8_t ip_addr[4], uint8_t ip_addr_compare[4]);
uint8_t *getIPAddress();
uint16_t getMaxReceivePayload();
};
#endif