-
Notifications
You must be signed in to change notification settings - Fork 1
/
Minet.h
154 lines (112 loc) · 3.73 KB
/
Minet.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef _Minet
#define _Minet
#include <iostream>
#include <string>
#include "config.h"
#include "buffer.h"
#include "debug.h"
#include "error.h"
#include "util.h"
#include "raw_ethernet_packet.h"
#include "raw_ethernet_packet_buffer.h"
#include "ethernet.h"
#include "arp.h"
#include "headertrailer.h"
#include "packet.h"
#include "ip.h"
#include "icmp.h"
#include "udp.h"
#include "tcp.h"
#include "sock.h"
#include "sockint.h"
#include "sock_mod_structs.h"
#include "constate.h"
typedef int MinetHandle;
int MinetHandleToInputOutputFDs(const MinetHandle &h, int *inputfd, int *outputfd);
const MinetHandle MINET_NOHANDLE=-1;
enum MinetModule {
MINET_MONITOR,
MINET_READER,
MINET_WRITER,
MINET_DEVICE_DRIVER,
MINET_ETHERNET_MUX,
MINET_IP_MODULE,
MINET_ARP_MODULE,
MINET_OTHER_MODULE,
MINET_IP_MUX,
MINET_IP_OTHER_MODULE,
MINET_ICMP_MODULE,
MINET_UDP_MODULE,
MINET_TCP_MODULE,
MINET_SOCK_MODULE,
MINET_SOCKLIB_MODULE,
MINET_APP,
MINET_EXTERNAL,
MINET_DEFAULT,
};
enum MinetDatatype {
MINET_NONE,
MINET_EVENT,
MINET_MONITORINGEVENT,
MINET_MONITORINGEVENTDESC,
MINET_RAWETHERNETPACKET,
MINET_PACKET,
MINET_ARPREQUESTRESPONSE,
MINET_SOCKREQUESTRESPONSE,
MINET_SOCKLIBREQUESTRESPONSE,
};
ostream & operator<<(ostream &os, const MinetModule &mon);
ostream & operator<<(ostream &os, const MinetDatatype &t);
struct MinetEvent {
enum {Dataflow, Exception, Timeout, Error } eventtype;
enum {IN, OUT, INOUT, NONE} direction;
MinetHandle handle;
int error;
double overtime;
MinetEvent();
MinetEvent(const MinetEvent &rhs);
virtual ~MinetEvent();
virtual const MinetEvent & operator= (const MinetEvent &rhs);
virtual void Serialize(const int fd) const;
virtual void Unserialize(const int fd);
virtual ostream & Print(ostream &os) const;
};
class MinetException : public string {
private:
MinetException() {}
public:
MinetException(const MinetException &rhs) : string(rhs) {}
MinetException(const string &rhs) : string(rhs) {}
MinetException(const char *rhs) : string(rhs) {}
virtual ~MinetException() {}
const MinetException &operator=(const MinetException &rhs)
{ ((string*)this)->operator=(rhs); return *this;}
virtual ostream & Print(ostream &os) const
{ os << "MinetException("<<((const string &)(*this))<<")"; return os;}
};
int MinetInit(const MinetModule &mod);
int MinetDeinit();
bool MinetIsModuleInConfig(const MinetModule &mod);
bool MinetIsModuleMonitored(const MinetModule &mod);
MinetHandle MinetConnect(const MinetModule &mod);
MinetHandle MinetAccept(const MinetModule &mod);
MinetHandle MinetAddExternalConnection(const int inputfd, const int outputfd);
int MinetClose(const MinetHandle &mh);
int MinetGetNextEvent(MinetEvent &event, double timeout=-1);
#define MINET_DECL(TYPE) \
int MinetSend(const MinetHandle &handle, const TYPE &object); \
int MinetReceive(const MinetHandle &handle, TYPE &object); \
int MinetMonitorSend(const MinetHandle &handle, const TYPE &object); \
int MinetMonitorReceive(const MinetHandle &handle, TYPE &object); \
MINET_DECL(MinetEvent)
MINET_DECL(RawEthernetPacket)
MINET_DECL(Packet)
MINET_DECL(ARPRequestResponse)
MINET_DECL(SockRequestResponse)
MINET_DECL(SockLibRequestResponse)
#include "Monitor.h"
int MinetSendToMonitor(const MinetMonitoringEvent &object);
int MinetSendToMonitor(const MinetMonitoringEventDescription &desc, const MinetMonitoringEvent &object=MinetMonitoringEvent("no further data"));
MINET_DECL(MinetMonitoringEvent)
MINET_DECL(MinetMonitoringEventDescription)
#endif