-rw-r--r-- | libopie2/opienet/opcap.h | 294 |
1 files changed, 294 insertions, 0 deletions
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h new file mode 100644 index 0000000..65c550c --- a/dev/null +++ b/libopie2/opienet/opcap.h | |||
@@ -0,0 +1,294 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) 2003 by the Wellenreiter team: | ||
4 | Martin J. Muench <mjm@remote-exploit.org> | ||
5 | Max Moser <mmo@remote-exploit.org | ||
6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
7 | =. | ||
8 | .=l. | ||
9 | .>+-= | ||
10 | _;:, .> :=|. This program is free software; you can | ||
11 | .> <`_, > . <= redistribute it and/or modify it under | ||
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
13 | .="- .-=="i, .._ License as published by the Free Software | ||
14 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
15 | ._= =} : or (at your option) any later version. | ||
16 | .%`+i> _;_. | ||
17 | .i_,=:_. -<s. This program is distributed in the hope that | ||
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
19 | : .. .:, . . . without even the implied warranty of | ||
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
22 | ..}^=.= = ; Library General Public License for more | ||
23 | ++= -. .` .: details. | ||
24 | : = ...= . :.=- | ||
25 | -. .:....=;==+<; You should have received a copy of the GNU | ||
26 | -_. . . )=. = Library General Public License along with | ||
27 | -- :-=` this library; see the file COPYING.LIB. | ||
28 | If not, write to the Free Software Foundation, | ||
29 | Inc., 59 Temple Place - Suite 330, | ||
30 | Boston, MA 02111-1307, USA. | ||
31 | |||
32 | */ | ||
33 | |||
34 | #ifndef OPCAP_H | ||
35 | #define OPCAP_H | ||
36 | |||
37 | /* LINUX */ | ||
38 | extern "C" // work around a bpf/pcap conflict in recent headers | ||
39 | { | ||
40 | #include <pcap.h> | ||
41 | } | ||
42 | #include <netinet/ether.h> | ||
43 | #include <netinet/ip.h> | ||
44 | #include <netinet/udp.h> | ||
45 | #include <netinet/tcp.h> | ||
46 | #include <time.h> | ||
47 | |||
48 | /* QT */ | ||
49 | #include <qhostaddress.h> | ||
50 | #include <qobject.h> | ||
51 | #include <qstring.h> | ||
52 | |||
53 | /* OPIE */ | ||
54 | #include <opie2/onetutils.h> | ||
55 | #include "802_11_user.h" | ||
56 | |||
57 | /* TYPEDEFS */ | ||
58 | typedef struct timeval timevalstruct; | ||
59 | typedef struct pcap_pkthdr packetheaderstruct; | ||
60 | |||
61 | /* FORWARDS */ | ||
62 | class OPacketCapturer; | ||
63 | |||
64 | /*====================================================================================== | ||
65 | * OPacket - A frame on the wire | ||
66 | *======================================================================================*/ | ||
67 | |||
68 | class OPacket : public QObject | ||
69 | { | ||
70 | Q_OBJECT | ||
71 | |||
72 | public: | ||
73 | OPacket( packetheaderstruct, const unsigned char*, QObject* parent ); | ||
74 | virtual ~OPacket(); | ||
75 | |||
76 | timevalstruct timeval() const; | ||
77 | |||
78 | OPacketCapturer* packetCapturer() const; | ||
79 | |||
80 | int caplen() const; | ||
81 | int len() const; | ||
82 | void dump() const; | ||
83 | |||
84 | private: | ||
85 | const packetheaderstruct _hdr; // pcap packet header | ||
86 | const unsigned char* _data; // pcap packet data | ||
87 | }; | ||
88 | |||
89 | /*====================================================================================== | ||
90 | * OEthernetPacket - DLT_EN10MB frame | ||
91 | *======================================================================================*/ | ||
92 | |||
93 | class OEthernetPacket : public QObject | ||
94 | { | ||
95 | Q_OBJECT | ||
96 | |||
97 | public: | ||
98 | OEthernetPacket( const struct ether_header*, QObject* parent = 0 ); | ||
99 | virtual ~OEthernetPacket(); | ||
100 | |||
101 | OMacAddress sourceAddress() const; | ||
102 | OMacAddress destinationAddress() const; | ||
103 | int type() const; | ||
104 | |||
105 | private: | ||
106 | const struct ether_header* _ether; | ||
107 | }; | ||
108 | |||
109 | |||
110 | /*====================================================================================== | ||
111 | * OWaveLanPacket - DLT_IEEE802_11 frame | ||
112 | *======================================================================================*/ | ||
113 | |||
114 | class OWaveLanPacket : public QObject | ||
115 | { | ||
116 | Q_OBJECT | ||
117 | |||
118 | public: | ||
119 | OWaveLanPacket( const struct ieee_802_11_header*, QObject* parent = 0 ); | ||
120 | virtual ~OWaveLanPacket(); | ||
121 | |||
122 | int duration() const; | ||
123 | bool fromDS() const; | ||
124 | bool toDS() const; | ||
125 | virtual OMacAddress macAddress1() const; | ||
126 | virtual OMacAddress macAddress2() const; | ||
127 | virtual OMacAddress macAddress3() const; | ||
128 | virtual OMacAddress macAddress4() const; | ||
129 | bool usesPowerManagement() const; | ||
130 | int type() const; | ||
131 | int subType() const; | ||
132 | int version() const; | ||
133 | bool usesWep() const; | ||
134 | |||
135 | private: | ||
136 | const struct ieee_802_11_header* _wlanhdr; | ||
137 | }; | ||
138 | |||
139 | |||
140 | /*====================================================================================== | ||
141 | * OWaveLanManagementPacket - type: management (T_MGMT) | ||
142 | *======================================================================================*/ | ||
143 | |||
144 | class OWaveLanManagementPacket : public QObject | ||
145 | { | ||
146 | Q_OBJECT | ||
147 | |||
148 | public: | ||
149 | OWaveLanManagementPacket( const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | ||
150 | virtual ~OWaveLanManagementPacket(); | ||
151 | |||
152 | QString SSID() const; | ||
153 | |||
154 | private: | ||
155 | const struct ieee_802_11_mgmt_header* _header; | ||
156 | const struct ieee_802_11_mgmt_body* _body; | ||
157 | }; | ||
158 | |||
159 | |||
160 | /*====================================================================================== | ||
161 | * OWaveLanDataPacket - type: data (T_DATA) | ||
162 | *======================================================================================*/ | ||
163 | |||
164 | class OWaveLanDataPacket : public QObject | ||
165 | { | ||
166 | Q_OBJECT | ||
167 | |||
168 | public: | ||
169 | OWaveLanDataPacket( const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | ||
170 | virtual ~OWaveLanDataPacket(); | ||
171 | |||
172 | private: | ||
173 | const struct ieee_802_11_data_header* _header; | ||
174 | }; | ||
175 | |||
176 | /*====================================================================================== | ||
177 | * OLLCPacket - IEEE 802.2 Link Level Control | ||
178 | *======================================================================================*/ | ||
179 | |||
180 | class OLLCPacket : public QObject | ||
181 | { | ||
182 | Q_OBJECT | ||
183 | |||
184 | public: | ||
185 | OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | ||
186 | virtual ~OLLCPacket(); | ||
187 | |||
188 | private: | ||
189 | const struct ieee_802_11_802_2_header* _header; | ||
190 | }; | ||
191 | |||
192 | /*====================================================================================== | ||
193 | * OIPPacket | ||
194 | *======================================================================================*/ | ||
195 | |||
196 | class OIPPacket : public QObject | ||
197 | { | ||
198 | Q_OBJECT | ||
199 | |||
200 | public: | ||
201 | OIPPacket( const struct iphdr*, QObject* parent = 0 ); | ||
202 | virtual ~OIPPacket(); | ||
203 | |||
204 | QHostAddress fromIPAddress() const; | ||
205 | QHostAddress toIPAddress() const; | ||
206 | |||
207 | int tos() const; | ||
208 | int len() const; | ||
209 | int id() const; | ||
210 | int offset() const; | ||
211 | int ttl() const; | ||
212 | int protocol() const; | ||
213 | int checksum() const; | ||
214 | |||
215 | private: | ||
216 | const struct iphdr* _iphdr; | ||
217 | }; | ||
218 | |||
219 | /*====================================================================================== | ||
220 | * OUDPPacket | ||
221 | *======================================================================================*/ | ||
222 | |||
223 | class OUDPPacket : public QObject | ||
224 | { | ||
225 | Q_OBJECT | ||
226 | |||
227 | public: | ||
228 | OUDPPacket( const struct udphdr*, QObject* parent = 0 ); | ||
229 | virtual ~OUDPPacket(); | ||
230 | |||
231 | int fromPort() const; | ||
232 | int toPort() const; | ||
233 | |||
234 | private: | ||
235 | const struct udphdr* _udphdr; | ||
236 | }; | ||
237 | |||
238 | /*====================================================================================== | ||
239 | * OTCPPacket | ||
240 | *======================================================================================*/ | ||
241 | |||
242 | class OTCPPacket : public QObject | ||
243 | { | ||
244 | Q_OBJECT | ||
245 | |||
246 | public: | ||
247 | OTCPPacket( const struct tcphdr*, QObject* parent = 0 ); | ||
248 | virtual ~OTCPPacket(); | ||
249 | |||
250 | int fromPort() const; | ||
251 | int toPort() const; | ||
252 | |||
253 | private: | ||
254 | const struct tcphdr* _tcphdr; | ||
255 | }; | ||
256 | |||
257 | |||
258 | /*====================================================================================== | ||
259 | * OPacketCapturer | ||
260 | *======================================================================================*/ | ||
261 | |||
262 | class OPacketCapturer : public QObject | ||
263 | { | ||
264 | Q_OBJECT | ||
265 | |||
266 | public: | ||
267 | OPacketCapturer( QObject* parent = 0, const char* name = 0 ); | ||
268 | ~OPacketCapturer(); | ||
269 | |||
270 | void setBlocking( bool ); | ||
271 | bool blocking() const; | ||
272 | |||
273 | void close(); | ||
274 | int dataLink() const; | ||
275 | int fileno() const; | ||
276 | OPacket* next(); | ||
277 | bool open( const QString& name ); | ||
278 | bool isOpen() const; | ||
279 | |||
280 | signals: | ||
281 | void receivedPacket( OPacket* ); | ||
282 | |||
283 | protected slots: | ||
284 | void readyToReceive(); | ||
285 | |||
286 | protected: | ||
287 | QString _name; // devicename | ||
288 | bool _open; // check this before doing pcap calls | ||
289 | pcap_t* _pch; // pcap library handle | ||
290 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; | ||
291 | }; | ||
292 | |||
293 | #endif // OPCAP_H | ||
294 | |||