-rw-r--r-- | libopie2/opienet/opcap.h | 160 |
1 files changed, 151 insertions, 9 deletions
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h index 65c550c..0b06572 100644 --- a/libopie2/opienet/opcap.h +++ b/libopie2/opienet/opcap.h | |||
@@ -57,12 +57,13 @@ extern "C" // work around a bpf/pcap conflict in recent headers | |||
57 | /* TYPEDEFS */ | 57 | /* TYPEDEFS */ |
58 | typedef struct timeval timevalstruct; | 58 | typedef struct timeval timevalstruct; |
59 | typedef struct pcap_pkthdr packetheaderstruct; | 59 | typedef struct pcap_pkthdr packetheaderstruct; |
60 | 60 | ||
61 | /* FORWARDS */ | 61 | /* FORWARDS */ |
62 | class OPacketCapturer; | 62 | class OPacketCapturer; |
63 | class QSocketNotifier; | ||
63 | 64 | ||
64 | /*====================================================================================== | 65 | /*====================================================================================== |
65 | * OPacket - A frame on the wire | 66 | * OPacket - A frame on the wire |
66 | *======================================================================================*/ | 67 | *======================================================================================*/ |
67 | 68 | ||
68 | class OPacket : public QObject | 69 | class OPacket : public QObject |
@@ -81,24 +82,25 @@ class OPacket : public QObject | |||
81 | int len() const; | 82 | int len() const; |
82 | void dump() const; | 83 | void dump() const; |
83 | 84 | ||
84 | private: | 85 | private: |
85 | const packetheaderstruct _hdr; // pcap packet header | 86 | const packetheaderstruct _hdr; // pcap packet header |
86 | const unsigned char* _data; // pcap packet data | 87 | const unsigned char* _data; // pcap packet data |
88 | const unsigned char* _end; // end of pcap packet data | ||
87 | }; | 89 | }; |
88 | 90 | ||
89 | /*====================================================================================== | 91 | /*====================================================================================== |
90 | * OEthernetPacket - DLT_EN10MB frame | 92 | * OEthernetPacket - DLT_EN10MB frame |
91 | *======================================================================================*/ | 93 | *======================================================================================*/ |
92 | 94 | ||
93 | class OEthernetPacket : public QObject | 95 | class OEthernetPacket : public QObject |
94 | { | 96 | { |
95 | Q_OBJECT | 97 | Q_OBJECT |
96 | 98 | ||
97 | public: | 99 | public: |
98 | OEthernetPacket( const struct ether_header*, QObject* parent = 0 ); | 100 | OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); |
99 | virtual ~OEthernetPacket(); | 101 | virtual ~OEthernetPacket(); |
100 | 102 | ||
101 | OMacAddress sourceAddress() const; | 103 | OMacAddress sourceAddress() const; |
102 | OMacAddress destinationAddress() const; | 104 | OMacAddress destinationAddress() const; |
103 | int type() const; | 105 | int type() const; |
104 | 106 | ||
@@ -113,13 +115,13 @@ class OEthernetPacket : public QObject | |||
113 | 115 | ||
114 | class OWaveLanPacket : public QObject | 116 | class OWaveLanPacket : public QObject |
115 | { | 117 | { |
116 | Q_OBJECT | 118 | Q_OBJECT |
117 | 119 | ||
118 | public: | 120 | public: |
119 | OWaveLanPacket( const struct ieee_802_11_header*, QObject* parent = 0 ); | 121 | OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); |
120 | virtual ~OWaveLanPacket(); | 122 | virtual ~OWaveLanPacket(); |
121 | 123 | ||
122 | int duration() const; | 124 | int duration() const; |
123 | bool fromDS() const; | 125 | bool fromDS() const; |
124 | bool toDS() const; | 126 | bool toDS() const; |
125 | virtual OMacAddress macAddress1() const; | 127 | virtual OMacAddress macAddress1() const; |
@@ -143,33 +145,172 @@ class OWaveLanPacket : public QObject | |||
143 | 145 | ||
144 | class OWaveLanManagementPacket : public QObject | 146 | class OWaveLanManagementPacket : public QObject |
145 | { | 147 | { |
146 | Q_OBJECT | 148 | Q_OBJECT |
147 | 149 | ||
148 | public: | 150 | public: |
149 | OWaveLanManagementPacket( const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); | 151 | OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); |
150 | virtual ~OWaveLanManagementPacket(); | 152 | virtual ~OWaveLanManagementPacket(); |
151 | 153 | ||
152 | QString SSID() const; | 154 | int beaconInterval() const; |
155 | int capabilities() const; // generic | ||
156 | |||
157 | bool canESS() const; | ||
158 | bool canIBSS() const; | ||
159 | bool canCFP() const; | ||
160 | bool canCFP_REQ() const; | ||
161 | bool canPrivacy() const; | ||
153 | 162 | ||
154 | private: | 163 | private: |
155 | const struct ieee_802_11_mgmt_header* _header; | 164 | const struct ieee_802_11_mgmt_header* _header; |
156 | const struct ieee_802_11_mgmt_body* _body; | 165 | const struct ieee_802_11_mgmt_body* _body; |
157 | }; | 166 | }; |
158 | 167 | ||
159 | 168 | ||
160 | /*====================================================================================== | 169 | /*====================================================================================== |
170 | * OWaveLanManagementSSID | ||
171 | *======================================================================================*/ | ||
172 | |||
173 | class OWaveLanManagementSSID : public QObject | ||
174 | { | ||
175 | Q_OBJECT | ||
176 | |||
177 | public: | ||
178 | OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); | ||
179 | virtual ~OWaveLanManagementSSID(); | ||
180 | |||
181 | QString ID() const; | ||
182 | |||
183 | private: | ||
184 | const struct ssid_t* _data; | ||
185 | }; | ||
186 | |||
187 | /*====================================================================================== | ||
188 | * OWaveLanManagementRates | ||
189 | *======================================================================================*/ | ||
190 | |||
191 | class OWaveLanManagementRates : public QObject | ||
192 | { | ||
193 | Q_OBJECT | ||
194 | |||
195 | public: | ||
196 | OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); | ||
197 | virtual ~OWaveLanManagementRates(); | ||
198 | |||
199 | private: | ||
200 | const struct rates_t* _data; | ||
201 | }; | ||
202 | |||
203 | /*====================================================================================== | ||
204 | * OWaveLanManagementCF | ||
205 | *======================================================================================*/ | ||
206 | |||
207 | class OWaveLanManagementCF : public QObject | ||
208 | { | ||
209 | Q_OBJECT | ||
210 | |||
211 | public: | ||
212 | OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); | ||
213 | virtual ~OWaveLanManagementCF(); | ||
214 | |||
215 | private: | ||
216 | const struct cf_t* _data; | ||
217 | }; | ||
218 | |||
219 | /*====================================================================================== | ||
220 | * OWaveLanManagementFH | ||
221 | *======================================================================================*/ | ||
222 | |||
223 | class OWaveLanManagementFH : public QObject | ||
224 | { | ||
225 | Q_OBJECT | ||
226 | |||
227 | public: | ||
228 | OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); | ||
229 | virtual ~OWaveLanManagementFH(); | ||
230 | |||
231 | private: | ||
232 | const struct fh_t* _data; | ||
233 | }; | ||
234 | |||
235 | /*====================================================================================== | ||
236 | * OWaveLanManagementDS | ||
237 | *======================================================================================*/ | ||
238 | |||
239 | class OWaveLanManagementDS : public QObject | ||
240 | { | ||
241 | Q_OBJECT | ||
242 | |||
243 | public: | ||
244 | OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); | ||
245 | virtual ~OWaveLanManagementDS(); | ||
246 | |||
247 | int channel() const; | ||
248 | |||
249 | private: | ||
250 | const struct ds_t* _data; | ||
251 | }; | ||
252 | |||
253 | /*====================================================================================== | ||
254 | * OWaveLanManagementTim | ||
255 | *======================================================================================*/ | ||
256 | |||
257 | class OWaveLanManagementTim : public QObject | ||
258 | { | ||
259 | Q_OBJECT | ||
260 | |||
261 | public: | ||
262 | OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); | ||
263 | virtual ~OWaveLanManagementTim(); | ||
264 | |||
265 | private: | ||
266 | const struct tim_t* _data; | ||
267 | }; | ||
268 | |||
269 | /*====================================================================================== | ||
270 | * OWaveLanManagementIBSS | ||
271 | *======================================================================================*/ | ||
272 | |||
273 | class OWaveLanManagementIBSS : public QObject | ||
274 | { | ||
275 | Q_OBJECT | ||
276 | |||
277 | public: | ||
278 | OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); | ||
279 | virtual ~OWaveLanManagementIBSS(); | ||
280 | |||
281 | private: | ||
282 | const struct ibss_t* _data; | ||
283 | }; | ||
284 | |||
285 | /*====================================================================================== | ||
286 | * OWaveLanManagementChallenge | ||
287 | *======================================================================================*/ | ||
288 | |||
289 | class OWaveLanManagementChallenge : public QObject | ||
290 | { | ||
291 | Q_OBJECT | ||
292 | |||
293 | public: | ||
294 | OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); | ||
295 | virtual ~OWaveLanManagementChallenge(); | ||
296 | |||
297 | private: | ||
298 | const struct challenge_t* _data; | ||
299 | }; | ||
300 | |||
301 | /*====================================================================================== | ||
161 | * OWaveLanDataPacket - type: data (T_DATA) | 302 | * OWaveLanDataPacket - type: data (T_DATA) |
162 | *======================================================================================*/ | 303 | *======================================================================================*/ |
163 | 304 | ||
164 | class OWaveLanDataPacket : public QObject | 305 | class OWaveLanDataPacket : public QObject |
165 | { | 306 | { |
166 | Q_OBJECT | 307 | Q_OBJECT |
167 | 308 | ||
168 | public: | 309 | public: |
169 | OWaveLanDataPacket( const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); | 310 | OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); |
170 | virtual ~OWaveLanDataPacket(); | 311 | virtual ~OWaveLanDataPacket(); |
171 | 312 | ||
172 | private: | 313 | private: |
173 | const struct ieee_802_11_data_header* _header; | 314 | const struct ieee_802_11_data_header* _header; |
174 | }; | 315 | }; |
175 | 316 | ||
@@ -179,13 +320,13 @@ class OWaveLanDataPacket : public QObject | |||
179 | 320 | ||
180 | class OLLCPacket : public QObject | 321 | class OLLCPacket : public QObject |
181 | { | 322 | { |
182 | Q_OBJECT | 323 | Q_OBJECT |
183 | 324 | ||
184 | public: | 325 | public: |
185 | OLLCPacket( const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); | 326 | OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); |
186 | virtual ~OLLCPacket(); | 327 | virtual ~OLLCPacket(); |
187 | 328 | ||
188 | private: | 329 | private: |
189 | const struct ieee_802_11_802_2_header* _header; | 330 | const struct ieee_802_11_802_2_header* _header; |
190 | }; | 331 | }; |
191 | 332 | ||
@@ -195,13 +336,13 @@ class OLLCPacket : public QObject | |||
195 | 336 | ||
196 | class OIPPacket : public QObject | 337 | class OIPPacket : public QObject |
197 | { | 338 | { |
198 | Q_OBJECT | 339 | Q_OBJECT |
199 | 340 | ||
200 | public: | 341 | public: |
201 | OIPPacket( const struct iphdr*, QObject* parent = 0 ); | 342 | OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); |
202 | virtual ~OIPPacket(); | 343 | virtual ~OIPPacket(); |
203 | 344 | ||
204 | QHostAddress fromIPAddress() const; | 345 | QHostAddress fromIPAddress() const; |
205 | QHostAddress toIPAddress() const; | 346 | QHostAddress toIPAddress() const; |
206 | 347 | ||
207 | int tos() const; | 348 | int tos() const; |
@@ -222,13 +363,13 @@ class OIPPacket : public QObject | |||
222 | 363 | ||
223 | class OUDPPacket : public QObject | 364 | class OUDPPacket : public QObject |
224 | { | 365 | { |
225 | Q_OBJECT | 366 | Q_OBJECT |
226 | 367 | ||
227 | public: | 368 | public: |
228 | OUDPPacket( const struct udphdr*, QObject* parent = 0 ); | 369 | OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); |
229 | virtual ~OUDPPacket(); | 370 | virtual ~OUDPPacket(); |
230 | 371 | ||
231 | int fromPort() const; | 372 | int fromPort() const; |
232 | int toPort() const; | 373 | int toPort() const; |
233 | 374 | ||
234 | private: | 375 | private: |
@@ -241,13 +382,13 @@ class OUDPPacket : public QObject | |||
241 | 382 | ||
242 | class OTCPPacket : public QObject | 383 | class OTCPPacket : public QObject |
243 | { | 384 | { |
244 | Q_OBJECT | 385 | Q_OBJECT |
245 | 386 | ||
246 | public: | 387 | public: |
247 | OTCPPacket( const struct tcphdr*, QObject* parent = 0 ); | 388 | OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); |
248 | virtual ~OTCPPacket(); | 389 | virtual ~OTCPPacket(); |
249 | 390 | ||
250 | int fromPort() const; | 391 | int fromPort() const; |
251 | int toPort() const; | 392 | int toPort() const; |
252 | 393 | ||
253 | private: | 394 | private: |
@@ -284,11 +425,12 @@ class OPacketCapturer : public QObject | |||
284 | void readyToReceive(); | 425 | void readyToReceive(); |
285 | 426 | ||
286 | protected: | 427 | protected: |
287 | QString _name; // devicename | 428 | QString _name; // devicename |
288 | bool _open; // check this before doing pcap calls | 429 | bool _open; // check this before doing pcap calls |
289 | pcap_t* _pch; // pcap library handle | 430 | pcap_t* _pch; // pcap library handle |
431 | QSocketNotifier* _sn; // socket notifier for main loop | ||
290 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; | 432 | mutable char _errbuf[PCAP_ERRBUF_SIZE]; |
291 | }; | 433 | }; |
292 | 434 | ||
293 | #endif // OPCAP_H | 435 | #endif // OPCAP_H |
294 | 436 | ||