summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-04 01:34:13 (UTC)
committer mickeyl <mickeyl>2003-10-04 01:34:13 (UTC)
commita4793f5226e9eb5c8a718cca9335c23530e08b08 (patch) (unidiff)
tree9e18d900f9c0a96170c8221ba4e60e7b7937cf39
parente2716e3862915582d0ce48aaacc967f5b0cf6550 (diff)
downloadopie-a4793f5226e9eb5c8a718cca9335c23530e08b08.zip
opie-a4793f5226e9eb5c8a718cca9335c23530e08b08.tar.gz
opie-a4793f5226e9eb5c8a718cca9335c23530e08b08.tar.bz2
Although not yet complete, the DHCP decoding is now usable
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp82
-rw-r--r--libopie2/opienet/opcap.h10
2 files changed, 92 insertions, 0 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index f1f2b4b..7a6f61b 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -1,1187 +1,1269 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/opcap.h> 36#include <opie2/opcap.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) 40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects)
41#include <qsocketnotifier.h> 41#include <qsocketnotifier.h>
42#include <qobjectlist.h> 42#include <qobjectlist.h>
43 43
44#include "udp_ports.h" 44#include "udp_ports.h"
45 45
46/*====================================================================================== 46/*======================================================================================
47 * OPacket 47 * OPacket
48 *======================================================================================*/ 48 *======================================================================================*/
49 49
50OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 50OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
51 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 51 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
52{ 52{
53 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 53 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
54 54
55 _end = (unsigned char*) data + header.len; 55 _end = (unsigned char*) data + header.len;
56 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 56 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
57 57
58 switch ( datalink ) 58 switch ( datalink )
59 { 59 {
60 case DLT_EN10MB: 60 case DLT_EN10MB:
61 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 61 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
62 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 62 new OEthernetPacket( _end, (const struct ether_header*) data, this );
63 break; 63 break;
64 64
65 case DLT_IEEE802_11: 65 case DLT_IEEE802_11:
66 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 66 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
67 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 67 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
68 break; 68 break;
69 69
70 case DLT_PRISM_HEADER: 70 case DLT_PRISM_HEADER:
71 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); 71 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" );
72 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); 72 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this );
73 break; 73 break;
74 74
75 default: 75 default:
76 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink ); 76 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink );
77 } 77 }
78} 78}
79 79
80 80
81OPacket::~OPacket() 81OPacket::~OPacket()
82{ 82{
83} 83}
84 84
85 85
86timevalstruct OPacket::timeval() const 86timevalstruct OPacket::timeval() const
87{ 87{
88 return _hdr.ts; 88 return _hdr.ts;
89} 89}
90 90
91 91
92int OPacket::caplen() const 92int OPacket::caplen() const
93{ 93{
94 return _hdr.caplen; 94 return _hdr.caplen;
95} 95}
96 96
97 97
98void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 98void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
99{ 99{
100 if (!l) return; 100 if (!l) return;
101 QObject* o = l->first(); 101 QObject* o = l->first();
102 while ( o ) 102 while ( o )
103 { 103 {
104 stats[o->name()]++; 104 stats[o->name()]++;
105 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 105 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
106 o = l->next(); 106 o = l->next();
107 } 107 }
108} 108}
109 109
110 110
111QString OPacket::dump( int bpl ) const 111QString OPacket::dump( int bpl ) const
112{ 112{
113 static int index = 0; 113 static int index = 0;
114 index++; 114 index++;
115 int len = _hdr.caplen; 115 int len = _hdr.caplen;
116 QString str; 116 QString str;
117 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 117 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
118 str.append( "0000: " ); 118 str.append( "0000: " );
119 QString tmp; 119 QString tmp;
120 QString bytes; 120 QString bytes;
121 QString chars; 121 QString chars;
122 122
123 for ( int i = 0; i < len; ++i ) 123 for ( int i = 0; i < len; ++i )
124 { 124 {
125 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 125 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
126 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 126 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
127 else chars.append( '.' ); 127 else chars.append( '.' );
128 128
129 if ( !((i+1) % bpl) ) 129 if ( !((i+1) % bpl) )
130 { 130 {
131 str.append( bytes ); 131 str.append( bytes );
132 str.append( ' ' ); 132 str.append( ' ' );
133 str.append( chars ); 133 str.append( chars );
134 str.append( '\n' ); 134 str.append( '\n' );
135 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); 135 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp );
136 bytes = ""; 136 bytes = "";
137 chars = ""; 137 chars = "";
138 } 138 }
139 139
140 } 140 }
141 if ( (len % bpl) ) 141 if ( (len % bpl) )
142 { 142 {
143 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 143 str.append( bytes.leftJustify( 1 + 3*bpl ) );
144 str.append( chars ); 144 str.append( chars );
145 } 145 }
146 str.append( '\n' ); 146 str.append( '\n' );
147 return str; 147 return str;
148} 148}
149 149
150 150
151int OPacket::len() const 151int OPacket::len() const
152{ 152{
153 return _hdr.len; 153 return _hdr.len;
154} 154}
155 155
156 156
157/*====================================================================================== 157/*======================================================================================
158 * OEthernetPacket 158 * OEthernetPacket
159 *======================================================================================*/ 159 *======================================================================================*/
160 160
161OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 161OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
162 :QObject( parent, "Ethernet" ), _ether( data ) 162 :QObject( parent, "Ethernet" ), _ether( data )
163{ 163{
164 164
165 qDebug( "Source = %s", (const char*) sourceAddress().toString() ); 165 qDebug( "Source = %s", (const char*) sourceAddress().toString() );
166 qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); 166 qDebug( "Destination = %s", (const char*) destinationAddress().toString() );
167 167
168 if ( sourceAddress() == OMacAddress::broadcast ) 168 if ( sourceAddress() == OMacAddress::broadcast )
169 qDebug( "Source is broadcast address" ); 169 qDebug( "Source is broadcast address" );
170 if ( destinationAddress() == OMacAddress::broadcast ) 170 if ( destinationAddress() == OMacAddress::broadcast )
171 qDebug( "Destination is broadcast address" ); 171 qDebug( "Destination is broadcast address" );
172 172
173 switch ( type() ) 173 switch ( type() )
174 { 174 {
175 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 175 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
176 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } 176 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; }
177 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } 177 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; }
178 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); 178 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" );
179 } 179 }
180 180
181} 181}
182 182
183 183
184OEthernetPacket::~OEthernetPacket() 184OEthernetPacket::~OEthernetPacket()
185{ 185{
186} 186}
187 187
188 188
189OMacAddress OEthernetPacket::sourceAddress() const 189OMacAddress OEthernetPacket::sourceAddress() const
190{ 190{
191 return OMacAddress( _ether->ether_shost ); 191 return OMacAddress( _ether->ether_shost );
192} 192}
193 193
194 194
195OMacAddress OEthernetPacket::destinationAddress() const 195OMacAddress OEthernetPacket::destinationAddress() const
196{ 196{
197 return OMacAddress( _ether->ether_dhost ); 197 return OMacAddress( _ether->ether_dhost );
198} 198}
199 199
200int OEthernetPacket::type() const 200int OEthernetPacket::type() const
201{ 201{
202 return ntohs( _ether->ether_type ); 202 return ntohs( _ether->ether_type );
203} 203}
204 204
205 205
206/*====================================================================================== 206/*======================================================================================
207 * OIPPacket 207 * OIPPacket
208 *======================================================================================*/ 208 *======================================================================================*/
209 209
210 210
211OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) 211OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
212 :QObject( parent, "IP" ), _iphdr( data ) 212 :QObject( parent, "IP" ), _iphdr( data )
213{ 213{
214 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); 214 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." );
215 215
216 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); 216 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) );
217 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); 217 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) );
218 218
219 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); 219 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() );
220 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); 220 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() );
221 221
222 switch ( protocol() ) 222 switch ( protocol() )
223 { 223 {
224 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; 224 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
225 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; 225 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
226 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); 226 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() );
227 } 227 }
228 228
229} 229}
230 230
231OIPPacket::~OIPPacket() 231OIPPacket::~OIPPacket()
232{ 232{
233} 233}
234 234
235 235
236QHostAddress OIPPacket::fromIPAddress() const 236QHostAddress OIPPacket::fromIPAddress() const
237{ 237{
238 return EXTRACT_32BITS( &_iphdr->saddr ); 238 return EXTRACT_32BITS( &_iphdr->saddr );
239} 239}
240 240
241 241
242QHostAddress OIPPacket::toIPAddress() const 242QHostAddress OIPPacket::toIPAddress() const
243{ 243{
244 return EXTRACT_32BITS( &_iphdr->saddr ); 244 return EXTRACT_32BITS( &_iphdr->saddr );
245} 245}
246 246
247 247
248int OIPPacket::tos() const 248int OIPPacket::tos() const
249{ 249{
250 return _iphdr->tos; 250 return _iphdr->tos;
251} 251}
252 252
253 253
254int OIPPacket::len() const 254int OIPPacket::len() const
255{ 255{
256 return EXTRACT_16BITS( &_iphdr->tot_len ); 256 return EXTRACT_16BITS( &_iphdr->tot_len );
257} 257}
258 258
259 259
260int OIPPacket::id() const 260int OIPPacket::id() const
261{ 261{
262 return EXTRACT_16BITS( &_iphdr->id ); 262 return EXTRACT_16BITS( &_iphdr->id );
263} 263}
264 264
265 265
266int OIPPacket::offset() const 266int OIPPacket::offset() const
267{ 267{
268 return EXTRACT_16BITS( &_iphdr->frag_off ); 268 return EXTRACT_16BITS( &_iphdr->frag_off );
269} 269}
270 270
271 271
272int OIPPacket::ttl() const 272int OIPPacket::ttl() const
273{ 273{
274 return _iphdr->ttl; 274 return _iphdr->ttl;
275} 275}
276 276
277 277
278int OIPPacket::protocol() const 278int OIPPacket::protocol() const
279{ 279{
280 return _iphdr->protocol; 280 return _iphdr->protocol;
281} 281}
282 282
283 283
284int OIPPacket::checksum() const 284int OIPPacket::checksum() const
285{ 285{
286 return EXTRACT_16BITS( &_iphdr->check ); 286 return EXTRACT_16BITS( &_iphdr->check );
287} 287}
288 288
289/*====================================================================================== 289/*======================================================================================
290 * OARPPacket 290 * OARPPacket
291 *======================================================================================*/ 291 *======================================================================================*/
292 292
293 293
294OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) 294OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent )
295 :QObject( parent, "ARP" ), _arphdr( data ) 295 :QObject( parent, "ARP" ), _arphdr( data )
296{ 296{
297 qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." ); 297 qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." );
298 qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() ); 298 qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() );
299 qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() ); 299 qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() );
300 qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() ); 300 qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() );
301} 301}
302 302
303 303
304OARPPacket::~OARPPacket() 304OARPPacket::~OARPPacket()
305{ 305{
306} 306}
307 307
308 308
309QString OARPPacket::type() const 309QString OARPPacket::type() const
310{ 310{
311 switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) 311 switch ( EXTRACT_16BITS( &_arphdr->ar_op ) )
312 { 312 {
313 case 1: return "REQUEST"; 313 case 1: return "REQUEST";
314 case 2: return "REPLY"; 314 case 2: return "REPLY";
315 case 3: return "RREQUEST"; 315 case 3: return "RREQUEST";
316 case 4: return "RREPLY"; 316 case 4: return "RREPLY";
317 case 8: return "InREQUEST"; 317 case 8: return "InREQUEST";
318 case 9: return "InREPLY"; 318 case 9: return "InREPLY";
319 case 10: return "NAK"; 319 case 10: return "NAK";
320 default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; 320 default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>";
321 } 321 }
322} 322}
323 323
324 324
325QHostAddress OARPPacket::senderIPV4Address() const 325QHostAddress OARPPacket::senderIPV4Address() const
326{ 326{
327 return EXTRACT_32BITS( &_arphdr->ar_sip ); 327 return EXTRACT_32BITS( &_arphdr->ar_sip );
328} 328}
329 329
330 330
331QHostAddress OARPPacket::targetIPV4Address() const 331QHostAddress OARPPacket::targetIPV4Address() const
332{ 332{
333 return EXTRACT_32BITS( &_arphdr->ar_tip ); 333 return EXTRACT_32BITS( &_arphdr->ar_tip );
334} 334}
335 335
336 336
337OMacAddress OARPPacket::senderMacAddress() const 337OMacAddress OARPPacket::senderMacAddress() const
338{ 338{
339 return OMacAddress( _arphdr->ar_sha ); 339 return OMacAddress( _arphdr->ar_sha );
340} 340}
341 341
342 342
343OMacAddress OARPPacket::targetMacAddress() const 343OMacAddress OARPPacket::targetMacAddress() const
344{ 344{
345 return OMacAddress( _arphdr->ar_tha ); 345 return OMacAddress( _arphdr->ar_tha );
346} 346}
347 347
348 348
349/*====================================================================================== 349/*======================================================================================
350 * OUDPPacket 350 * OUDPPacket
351 *======================================================================================*/ 351 *======================================================================================*/
352 352
353 353
354OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) 354OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
355 :QObject( parent, "UDP" ), _udphdr( data ) 355 :QObject( parent, "UDP" ), _udphdr( data )
356 356
357{ 357{
358 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); 358 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." );
359 qDebug( "fromPort = %d", fromPort() ); 359 qDebug( "fromPort = %d", fromPort() );
360 qDebug( " toPort = %d", toPort() ); 360 qDebug( " toPort = %d", toPort() );
361 361
362 // TODO: Make this a case or a hash if we know more udp protocols 362 // TODO: Make this a case or a hash if we know more udp protocols
363 363
364 if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || 364 if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC ||
365 toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) 365 toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC )
366 { 366 {
367 qDebug( "seems to be part of a DHCP conversation => creating DHCP packet." ); 367 qDebug( "seems to be part of a DHCP conversation => creating DHCP packet." );
368 new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); 368 new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this );
369 } 369 }
370} 370}
371 371
372 372
373OUDPPacket::~OUDPPacket() 373OUDPPacket::~OUDPPacket()
374{ 374{
375} 375}
376 376
377 377
378int OUDPPacket::fromPort() const 378int OUDPPacket::fromPort() const
379{ 379{
380 return EXTRACT_16BITS( &_udphdr->source ); 380 return EXTRACT_16BITS( &_udphdr->source );
381} 381}
382 382
383 383
384int OUDPPacket::toPort() const 384int OUDPPacket::toPort() const
385{ 385{
386 return EXTRACT_16BITS( &_udphdr->dest ); 386 return EXTRACT_16BITS( &_udphdr->dest );
387} 387}
388 388
389 389
390int OUDPPacket::length() const 390int OUDPPacket::length() const
391{ 391{
392 return EXTRACT_16BITS( &_udphdr->len ); 392 return EXTRACT_16BITS( &_udphdr->len );
393} 393}
394 394
395 395
396int OUDPPacket::checksum() const 396int OUDPPacket::checksum() const
397{ 397{
398 return EXTRACT_16BITS( &_udphdr->check ); 398 return EXTRACT_16BITS( &_udphdr->check );
399} 399}
400 400
401 401
402/*====================================================================================== 402/*======================================================================================
403 * ODHCPPacket 403 * ODHCPPacket
404 *======================================================================================*/ 404 *======================================================================================*/
405 405
406 406
407ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) 407ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent )
408 :QObject( parent, "DHCP" ), _dhcphdr( data ) 408 :QObject( parent, "DHCP" ), _dhcphdr( data )
409 409
410{ 410{
411 qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." ); 411 qDebug( "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." );
412 qDebug( "DHCP opcode seems to be %02d - '%s'", _dhcphdr->op, isRequest() ? "REQUEST" : "REPLY" );
413 qDebug( "clientAddress: %s", (const char*) clientAddress().toString() );
414 qDebug( " yourAddress: %s", (const char*) yourAddress().toString() );
415 qDebug( "serverAddress: %s", (const char*) serverAddress().toString() );
416 qDebug( " relayAddress: %s", (const char*) relayAddress().toString() );
417 qDebug( "parsing DHCP options..." );
418
419 _type = 0;
420
421 const unsigned char* option = &_dhcphdr->options[4];
422 char tag = -1;
423 char len = -1;
424
425 while ( ( tag = *option++ ) != -1 /* end of option field */ )
426 {
427 len = *option++;
428 qDebug( "recognized DHCP option #%d, length %d", tag, len );
429
430 if ( tag == DHO_DHCP_MESSAGE_TYPE )
431 _type = *option;
432
433 option += len;
434 if ( option >= end )
435 {
436 qWarning( "DHCP parsing ERROR: sanity check says the packet is at its end!" );
437 break;
438 }
439 }
440
441 qDebug( "DHCP type seems to be '%s'", (const char*) type() );
412} 442}
413 443
414 444
415ODHCPPacket::~ODHCPPacket() 445ODHCPPacket::~ODHCPPacket()
416{ 446{
417} 447}
418 448
419 449
450bool ODHCPPacket::isRequest() const
451{
452 return ( _dhcphdr->op == 01 );
453}
454
455
456bool ODHCPPacket::isReply() const
457{
458 return ( _dhcphdr->op == 02 );
459}
460
461
462QString ODHCPPacket::type() const
463{
464 switch ( _type )
465 {
466 case 1: return "DISCOVER";
467 case 2: return "OFFER";
468 case 3: return "REQUEST";
469 case 4: return "DECLINE";
470 case 5: return "ACK";
471 case 6: return "NAK";
472 case 7: return "RELEASE";
473 case 8: return "INFORM";
474 default: qWarning( "ODHCPPacket::type(): invalid DHCP type (%d) !", _dhcphdr->op ); return "<unknown>";
475 }
476}
477
478
479QHostAddress ODHCPPacket::clientAddress() const
480{
481 return EXTRACT_32BITS( &_dhcphdr->ciaddr );
482}
483
484
485QHostAddress ODHCPPacket::yourAddress() const
486{
487 return EXTRACT_32BITS( &_dhcphdr->yiaddr );
488}
489
490
491QHostAddress ODHCPPacket::serverAddress() const
492{
493 return EXTRACT_32BITS( &_dhcphdr->siaddr );
494}
495
496
497QHostAddress ODHCPPacket::relayAddress() const
498{
499 return EXTRACT_32BITS( &_dhcphdr->giaddr );
500}
501
420/*====================================================================================== 502/*======================================================================================
421 * OTCPPacket 503 * OTCPPacket
422 *======================================================================================*/ 504 *======================================================================================*/
423 505
424 506
425OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) 507OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
426 :QObject( parent, "TCP" ), _tcphdr( data ) 508 :QObject( parent, "TCP" ), _tcphdr( data )
427 509
428{ 510{
429 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); 511 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." );
430} 512}
431 513
432 514
433OTCPPacket::~OTCPPacket() 515OTCPPacket::~OTCPPacket()
434{ 516{
435} 517}
436 518
437 519
438int OTCPPacket::fromPort() const 520int OTCPPacket::fromPort() const
439{ 521{
440 return EXTRACT_16BITS( &_tcphdr->source ); 522 return EXTRACT_16BITS( &_tcphdr->source );
441} 523}
442 524
443 525
444int OTCPPacket::toPort() const 526int OTCPPacket::toPort() const
445{ 527{
446 return EXTRACT_16BITS( &_tcphdr->dest ); 528 return EXTRACT_16BITS( &_tcphdr->dest );
447} 529}
448 530
449 531
450int OTCPPacket::seq() const 532int OTCPPacket::seq() const
451{ 533{
452 return EXTRACT_16BITS( &_tcphdr->seq ); 534 return EXTRACT_16BITS( &_tcphdr->seq );
453} 535}
454 536
455 537
456int OTCPPacket::ack() const 538int OTCPPacket::ack() const
457{ 539{
458 return EXTRACT_16BITS( &_tcphdr->ack_seq ); 540 return EXTRACT_16BITS( &_tcphdr->ack_seq );
459} 541}
460 542
461 543
462int OTCPPacket::window() const 544int OTCPPacket::window() const
463{ 545{
464 return EXTRACT_16BITS( &_tcphdr->window ); 546 return EXTRACT_16BITS( &_tcphdr->window );
465} 547}
466 548
467 549
468int OTCPPacket::checksum() const 550int OTCPPacket::checksum() const
469{ 551{
470 return EXTRACT_16BITS( &_tcphdr->check ); 552 return EXTRACT_16BITS( &_tcphdr->check );
471} 553}
472 554
473/*====================================================================================== 555/*======================================================================================
474 * OPrismHeaderPacket 556 * OPrismHeaderPacket
475 *======================================================================================*/ 557 *======================================================================================*/
476 558
477 559
478OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) 560OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent )
479 :QObject( parent, "Prism" ), _header( data ) 561 :QObject( parent, "Prism" ), _header( data )
480 562
481{ 563{
482 qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." ); 564 qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." );
483 565
484 qDebug( "Signal Strength = %d", data->signal.data ); 566 qDebug( "Signal Strength = %d", data->signal.data );
485 567
486 new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); 568 new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this );
487} 569}
488 570
489OPrismHeaderPacket::~OPrismHeaderPacket() 571OPrismHeaderPacket::~OPrismHeaderPacket()
490{ 572{
491} 573}
492 574
493 575
494unsigned int OPrismHeaderPacket::signalStrength() const 576unsigned int OPrismHeaderPacket::signalStrength() const
495{ 577{
496 return _header->signal.data; 578 return _header->signal.data;
497} 579}
498 580
499/*====================================================================================== 581/*======================================================================================
500 * OWaveLanPacket 582 * OWaveLanPacket
501 *======================================================================================*/ 583 *======================================================================================*/
502 584
503 585
504OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) 586OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
505 :QObject( parent, "802.11" ), _wlanhdr( data ) 587 :QObject( parent, "802.11" ), _wlanhdr( data )
506 588
507{ 589{
508 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); 590 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." );
509 qDebug( "type: %0X", type() ); 591 qDebug( "type: %0X", type() );
510 qDebug( "subType: %0X", subType() ); 592 qDebug( "subType: %0X", subType() );
511 qDebug( "duration: %d", duration() ); 593 qDebug( "duration: %d", duration() );
512 qDebug( "powermanagement: %d", usesPowerManagement() ); 594 qDebug( "powermanagement: %d", usesPowerManagement() );
513 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); 595 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" );
514 qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); 596 qDebug( "MAC1: %s", (const char*) macAddress1().toString() );
515 qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); 597 qDebug( "MAC2: %s", (const char*) macAddress2().toString() );
516 qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); 598 qDebug( "MAC3: %s", (const char*) macAddress3().toString() );
517 qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); 599 qDebug( "MAC4: %s", (const char*) macAddress4().toString() );
518 600
519 switch ( type() ) 601 switch ( type() )
520 { 602 {
521 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; 603 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
522 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; 604 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
523 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; 605 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break;
524 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); 606 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() );
525 } 607 }
526} 608}
527 609
528OWaveLanPacket::~OWaveLanPacket() 610OWaveLanPacket::~OWaveLanPacket()
529{ 611{
530} 612}
531 613
532 614
533int OWaveLanPacket::duration() const 615int OWaveLanPacket::duration() const
534{ 616{
535 return _wlanhdr->duration; 617 return _wlanhdr->duration;
536} 618}
537 619
538 620
539OMacAddress OWaveLanPacket::macAddress1() const 621OMacAddress OWaveLanPacket::macAddress1() const
540{ 622{
541 return OMacAddress( _wlanhdr->mac1 ); 623 return OMacAddress( _wlanhdr->mac1 );
542} 624}
543 625
544 626
545OMacAddress OWaveLanPacket::macAddress2() const 627OMacAddress OWaveLanPacket::macAddress2() const
546{ 628{
547 return OMacAddress( _wlanhdr->mac2 ); 629 return OMacAddress( _wlanhdr->mac2 );
548} 630}
549 631
550 632
551OMacAddress OWaveLanPacket::macAddress3() const 633OMacAddress OWaveLanPacket::macAddress3() const
552{ 634{
553 return OMacAddress( _wlanhdr->mac3 ); 635 return OMacAddress( _wlanhdr->mac3 );
554} 636}
555 637
556 638
557OMacAddress OWaveLanPacket::macAddress4() const 639OMacAddress OWaveLanPacket::macAddress4() const
558{ 640{
559 return OMacAddress( _wlanhdr->mac4 ); 641 return OMacAddress( _wlanhdr->mac4 );
560} 642}
561 643
562 644
563int OWaveLanPacket::subType() const 645int OWaveLanPacket::subType() const
564{ 646{
565 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 647 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
566} 648}
567 649
568 650
569int OWaveLanPacket::type() const 651int OWaveLanPacket::type() const
570{ 652{
571 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 653 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
572} 654}
573 655
574 656
575int OWaveLanPacket::version() const 657int OWaveLanPacket::version() const
576{ 658{
577 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 659 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
578} 660}
579 661
580 662
581bool OWaveLanPacket::fromDS() const 663bool OWaveLanPacket::fromDS() const
582{ 664{
583 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 665 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
584} 666}
585 667
586 668
587bool OWaveLanPacket::toDS() const 669bool OWaveLanPacket::toDS() const
588{ 670{
589 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 671 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
590} 672}
591 673
592 674
593bool OWaveLanPacket::usesPowerManagement() const 675bool OWaveLanPacket::usesPowerManagement() const
594{ 676{
595 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 677 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
596} 678}
597 679
598 680
599bool OWaveLanPacket::usesWep() const 681bool OWaveLanPacket::usesWep() const
600{ 682{
601 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 683 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
602} 684}
603 685
604 686
605/*====================================================================================== 687/*======================================================================================
606 * OWaveLanManagementPacket 688 * OWaveLanManagementPacket
607 *======================================================================================*/ 689 *======================================================================================*/
608 690
609OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 691OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
610 :QObject( parent, "802.11 Management" ), _header( data ), 692 :QObject( parent, "802.11 Management" ), _header( data ),
611 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 693 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
612{ 694{
613 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); 695 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." );
614 qDebug( "Detected subtype is '%s'", (const char*) managementType() ); 696 qDebug( "Detected subtype is '%s'", (const char*) managementType() );
615 697
616 // grab tagged values 698 // grab tagged values
617 const unsigned char* ptr = (const unsigned char*) (_body+1); 699 const unsigned char* ptr = (const unsigned char*) (_body+1);
618 while (ptr < end) 700 while (ptr < end)
619 { 701 {
620 switch ( *ptr ) 702 switch ( *ptr )
621 { 703 {
622 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; 704 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
623 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; 705 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
624 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; 706 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
625 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; 707 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
626 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; 708 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
627 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; 709 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
628 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; 710 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
629 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; 711 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
630 } 712 }
631 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value 713 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
632 ptr+= 2; // skip tag ID and length 714 ptr+= 2; // skip tag ID and length
633 } 715 }
634} 716}
635 717
636 718
637OWaveLanManagementPacket::~OWaveLanManagementPacket() 719OWaveLanManagementPacket::~OWaveLanManagementPacket()
638{ 720{
639} 721}
640 722
641 723
642QString OWaveLanManagementPacket::managementType() const 724QString OWaveLanManagementPacket::managementType() const
643{ 725{
644 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) 726 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
645 { 727 {
646 case ST_ASSOC_REQUEST: return "AssociationRequest"; break; 728 case ST_ASSOC_REQUEST: return "AssociationRequest"; break;
647 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; 729 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break;
648 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; 730 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break;
649 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; 731 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break;
650 case ST_PROBE_REQUEST: return "ProbeRequest"; break; 732 case ST_PROBE_REQUEST: return "ProbeRequest"; break;
651 case ST_PROBE_RESPONSE: return "ProbeResponse"; break; 733 case ST_PROBE_RESPONSE: return "ProbeResponse"; break;
652 case ST_BEACON: return "Beacon"; break; 734 case ST_BEACON: return "Beacon"; break;
653 case ST_ATIM: return "Atim"; break; 735 case ST_ATIM: return "Atim"; break;
654 case ST_DISASSOC: return "Disassociation"; break; 736 case ST_DISASSOC: return "Disassociation"; break;
655 case ST_AUTH: return "Authentication"; break; 737 case ST_AUTH: return "Authentication"; break;
656 case ST_DEAUTH: return "Deathentication"; break; 738 case ST_DEAUTH: return "Deathentication"; break;
657 default: 739 default:
658 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); 740 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) );
659 return "Unknown"; 741 return "Unknown";
660 } 742 }
661} 743}
662 744
663 745
664int OWaveLanManagementPacket::beaconInterval() const 746int OWaveLanManagementPacket::beaconInterval() const
665{ 747{
666 return EXTRACT_LE_16BITS( &_body->beacon_interval ); 748 return EXTRACT_LE_16BITS( &_body->beacon_interval );
667} 749}
668 750
669 751
670int OWaveLanManagementPacket::capabilities() const 752int OWaveLanManagementPacket::capabilities() const
671{ 753{
672 return EXTRACT_LE_16BITS( &_body->capability_info ); 754 return EXTRACT_LE_16BITS( &_body->capability_info );
673} 755}
674 756
675 757
676bool OWaveLanManagementPacket::canESS() const 758bool OWaveLanManagementPacket::canESS() const
677{ 759{
678 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 760 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
679} 761}
680 762
681 763
682bool OWaveLanManagementPacket::canIBSS() const 764bool OWaveLanManagementPacket::canIBSS() const
683{ 765{
684 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 766 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
685} 767}
686 768
687 769
688bool OWaveLanManagementPacket::canCFP() const 770bool OWaveLanManagementPacket::canCFP() const
689{ 771{
690 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); 772 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) );
691} 773}
692 774
693 775
694bool OWaveLanManagementPacket::canCFP_REQ() const 776bool OWaveLanManagementPacket::canCFP_REQ() const
695{ 777{
696 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); 778 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) );
697} 779}
698 780
699 781
700bool OWaveLanManagementPacket::canPrivacy() const 782bool OWaveLanManagementPacket::canPrivacy() const
701{ 783{
702 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); 784 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) );
703} 785}
704 786
705 787
706/*====================================================================================== 788/*======================================================================================
707 * OWaveLanManagementSSID 789 * OWaveLanManagementSSID
708 *======================================================================================*/ 790 *======================================================================================*/
709 791
710OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) 792OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
711 :QObject( parent, "802.11 SSID" ), _data( data ) 793 :QObject( parent, "802.11 SSID" ), _data( data )
712{ 794{
713 qDebug( "OWaveLanManagementSSID()" ); 795 qDebug( "OWaveLanManagementSSID()" );
714} 796}
715 797
716 798
717OWaveLanManagementSSID::~OWaveLanManagementSSID() 799OWaveLanManagementSSID::~OWaveLanManagementSSID()
718{ 800{
719} 801}
720 802
721 803
722QString OWaveLanManagementSSID::ID() const 804QString OWaveLanManagementSSID::ID() const
723{ 805{
724 int length = _data->length; 806 int length = _data->length;
725 if ( length > 32 ) length = 32; 807 if ( length > 32 ) length = 32;
726 char essid[length+1]; 808 char essid[length+1];
727 memcpy( &essid, &_data->ssid, length ); 809 memcpy( &essid, &_data->ssid, length );
728 essid[length] = 0x0; 810 essid[length] = 0x0;
729 return essid; 811 return essid;
730} 812}
731 813
732 814
733/*====================================================================================== 815/*======================================================================================
734 * OWaveLanManagementRates 816 * OWaveLanManagementRates
735 *======================================================================================*/ 817 *======================================================================================*/
736 818
737OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) 819OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
738 :QObject( parent, "802.11 Rates" ), _data( data ) 820 :QObject( parent, "802.11 Rates" ), _data( data )
739{ 821{
740 qDebug( "OWaveLanManagementRates()" ); 822 qDebug( "OWaveLanManagementRates()" );
741} 823}
742 824
743 825
744OWaveLanManagementRates::~OWaveLanManagementRates() 826OWaveLanManagementRates::~OWaveLanManagementRates()
745{ 827{
746} 828}
747 829
748/*====================================================================================== 830/*======================================================================================
749 * OWaveLanManagementCF 831 * OWaveLanManagementCF
750 *======================================================================================*/ 832 *======================================================================================*/
751 833
752OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) 834OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
753 :QObject( parent, "802.11 CF" ), _data( data ) 835 :QObject( parent, "802.11 CF" ), _data( data )
754{ 836{
755 qDebug( "OWaveLanManagementCF()" ); 837 qDebug( "OWaveLanManagementCF()" );
756} 838}
757 839
758 840
759OWaveLanManagementCF::~OWaveLanManagementCF() 841OWaveLanManagementCF::~OWaveLanManagementCF()
760{ 842{
761} 843}
762 844
763/*====================================================================================== 845/*======================================================================================
764 * OWaveLanManagementFH 846 * OWaveLanManagementFH
765 *======================================================================================*/ 847 *======================================================================================*/
766 848
767OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) 849OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
768 :QObject( parent, "802.11 FH" ), _data( data ) 850 :QObject( parent, "802.11 FH" ), _data( data )
769{ 851{
770 qDebug( "OWaveLanManagementFH()" ); 852 qDebug( "OWaveLanManagementFH()" );
771} 853}
772 854
773 855
774OWaveLanManagementFH::~OWaveLanManagementFH() 856OWaveLanManagementFH::~OWaveLanManagementFH()
775{ 857{
776} 858}
777 859
778/*====================================================================================== 860/*======================================================================================
779 * OWaveLanManagementDS 861 * OWaveLanManagementDS
780 *======================================================================================*/ 862 *======================================================================================*/
781 863
782OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) 864OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
783 :QObject( parent, "802.11 DS" ), _data( data ) 865 :QObject( parent, "802.11 DS" ), _data( data )
784{ 866{
785 qDebug( "OWaveLanManagementDS()" ); 867 qDebug( "OWaveLanManagementDS()" );
786} 868}
787 869
788 870
789OWaveLanManagementDS::~OWaveLanManagementDS() 871OWaveLanManagementDS::~OWaveLanManagementDS()
790{ 872{
791} 873}
792 874
793 875
794int OWaveLanManagementDS::channel() const 876int OWaveLanManagementDS::channel() const
795{ 877{
796 return _data->channel; 878 return _data->channel;
797} 879}
798 880
799/*====================================================================================== 881/*======================================================================================
800 * OWaveLanManagementTim 882 * OWaveLanManagementTim
801 *======================================================================================*/ 883 *======================================================================================*/
802 884
803OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) 885OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
804 :QObject( parent, "802.11 Tim" ), _data( data ) 886 :QObject( parent, "802.11 Tim" ), _data( data )
805{ 887{
806 qDebug( "OWaveLanManagementTim()" ); 888 qDebug( "OWaveLanManagementTim()" );
807} 889}
808 890
809 891
810OWaveLanManagementTim::~OWaveLanManagementTim() 892OWaveLanManagementTim::~OWaveLanManagementTim()
811{ 893{
812} 894}
813 895
814/*====================================================================================== 896/*======================================================================================
815 * OWaveLanManagementIBSS 897 * OWaveLanManagementIBSS
816 *======================================================================================*/ 898 *======================================================================================*/
817 899
818OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) 900OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
819 :QObject( parent, "802.11 IBSS" ), _data( data ) 901 :QObject( parent, "802.11 IBSS" ), _data( data )
820{ 902{
821 qDebug( "OWaveLanManagementIBSS()" ); 903 qDebug( "OWaveLanManagementIBSS()" );
822} 904}
823 905
824 906
825OWaveLanManagementIBSS::~OWaveLanManagementIBSS() 907OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
826{ 908{
827} 909}
828 910
829/*====================================================================================== 911/*======================================================================================
830 * OWaveLanManagementChallenge 912 * OWaveLanManagementChallenge
831 *======================================================================================*/ 913 *======================================================================================*/
832 914
833OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) 915OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
834 :QObject( parent, "802.11 Challenge" ), _data( data ) 916 :QObject( parent, "802.11 Challenge" ), _data( data )
835{ 917{
836 qDebug( "OWaveLanManagementChallenge()" ); 918 qDebug( "OWaveLanManagementChallenge()" );
837} 919}
838 920
839 921
840OWaveLanManagementChallenge::~OWaveLanManagementChallenge() 922OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
841{ 923{
842} 924}
843 925
844/*====================================================================================== 926/*======================================================================================
845 * OWaveLanDataPacket 927 * OWaveLanDataPacket
846 *======================================================================================*/ 928 *======================================================================================*/
847 929
848OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 930OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
849 :QObject( parent, "802.11 Data" ), _header( data ) 931 :QObject( parent, "802.11 Data" ), _header( data )
850{ 932{
851 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); 933 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." );
852 934
853 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 935 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
854 936
855 #warning The next line works for most cases, but can not be correct generally! 937 #warning The next line works for most cases, but can not be correct generally!
856 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 938 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
857 939
858 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); 940 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
859} 941}
860 942
861 943
862OWaveLanDataPacket::~OWaveLanDataPacket() 944OWaveLanDataPacket::~OWaveLanDataPacket()
863{ 945{
864} 946}
865 947
866 948
867/*====================================================================================== 949/*======================================================================================
868 * OLLCPacket 950 * OLLCPacket
869 *======================================================================================*/ 951 *======================================================================================*/
870 952
871OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 953OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
872 :QObject( parent, "802.11 LLC" ), _header( data ) 954 :QObject( parent, "802.11 LLC" ), _header( data )
873{ 955{
874 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 956 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
875 957
876 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 958 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
877 { 959 {
878 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 960 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
879 961
880 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 962 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
881 { 963 {
882 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 964 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
883 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; 965 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
884 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 966 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) );
885 } 967 }
886 968
887 } 969 }
888} 970}
889 971
890 972
891OLLCPacket::~OLLCPacket() 973OLLCPacket::~OLLCPacket()
892{ 974{
893} 975}
894 976
895 977
896/*====================================================================================== 978/*======================================================================================
897 * OWaveLanControlPacket 979 * OWaveLanControlPacket
898 *======================================================================================*/ 980 *======================================================================================*/
899 981
900OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) 982OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
901 :QObject( parent, "802.11 Control" ), _header( data ) 983 :QObject( parent, "802.11 Control" ), _header( data )
902{ 984{
903 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); 985 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
904 //TODO: Implement this 986 //TODO: Implement this
905} 987}
906 988
907 989
908OWaveLanControlPacket::~OWaveLanControlPacket() 990OWaveLanControlPacket::~OWaveLanControlPacket()
909{ 991{
910} 992}
911 993
912 994
913/*====================================================================================== 995/*======================================================================================
914 * OPacketCapturer 996 * OPacketCapturer
915 *======================================================================================*/ 997 *======================================================================================*/
916 998
917OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 999OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
918 :QObject( parent, name ), _name( QString::null ), _open( false ), 1000 :QObject( parent, name ), _name( QString::null ), _open( false ),
919 _pch( 0 ), _pcd( 0 ), _sn( 0 ) 1001 _pch( 0 ), _pcd( 0 ), _sn( 0 )
920{ 1002{
921} 1003}
922 1004
923 1005
924OPacketCapturer::~OPacketCapturer() 1006OPacketCapturer::~OPacketCapturer()
925{ 1007{
926 if ( _open ) 1008 if ( _open )
927 { 1009 {
928 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 1010 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
929 close(); 1011 close();
930 } 1012 }
931} 1013}
932 1014
933 1015
934void OPacketCapturer::setBlocking( bool b ) 1016void OPacketCapturer::setBlocking( bool b )
935{ 1017{
936 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 1018 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
937 { 1019 {
938 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 1020 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
939 } 1021 }
940 else 1022 else
941 { 1023 {
942 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 1024 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
943 } 1025 }
944} 1026}
945 1027
946 1028
947bool OPacketCapturer::blocking() const 1029bool OPacketCapturer::blocking() const
948{ 1030{
949 int b = pcap_getnonblock( _pch, _errbuf ); 1031 int b = pcap_getnonblock( _pch, _errbuf );
950 if ( b == -1 ) 1032 if ( b == -1 )
951 { 1033 {
952 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 1034 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
953 return -1; 1035 return -1;
954 } 1036 }
955 return !b; 1037 return !b;
956} 1038}
957 1039
958 1040
959void OPacketCapturer::closeDumpFile() 1041void OPacketCapturer::closeDumpFile()
960{ 1042{
961 if ( _pcd ) 1043 if ( _pcd )
962 { 1044 {
963 pcap_dump_close( _pcd ); 1045 pcap_dump_close( _pcd );
964 _pcd = 0; 1046 _pcd = 0;
965 } 1047 }
966 pcap_close( _pch ); 1048 pcap_close( _pch );
967} 1049}
968 1050
969 1051
970void OPacketCapturer::close() 1052void OPacketCapturer::close()
971{ 1053{
972 if ( _open ) 1054 if ( _open )
973 { 1055 {
974 if ( _sn ) 1056 if ( _sn )
975 { 1057 {
976 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1058 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
977 delete _sn; 1059 delete _sn;
978 } 1060 }
979 closeDumpFile(); 1061 closeDumpFile();
980 _open = false; 1062 _open = false;
981 } 1063 }
982 1064
983 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 1065 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
984 qDebug( "--------------------------------------------------" ); 1066 qDebug( "--------------------------------------------------" );
985 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 1067 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
986 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 1068 qDebug( "%s : %d", (const char*) it.key(), it.data() );
987 qDebug( "--------------------------------------------------" ); 1069 qDebug( "--------------------------------------------------" );
988 1070
989} 1071}
990 1072
991 1073
992int OPacketCapturer::dataLink() const 1074int OPacketCapturer::dataLink() const
993{ 1075{
994 return pcap_datalink( _pch ); 1076 return pcap_datalink( _pch );
995} 1077}
996 1078
997 1079
998void OPacketCapturer::dump( OPacket* p ) 1080void OPacketCapturer::dump( OPacket* p )
999{ 1081{
1000 if ( !_pcd ) 1082 if ( !_pcd )
1001 { 1083 {
1002 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" ); 1084 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" );
1003 return; 1085 return;
1004 } 1086 }
1005 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); 1087 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data );
1006} 1088}
1007 1089
1008 1090
1009int OPacketCapturer::fileno() const 1091int OPacketCapturer::fileno() const
1010{ 1092{
1011 if ( _open ) 1093 if ( _open )
1012 { 1094 {
1013 return pcap_fileno( _pch ); 1095 return pcap_fileno( _pch );
1014 } 1096 }
1015 else 1097 else
1016 { 1098 {
1017 return -1; 1099 return -1;
1018 } 1100 }
1019} 1101}
1020 1102
1021OPacket* OPacketCapturer::next() 1103OPacket* OPacketCapturer::next()
1022{ 1104{
1023 packetheaderstruct header; 1105 packetheaderstruct header;
1024 qDebug( "==> OPacketCapturer::next()" ); 1106 qDebug( "==> OPacketCapturer::next()" );
1025 const unsigned char* pdata = pcap_next( _pch, &header ); 1107 const unsigned char* pdata = pcap_next( _pch, &header );
1026 qDebug( "<== OPacketCapturer::next()" ); 1108 qDebug( "<== OPacketCapturer::next()" );
1027 1109
1028 if ( pdata && header.len ) 1110 if ( pdata && header.len )
1029 { 1111 {
1030 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 1112 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
1031 // packets shouldn't be inserted in the QObject child-parent hierarchy, 1113 // packets shouldn't be inserted in the QObject child-parent hierarchy,
1032 // because due to memory constraints they will be deleted as soon 1114 // because due to memory constraints they will be deleted as soon
1033 // as possible - that is right after they have been processed 1115 // as possible - that is right after they have been processed
1034 // by emit() [ see below ] 1116 // by emit() [ see below ]
1035 //TODO: make gathering statistics optional, because it takes time 1117 //TODO: make gathering statistics optional, because it takes time
1036 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 1118 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
1037 1119
1038 return p; 1120 return p;
1039 } 1121 }
1040 else 1122 else
1041 { 1123 {
1042 qWarning( "OPacketCapturer::next() - no packet received!" ); 1124 qWarning( "OPacketCapturer::next() - no packet received!" );
1043 return 0; 1125 return 0;
1044 } 1126 }
1045} 1127}
1046 1128
1047 1129
1048bool OPacketCapturer::open( const QString& name ) 1130bool OPacketCapturer::open( const QString& name )
1049{ 1131{
1050 if ( _open ) 1132 if ( _open )
1051 { 1133 {
1052 if ( name == _name ) // ignore opening an already openend device 1134 if ( name == _name ) // ignore opening an already openend device
1053 { 1135 {
1054 return true; 1136 return true;
1055 } 1137 }
1056 else // close the last opened device 1138 else // close the last opened device
1057 { 1139 {
1058 close(); 1140 close();
1059 } 1141 }
1060 } 1142 }
1061 1143
1062 _name = name; 1144 _name = name;
1063 1145
1064 // open libpcap 1146 // open libpcap
1065 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 1147 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
1066 1148
1067 if ( !handle ) 1149 if ( !handle )
1068 { 1150 {
1069 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1151 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1070 return false; 1152 return false;
1071 } 1153 }
1072 1154
1073 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 1155 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
1074 _pch = handle; 1156 _pch = handle;
1075 _open = true; 1157 _open = true;
1076 _stats.clear(); 1158 _stats.clear();
1077 1159
1078 // in case we have an application object, create a socket notifier 1160 // in case we have an application object, create a socket notifier
1079 if ( qApp ) //TODO: I don't like this here... 1161 if ( qApp ) //TODO: I don't like this here...
1080 { 1162 {
1081 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1163 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1082 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1164 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1083 } 1165 }
1084 1166
1085 return true; 1167 return true;
1086} 1168}
1087 1169
1088 1170
1089bool OPacketCapturer::openDumpFile( const QString& filename ) 1171bool OPacketCapturer::openDumpFile( const QString& filename )
1090{ 1172{
1091 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 1173 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
1092 if ( !dump ) 1174 if ( !dump )
1093 { 1175 {
1094 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 1176 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
1095 return false; 1177 return false;
1096 } 1178 }
1097 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); 1179 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
1098 _pcd = dump; 1180 _pcd = dump;
1099 1181
1100 return true; 1182 return true;
1101} 1183}
1102 1184
1103 1185
1104bool OPacketCapturer::open( const QFile& file ) 1186bool OPacketCapturer::open( const QFile& file )
1105{ 1187{
1106 QString name = file.name(); 1188 QString name = file.name();
1107 1189
1108 if ( _open ) 1190 if ( _open )
1109 { 1191 {
1110 close(); 1192 close();
1111 if ( name == _name ) // ignore opening an already openend device 1193 if ( name == _name ) // ignore opening an already openend device
1112 { 1194 {
1113 return true; 1195 return true;
1114 } 1196 }
1115 else // close the last opened device 1197 else // close the last opened device
1116 { 1198 {
1117 close(); 1199 close();
1118 } 1200 }
1119 } 1201 }
1120 1202
1121 _name = name; 1203 _name = name;
1122 1204
1123 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); 1205 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
1124 1206
1125 if ( handle ) 1207 if ( handle )
1126 { 1208 {
1127 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 1209 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
1128 _pch = handle; 1210 _pch = handle;
1129 _open = true; 1211 _open = true;
1130 1212
1131 // in case we have an application object, create a socket notifier 1213 // in case we have an application object, create a socket notifier
1132 if ( qApp ) 1214 if ( qApp )
1133 { 1215 {
1134 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1216 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1135 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1217 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1136 } 1218 }
1137 1219
1138 return true; 1220 return true;
1139 } 1221 }
1140 else 1222 else
1141 { 1223 {
1142 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1224 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1143 return false; 1225 return false;
1144 } 1226 }
1145 1227
1146} 1228}
1147 1229
1148 1230
1149bool OPacketCapturer::isOpen() const 1231bool OPacketCapturer::isOpen() const
1150{ 1232{
1151 return _open; 1233 return _open;
1152} 1234}
1153 1235
1154 1236
1155void OPacketCapturer::readyToReceive() 1237void OPacketCapturer::readyToReceive()
1156{ 1238{
1157 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); 1239 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" );
1158 OPacket* p = next(); 1240 OPacket* p = next();
1159 emit receivedPacket( p ); 1241 emit receivedPacket( p );
1160 // emit is synchronous - packet has been dealt with, now it's safe to delete 1242 // emit is synchronous - packet has been dealt with, now it's safe to delete
1161 delete p; 1243 delete p;
1162} 1244}
1163 1245
1164 1246
1165const QMap<QString,int>& OPacketCapturer::statistics() const 1247const QMap<QString,int>& OPacketCapturer::statistics() const
1166{ 1248{
1167 return _stats; 1249 return _stats;
1168} 1250}
1169 1251
1170 1252
1171int OPacketCapturer::snapShot() const 1253int OPacketCapturer::snapShot() const
1172{ 1254{
1173 return pcap_snapshot( _pch ); 1255 return pcap_snapshot( _pch );
1174} 1256}
1175 1257
1176 1258
1177bool OPacketCapturer::swapped() const 1259bool OPacketCapturer::swapped() const
1178{ 1260{
1179 return pcap_is_swapped( _pch ); 1261 return pcap_is_swapped( _pch );
1180} 1262}
1181 1263
1182 1264
1183QString OPacketCapturer::version() const 1265QString OPacketCapturer::version() const
1184{ 1266{
1185 return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); 1267 return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) );
1186} 1268}
1187 1269
diff --git a/libopie2/opienet/opcap.h b/libopie2/opienet/opcap.h
index 0c9e7da..a031dd1 100644
--- a/libopie2/opienet/opcap.h
+++ b/libopie2/opienet/opcap.h
@@ -1,645 +1,655 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef OPCAP_H 34#ifndef OPCAP_H
35#define OPCAP_H 35#define OPCAP_H
36 36
37/* LINUX */ 37/* LINUX */
38extern "C" // work around a bpf/pcap conflict in recent headers 38extern "C" // work around a bpf/pcap conflict in recent headers
39{ 39{
40 #include <pcap.h> 40 #include <pcap.h>
41} 41}
42#include <netinet/ether.h> 42#include <netinet/ether.h>
43#include <netinet/ip.h> 43#include <netinet/ip.h>
44#include <netinet/udp.h> 44#include <netinet/udp.h>
45#include <netinet/tcp.h> 45#include <netinet/tcp.h>
46#include <time.h> 46#include <time.h>
47 47
48/* QT */ 48/* QT */
49#include <qevent.h> 49#include <qevent.h>
50#include <qfile.h> 50#include <qfile.h>
51#include <qhostaddress.h> 51#include <qhostaddress.h>
52#include <qobject.h> 52#include <qobject.h>
53#include <qstring.h> 53#include <qstring.h>
54#include <qmap.h> 54#include <qmap.h>
55 55
56/* OPIE */ 56/* OPIE */
57#include <opie2/onetutils.h> 57#include <opie2/onetutils.h>
58 58
59/* Custom Network Includes */ 59/* Custom Network Includes */
60#include "802_11_user.h" 60#include "802_11_user.h"
61#include "dhcp.h" 61#include "dhcp.h"
62 62
63/* TYPEDEFS */ 63/* TYPEDEFS */
64typedef struct timeval timevalstruct; 64typedef struct timeval timevalstruct;
65typedef struct pcap_pkthdr packetheaderstruct; 65typedef struct pcap_pkthdr packetheaderstruct;
66 66
67/* FORWARDS */ 67/* FORWARDS */
68class OPacketCapturer; 68class OPacketCapturer;
69class QSocketNotifier; 69class QSocketNotifier;
70 70
71/*====================================================================================== 71/*======================================================================================
72 * OPacket - A frame on the wire 72 * OPacket - A frame on the wire
73 *======================================================================================*/ 73 *======================================================================================*/
74 74
75/** @brief A class representing a data frame on the wire. 75/** @brief A class representing a data frame on the wire.
76 * 76 *
77 * The whole family of the packet classes are used when capturing frames from a network. 77 * The whole family of the packet classes are used when capturing frames from a network.
78 * Most standard network protocols in use share a common architecture, which mostly is 78 * Most standard network protocols in use share a common architecture, which mostly is
79 * a packet header and then the packet payload. In layered architectures, each lower layer 79 * a packet header and then the packet payload. In layered architectures, each lower layer
80 * encapsulates data from its upper layer - that is it 80 * encapsulates data from its upper layer - that is it
81 * treats the data from its upper layer as payload and prepends an own header to the packet, 81 * treats the data from its upper layer as payload and prepends an own header to the packet,
82 * which - again - is treated as the payload for the layer below. The figure below is an 82 * which - again - is treated as the payload for the layer below. The figure below is an
83 * example for how such a data frame is composed out of packets, e.g. when sending a mail. 83 * example for how such a data frame is composed out of packets, e.g. when sending a mail.
84 * 84 *
85 * <pre> 85 * <pre>
86 * | User Data | == Mail Data 86 * | User Data | == Mail Data
87 * | SMTP Header | User Data | == SMTP 87 * | SMTP Header | User Data | == SMTP
88 * | TCP Header | SMTP Header | User Data | == TCP 88 * | TCP Header | SMTP Header | User Data | == TCP
89 * | IP Header | TCP Header | SMTP Header | User Data | == IP 89 * | IP Header | TCP Header | SMTP Header | User Data | == IP
90 * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC 90 * | MAC Header | IP Header | TCP Header | SMTP Header | User Data | == MAC
91 * 91 *
92 * </pre> 92 * </pre>
93 * 93 *
94 * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer 94 * The example is trimmed for simplicity, because the MAC (Medium Access Control) layer
95 * also contains a few more levels of encapsulation. 95 * also contains a few more levels of encapsulation.
96 * Since the type of the payload is more or less independent from the encapsulating protocol, 96 * Since the type of the payload is more or less independent from the encapsulating protocol,
97 * the header must be inspected before attempting to decode the payload. Hence, the 97 * the header must be inspected before attempting to decode the payload. Hence, the
98 * encapsulation level varies and can't be deduced without actually looking into the packets. 98 * encapsulation level varies and can't be deduced without actually looking into the packets.
99 * 99 *
100 * For actually working with captured frames, it's useful to identify the packets via names and 100 * For actually working with captured frames, it's useful to identify the packets via names and
101 * insert them into a parent/child - relationship based on the encapsulation. This is why 101 * insert them into a parent/child - relationship based on the encapsulation. This is why
102 * all packet classes derive from QObject. The amount of overhead caused by the QObject is 102 * all packet classes derive from QObject. The amount of overhead caused by the QObject is
103 * not a problem in this case, because we're talking about a theoratical maximum of about 103 * not a problem in this case, because we're talking about a theoratical maximum of about
104 * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the 104 * 10 packets per captured frame. We need to stuff them into a searchable list anyway and the
105 * QObject also cares about destroying the sub-, (child-) packets. 105 * QObject also cares about destroying the sub-, (child-) packets.
106 * 106 *
107 * This enables us to perform a simple look for packets of a certain type: 107 * This enables us to perform a simple look for packets of a certain type:
108 * @code 108 * @code
109 * OPacketCapturer* pcap = new OPacketCapturer(); 109 * OPacketCapturer* pcap = new OPacketCapturer();
110 * pcap->open( "eth0" ); 110 * pcap->open( "eth0" );
111 * OPacket* p = pcap->next(); 111 * OPacket* p = pcap->next();
112 * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists 112 * OIPPacket* ip = (OIPPacket*) p->child( "IP" ); // returns 0, if no such child exists
113 * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl; 113 * odebug << "got ip packet from " << ip->fromIPAddress().toString() << " to " << ip->toIPAddress().toString() << oendl;
114 * 114 *
115 */ 115 */
116 116
117class OPacket : public QObject 117class OPacket : public QObject
118{ 118{
119 Q_OBJECT 119 Q_OBJECT
120 120
121 friend class OPacketCapturer; 121 friend class OPacketCapturer;
122 122
123 public: 123 public:
124 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent ); 124 OPacket( int datalink, packetheaderstruct, const unsigned char*, QObject* parent );
125 virtual ~OPacket(); 125 virtual ~OPacket();
126 126
127 timevalstruct timeval() const; 127 timevalstruct timeval() const;
128 128
129 int caplen() const; 129 int caplen() const;
130 int len() const; 130 int len() const;
131 QString dump( int = 32 ) const; 131 QString dump( int = 32 ) const;
132 132
133 void updateStats( QMap<QString,int>&, QObjectList* ); 133 void updateStats( QMap<QString,int>&, QObjectList* );
134 134
135 private: 135 private:
136 const packetheaderstruct _hdr; // pcap packet header 136 const packetheaderstruct _hdr; // pcap packet header
137 const unsigned char* _data; // pcap packet data 137 const unsigned char* _data; // pcap packet data
138 const unsigned char* _end; // end of pcap packet data 138 const unsigned char* _end; // end of pcap packet data
139}; 139};
140 140
141/*====================================================================================== 141/*======================================================================================
142 * OEthernetPacket - DLT_EN10MB frame 142 * OEthernetPacket - DLT_EN10MB frame
143 *======================================================================================*/ 143 *======================================================================================*/
144 144
145class OEthernetPacket : public QObject 145class OEthernetPacket : public QObject
146{ 146{
147 Q_OBJECT 147 Q_OBJECT
148 148
149 public: 149 public:
150 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 ); 150 OEthernetPacket( const unsigned char*, const struct ether_header*, QObject* parent = 0 );
151 virtual ~OEthernetPacket(); 151 virtual ~OEthernetPacket();
152 152
153 OMacAddress sourceAddress() const; 153 OMacAddress sourceAddress() const;
154 OMacAddress destinationAddress() const; 154 OMacAddress destinationAddress() const;
155 int type() const; 155 int type() const;
156 156
157 private: 157 private:
158 const struct ether_header* _ether; 158 const struct ether_header* _ether;
159}; 159};
160 160
161/*====================================================================================== 161/*======================================================================================
162 * OPrismHeaderPacket - DLT_PRISM_HEADER frame 162 * OPrismHeaderPacket - DLT_PRISM_HEADER frame
163 *======================================================================================*/ 163 *======================================================================================*/
164 164
165class OPrismHeaderPacket : public QObject 165class OPrismHeaderPacket : public QObject
166{ 166{
167 Q_OBJECT 167 Q_OBJECT
168 168
169 public: 169 public:
170 OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 ); 170 OPrismHeaderPacket( const unsigned char*, const struct prism_hdr*, QObject* parent = 0 );
171 virtual ~OPrismHeaderPacket(); 171 virtual ~OPrismHeaderPacket();
172 172
173 unsigned int signalStrength() const; 173 unsigned int signalStrength() const;
174 174
175 private: 175 private:
176 const struct prism_hdr* _header; 176 const struct prism_hdr* _header;
177}; 177};
178 178
179/*====================================================================================== 179/*======================================================================================
180 * OWaveLanPacket - DLT_IEEE802_11 frame 180 * OWaveLanPacket - DLT_IEEE802_11 frame
181 *======================================================================================*/ 181 *======================================================================================*/
182 182
183class OWaveLanPacket : public QObject 183class OWaveLanPacket : public QObject
184{ 184{
185 Q_OBJECT 185 Q_OBJECT
186 186
187 public: 187 public:
188 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 ); 188 OWaveLanPacket( const unsigned char*, const struct ieee_802_11_header*, QObject* parent = 0 );
189 virtual ~OWaveLanPacket(); 189 virtual ~OWaveLanPacket();
190 190
191 int duration() const; 191 int duration() const;
192 bool fromDS() const; 192 bool fromDS() const;
193 bool toDS() const; 193 bool toDS() const;
194 virtual OMacAddress macAddress1() const; 194 virtual OMacAddress macAddress1() const;
195 virtual OMacAddress macAddress2() const; 195 virtual OMacAddress macAddress2() const;
196 virtual OMacAddress macAddress3() const; 196 virtual OMacAddress macAddress3() const;
197 virtual OMacAddress macAddress4() const; 197 virtual OMacAddress macAddress4() const;
198 bool usesPowerManagement() const; 198 bool usesPowerManagement() const;
199 int type() const; 199 int type() const;
200 int subType() const; 200 int subType() const;
201 int version() const; 201 int version() const;
202 bool usesWep() const; 202 bool usesWep() const;
203 203
204 private: 204 private:
205 const struct ieee_802_11_header* _wlanhdr; 205 const struct ieee_802_11_header* _wlanhdr;
206}; 206};
207 207
208 208
209/*====================================================================================== 209/*======================================================================================
210 * OWaveLanManagementPacket - type: management (T_MGMT) 210 * OWaveLanManagementPacket - type: management (T_MGMT)
211 *======================================================================================*/ 211 *======================================================================================*/
212 212
213class OWaveLanManagementPacket : public QObject 213class OWaveLanManagementPacket : public QObject
214{ 214{
215 Q_OBJECT 215 Q_OBJECT
216 216
217 public: 217 public:
218 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 ); 218 OWaveLanManagementPacket( const unsigned char*, const struct ieee_802_11_mgmt_header*, OWaveLanPacket* parent = 0 );
219 virtual ~OWaveLanManagementPacket(); 219 virtual ~OWaveLanManagementPacket();
220 220
221 QString managementType() const; 221 QString managementType() const;
222 222
223 int beaconInterval() const; 223 int beaconInterval() const;
224 int capabilities() const; // generic 224 int capabilities() const; // generic
225 225
226 bool canESS() const; 226 bool canESS() const;
227 bool canIBSS() const; 227 bool canIBSS() const;
228 bool canCFP() const; 228 bool canCFP() const;
229 bool canCFP_REQ() const; 229 bool canCFP_REQ() const;
230 bool canPrivacy() const; 230 bool canPrivacy() const;
231 231
232 private: 232 private:
233 const struct ieee_802_11_mgmt_header* _header; 233 const struct ieee_802_11_mgmt_header* _header;
234 const struct ieee_802_11_mgmt_body* _body; 234 const struct ieee_802_11_mgmt_body* _body;
235}; 235};
236 236
237 237
238/*====================================================================================== 238/*======================================================================================
239 * OWaveLanManagementSSID 239 * OWaveLanManagementSSID
240 *======================================================================================*/ 240 *======================================================================================*/
241 241
242class OWaveLanManagementSSID : public QObject 242class OWaveLanManagementSSID : public QObject
243{ 243{
244 Q_OBJECT 244 Q_OBJECT
245 245
246 public: 246 public:
247 OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 ); 247 OWaveLanManagementSSID( const unsigned char*, const struct ssid_t*, QObject* parent = 0 );
248 virtual ~OWaveLanManagementSSID(); 248 virtual ~OWaveLanManagementSSID();
249 249
250 QString ID() const; 250 QString ID() const;
251 251
252 private: 252 private:
253 const struct ssid_t* _data; 253 const struct ssid_t* _data;
254}; 254};
255 255
256/*====================================================================================== 256/*======================================================================================
257 * OWaveLanManagementRates 257 * OWaveLanManagementRates
258 *======================================================================================*/ 258 *======================================================================================*/
259 259
260class OWaveLanManagementRates : public QObject 260class OWaveLanManagementRates : public QObject
261{ 261{
262 Q_OBJECT 262 Q_OBJECT
263 263
264 public: 264 public:
265 OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 ); 265 OWaveLanManagementRates( const unsigned char*, const struct rates_t*, QObject* parent = 0 );
266 virtual ~OWaveLanManagementRates(); 266 virtual ~OWaveLanManagementRates();
267 267
268 private: 268 private:
269 const struct rates_t* _data; 269 const struct rates_t* _data;
270}; 270};
271 271
272/*====================================================================================== 272/*======================================================================================
273 * OWaveLanManagementCF 273 * OWaveLanManagementCF
274 *======================================================================================*/ 274 *======================================================================================*/
275 275
276class OWaveLanManagementCF : public QObject 276class OWaveLanManagementCF : public QObject
277{ 277{
278 Q_OBJECT 278 Q_OBJECT
279 279
280 public: 280 public:
281 OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 ); 281 OWaveLanManagementCF( const unsigned char*, const struct cf_t*, QObject* parent = 0 );
282 virtual ~OWaveLanManagementCF(); 282 virtual ~OWaveLanManagementCF();
283 283
284 private: 284 private:
285 const struct cf_t* _data; 285 const struct cf_t* _data;
286}; 286};
287 287
288/*====================================================================================== 288/*======================================================================================
289 * OWaveLanManagementFH 289 * OWaveLanManagementFH
290 *======================================================================================*/ 290 *======================================================================================*/
291 291
292class OWaveLanManagementFH : public QObject 292class OWaveLanManagementFH : public QObject
293{ 293{
294 Q_OBJECT 294 Q_OBJECT
295 295
296 public: 296 public:
297 OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 ); 297 OWaveLanManagementFH( const unsigned char*, const struct fh_t*, QObject* parent = 0 );
298 virtual ~OWaveLanManagementFH(); 298 virtual ~OWaveLanManagementFH();
299 299
300 private: 300 private:
301 const struct fh_t* _data; 301 const struct fh_t* _data;
302}; 302};
303 303
304/*====================================================================================== 304/*======================================================================================
305 * OWaveLanManagementDS 305 * OWaveLanManagementDS
306 *======================================================================================*/ 306 *======================================================================================*/
307 307
308class OWaveLanManagementDS : public QObject 308class OWaveLanManagementDS : public QObject
309{ 309{
310 Q_OBJECT 310 Q_OBJECT
311 311
312 public: 312 public:
313 OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 ); 313 OWaveLanManagementDS( const unsigned char*, const struct ds_t*, QObject* parent = 0 );
314 virtual ~OWaveLanManagementDS(); 314 virtual ~OWaveLanManagementDS();
315 315
316 int channel() const; 316 int channel() const;
317 317
318 private: 318 private:
319 const struct ds_t* _data; 319 const struct ds_t* _data;
320}; 320};
321 321
322/*====================================================================================== 322/*======================================================================================
323 * OWaveLanManagementTim 323 * OWaveLanManagementTim
324 *======================================================================================*/ 324 *======================================================================================*/
325 325
326class OWaveLanManagementTim : public QObject 326class OWaveLanManagementTim : public QObject
327{ 327{
328 Q_OBJECT 328 Q_OBJECT
329 329
330 public: 330 public:
331 OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 ); 331 OWaveLanManagementTim( const unsigned char*, const struct tim_t*, QObject* parent = 0 );
332 virtual ~OWaveLanManagementTim(); 332 virtual ~OWaveLanManagementTim();
333 333
334 private: 334 private:
335 const struct tim_t* _data; 335 const struct tim_t* _data;
336}; 336};
337 337
338/*====================================================================================== 338/*======================================================================================
339 * OWaveLanManagementIBSS 339 * OWaveLanManagementIBSS
340 *======================================================================================*/ 340 *======================================================================================*/
341 341
342class OWaveLanManagementIBSS : public QObject 342class OWaveLanManagementIBSS : public QObject
343{ 343{
344 Q_OBJECT 344 Q_OBJECT
345 345
346 public: 346 public:
347 OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 ); 347 OWaveLanManagementIBSS( const unsigned char*, const struct ibss_t*, QObject* parent = 0 );
348 virtual ~OWaveLanManagementIBSS(); 348 virtual ~OWaveLanManagementIBSS();
349 349
350 private: 350 private:
351 const struct ibss_t* _data; 351 const struct ibss_t* _data;
352}; 352};
353 353
354/*====================================================================================== 354/*======================================================================================
355 * OWaveLanManagementChallenge 355 * OWaveLanManagementChallenge
356 *======================================================================================*/ 356 *======================================================================================*/
357 357
358class OWaveLanManagementChallenge : public QObject 358class OWaveLanManagementChallenge : public QObject
359{ 359{
360 Q_OBJECT 360 Q_OBJECT
361 361
362 public: 362 public:
363 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 ); 363 OWaveLanManagementChallenge( const unsigned char*, const struct challenge_t*, QObject* parent = 0 );
364 virtual ~OWaveLanManagementChallenge(); 364 virtual ~OWaveLanManagementChallenge();
365 365
366 private: 366 private:
367 const struct challenge_t* _data; 367 const struct challenge_t* _data;
368}; 368};
369 369
370/*====================================================================================== 370/*======================================================================================
371 * OWaveLanDataPacket - type: data (T_DATA) 371 * OWaveLanDataPacket - type: data (T_DATA)
372 *======================================================================================*/ 372 *======================================================================================*/
373 373
374class OWaveLanDataPacket : public QObject 374class OWaveLanDataPacket : public QObject
375{ 375{
376 Q_OBJECT 376 Q_OBJECT
377 377
378 public: 378 public:
379 OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 ); 379 OWaveLanDataPacket( const unsigned char*, const struct ieee_802_11_data_header*, OWaveLanPacket* parent = 0 );
380 virtual ~OWaveLanDataPacket(); 380 virtual ~OWaveLanDataPacket();
381 381
382 private: 382 private:
383 const struct ieee_802_11_data_header* _header; 383 const struct ieee_802_11_data_header* _header;
384}; 384};
385 385
386/*====================================================================================== 386/*======================================================================================
387 * OWaveLanControlPacket - type: control (T_CTRL) 387 * OWaveLanControlPacket - type: control (T_CTRL)
388 *======================================================================================*/ 388 *======================================================================================*/
389 389
390class OWaveLanControlPacket : public QObject 390class OWaveLanControlPacket : public QObject
391{ 391{
392 Q_OBJECT 392 Q_OBJECT
393 393
394 public: 394 public:
395 OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 ); 395 OWaveLanControlPacket( const unsigned char*, const struct ieee_802_11_control_header*, OWaveLanPacket* parent = 0 );
396 virtual ~OWaveLanControlPacket(); 396 virtual ~OWaveLanControlPacket();
397 397
398 private: 398 private:
399 const struct ieee_802_11_control_header* _header; 399 const struct ieee_802_11_control_header* _header;
400}; 400};
401 401
402/*====================================================================================== 402/*======================================================================================
403 * OLLCPacket - IEEE 802.2 Link Level Control 403 * OLLCPacket - IEEE 802.2 Link Level Control
404 *======================================================================================*/ 404 *======================================================================================*/
405 405
406class OLLCPacket : public QObject 406class OLLCPacket : public QObject
407{ 407{
408 Q_OBJECT 408 Q_OBJECT
409 409
410 public: 410 public:
411 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 ); 411 OLLCPacket( const unsigned char*, const struct ieee_802_11_802_2_header* data, QObject* parent = 0 );
412 virtual ~OLLCPacket(); 412 virtual ~OLLCPacket();
413 413
414 private: 414 private:
415 const struct ieee_802_11_802_2_header* _header; 415 const struct ieee_802_11_802_2_header* _header;
416}; 416};
417 417
418/*====================================================================================== 418/*======================================================================================
419 * OIPPacket 419 * OIPPacket
420 *======================================================================================*/ 420 *======================================================================================*/
421 421
422class OIPPacket : public QObject 422class OIPPacket : public QObject
423{ 423{
424 Q_OBJECT 424 Q_OBJECT
425 425
426 public: 426 public:
427 OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 ); 427 OIPPacket( const unsigned char*, const struct iphdr*, QObject* parent = 0 );
428 virtual ~OIPPacket(); 428 virtual ~OIPPacket();
429 429
430 QHostAddress fromIPAddress() const; 430 QHostAddress fromIPAddress() const;
431 QHostAddress toIPAddress() const; 431 QHostAddress toIPAddress() const;
432 432
433 int tos() const; 433 int tos() const;
434 int len() const; 434 int len() const;
435 int id() const; 435 int id() const;
436 int offset() const; 436 int offset() const;
437 int ttl() const; 437 int ttl() const;
438 int protocol() const; 438 int protocol() const;
439 int checksum() const; 439 int checksum() const;
440 440
441 private: 441 private:
442 const struct iphdr* _iphdr; 442 const struct iphdr* _iphdr;
443}; 443};
444 444
445/*====================================================================================== 445/*======================================================================================
446 * OARPPacket 446 * OARPPacket
447 *======================================================================================*/ 447 *======================================================================================*/
448 448
449class OARPPacket : public QObject 449class OARPPacket : public QObject
450{ 450{
451 Q_OBJECT 451 Q_OBJECT
452 452
453 public: 453 public:
454 OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 ); 454 OARPPacket( const unsigned char*, const struct myarphdr*, QObject* parent = 0 );
455 virtual ~OARPPacket(); 455 virtual ~OARPPacket();
456 456
457 QHostAddress senderIPV4Address() const; 457 QHostAddress senderIPV4Address() const;
458 OMacAddress senderMacAddress() const; 458 OMacAddress senderMacAddress() const;
459 QHostAddress targetIPV4Address() const; 459 QHostAddress targetIPV4Address() const;
460 OMacAddress targetMacAddress() const; 460 OMacAddress targetMacAddress() const;
461 461
462 //int type() const; 462 //int type() const;
463 QString type() const; 463 QString type() const;
464 464
465 private: 465 private:
466 const struct myarphdr* _arphdr; 466 const struct myarphdr* _arphdr;
467}; 467};
468 468
469/*====================================================================================== 469/*======================================================================================
470 * OUDPPacket 470 * OUDPPacket
471 *======================================================================================*/ 471 *======================================================================================*/
472 472
473class OUDPPacket : public QObject 473class OUDPPacket : public QObject
474{ 474{
475 Q_OBJECT 475 Q_OBJECT
476 476
477 public: 477 public:
478 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 ); 478 OUDPPacket( const unsigned char*, const struct udphdr*, QObject* parent = 0 );
479 virtual ~OUDPPacket(); 479 virtual ~OUDPPacket();
480 480
481 int fromPort() const; 481 int fromPort() const;
482 int toPort() const; 482 int toPort() const;
483 int length() const; 483 int length() const;
484 int checksum() const; 484 int checksum() const;
485 485
486 private: 486 private:
487 const struct udphdr* _udphdr; 487 const struct udphdr* _udphdr;
488}; 488};
489 489
490/*====================================================================================== 490/*======================================================================================
491 * ODHCPPacket 491 * ODHCPPacket
492 *======================================================================================*/ 492 *======================================================================================*/
493 493
494class ODHCPPacket : public QObject 494class ODHCPPacket : public QObject
495{ 495{
496 Q_OBJECT 496 Q_OBJECT
497 497
498 public: 498 public:
499 ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 ); 499 ODHCPPacket( const unsigned char*, const struct dhcp_packet*, QObject* parent = 0 );
500 virtual ~ODHCPPacket(); 500 virtual ~ODHCPPacket();
501 501
502 QHostAddress clientAddress() const;
503 QHostAddress yourAddress() const;
504 QHostAddress serverAddress() const;
505 QHostAddress relayAddress() const;
506
507 bool isRequest() const;
508 bool isReply() const;
509 QString type() const;
510
502 private: 511 private:
503 const struct dhcp_packet* _dhcphdr; 512 const struct dhcp_packet* _dhcphdr;
513 unsigned char _type;
504}; 514};
505 515
506/*====================================================================================== 516/*======================================================================================
507 * OTCPPacket 517 * OTCPPacket
508 *======================================================================================*/ 518 *======================================================================================*/
509 519
510class OTCPPacket : public QObject 520class OTCPPacket : public QObject
511{ 521{
512 Q_OBJECT 522 Q_OBJECT
513 523
514 public: 524 public:
515 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 ); 525 OTCPPacket( const unsigned char*, const struct tcphdr*, QObject* parent = 0 );
516 virtual ~OTCPPacket(); 526 virtual ~OTCPPacket();
517 527
518 int fromPort() const; 528 int fromPort() const;
519 int toPort() const; 529 int toPort() const;
520 int seq() const; 530 int seq() const;
521 int ack() const; 531 int ack() const;
522 int window() const; 532 int window() const;
523 int checksum() const; 533 int checksum() const;
524 534
525 private: 535 private:
526 const struct tcphdr* _tcphdr; 536 const struct tcphdr* _tcphdr;
527}; 537};
528 538
529 539
530/*====================================================================================== 540/*======================================================================================
531 * OPacketCapturer 541 * OPacketCapturer
532 *======================================================================================*/ 542 *======================================================================================*/
533 543
534/** 544/**
535 * @brief A class based wrapper for network packet capturing. 545 * @brief A class based wrapper for network packet capturing.
536 * 546 *
537 * This class is the base of a high-level interface to the well known packet capturing 547 * This class is the base of a high-level interface to the well known packet capturing
538 * library libpcap. 548 * library libpcap.
539 * @see http://tcpdump.org 549 * @see http://tcpdump.org
540 */ 550 */
541class OPacketCapturer : public QObject 551class OPacketCapturer : public QObject
542{ 552{
543 Q_OBJECT 553 Q_OBJECT
544 554
545 public: 555 public:
546 /** 556 /**
547 * Constructor. 557 * Constructor.
548 */ 558 */
549 OPacketCapturer( QObject* parent = 0, const char* name = 0 ); 559 OPacketCapturer( QObject* parent = 0, const char* name = 0 );
550 /** 560 /**
551 * Destructor. 561 * Destructor.
552 */ 562 */
553 ~OPacketCapturer(); 563 ~OPacketCapturer();
554 /** 564 /**
555 * Set the packet capturer to use blocking or non-blocking IO. This can be useful when 565 * Set the packet capturer to use blocking or non-blocking IO. This can be useful when
556 * not using the socket notifier, e.g. without an application object. 566 * not using the socket notifier, e.g. without an application object.
557 */ 567 */
558 void setBlocking( bool ); 568 void setBlocking( bool );
559 /** 569 /**
560 * @returns true if the packet capturer uses blocking IO calls. 570 * @returns true if the packet capturer uses blocking IO calls.
561 */ 571 */
562 bool blocking() const; 572 bool blocking() const;
563 /** 573 /**
564 * Close the packet capturer. This is automatically done in the destructor. 574 * Close the packet capturer. This is automatically done in the destructor.
565 */ 575 */
566 void close(); 576 void close();
567 /** 577 /**
568 * Close the output capture file. 578 * Close the output capture file.
569 */ 579 */
570 void closeDumpFile(); 580 void closeDumpFile();
571 /** 581 /**
572 * @returns the data link type. 582 * @returns the data link type.
573 * @see <pcap.h> for possible values. 583 * @see <pcap.h> for possible values.
574 */ 584 */
575 int dataLink() const; 585 int dataLink() const;
576 /** 586 /**
577 * Dump a packet to the output capture file. 587 * Dump a packet to the output capture file.
578 */ 588 */
579 void dump( OPacket* ); 589 void dump( OPacket* );
580 /** 590 /**
581 * @returns the file descriptor of the packet capturer. This is only useful, if 591 * @returns the file descriptor of the packet capturer. This is only useful, if
582 * not using the socket notifier, e.g. without an application object. 592 * not using the socket notifier, e.g. without an application object.
583 */ 593 */
584 int fileno() const; 594 int fileno() const;
585 /** 595 /**
586 * @returns the next @ref OPacket from the packet capturer. 596 * @returns the next @ref OPacket from the packet capturer.
587 * @note If blocking mode is true then this call might block. 597 * @note If blocking mode is true then this call might block.
588 */ 598 */
589 OPacket* next(); 599 OPacket* next();
590 /** 600 /**
591 * Open the packet capturer to capture packets in live-mode from @a interface. 601 * Open the packet capturer to capture packets in live-mode from @a interface.
592 */ 602 */
593 bool open( const QString& interface ); 603 bool open( const QString& interface );
594 /** 604 /**
595 * Open the packet capturer to capture packets in offline-mode from @a file. 605 * Open the packet capturer to capture packets in offline-mode from @a file.
596 */ 606 */
597 bool open( const QFile& file ); 607 bool open( const QFile& file );
598 /** 608 /**
599 * Open a prerecorded tcpdump compatible capture file for use with @ref dump() 609 * Open a prerecorded tcpdump compatible capture file for use with @ref dump()
600 */ 610 */
601 bool openDumpFile( const QString& filename ); 611 bool openDumpFile( const QString& filename );
602 /** 612 /**
603 * @returns true if the packet capturer is open 613 * @returns true if the packet capturer is open
604 */ 614 */
605 bool isOpen() const; 615 bool isOpen() const;
606 /** 616 /**
607 * @returns the snapshot length of this packet capturer 617 * @returns the snapshot length of this packet capturer
608 */ 618 */
609 int snapShot() const; 619 int snapShot() const;
610 /** 620 /**
611 * @returns true if the input capture file has a different byte-order 621 * @returns true if the input capture file has a different byte-order
612 * than the byte-order of the running system. 622 * than the byte-order of the running system.
613 */ 623 */
614 bool swapped() const; 624 bool swapped() const;
615 /** 625 /**
616 * @returns the libpcap version string used to write the input capture file. 626 * @returns the libpcap version string used to write the input capture file.
617 */ 627 */
618 QString version() const; 628 QString version() const;
619 /** 629 /**
620 * @returns the packet statistic database. 630 * @returns the packet statistic database.
621 * @see QMap 631 * @see QMap
622 */ 632 */
623 const QMap<QString,int>& statistics() const; 633 const QMap<QString,int>& statistics() const;
624 634
625 signals: 635 signals:
626 /** 636 /**
627 * This signal is emitted, when a packet has been received. 637 * This signal is emitted, when a packet has been received.
628 */ 638 */
629 void receivedPacket( OPacket* ); 639 void receivedPacket( OPacket* );
630 640
631 protected slots: 641 protected slots:
632 void readyToReceive(); 642 void readyToReceive();
633 643
634 protected: 644 protected:
635 QString _name; // devicename 645 QString _name; // devicename
636 bool _open; // check this before doing pcap calls 646 bool _open; // check this before doing pcap calls
637 pcap_t* _pch; // pcap library handle 647 pcap_t* _pch; // pcap library handle
638 pcap_dumper_t* _pcd; // pcap dumper handle 648 pcap_dumper_t* _pcd; // pcap dumper handle
639 QSocketNotifier* _sn; // socket notifier for main loop 649 QSocketNotifier* _sn; // socket notifier for main loop
640 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap 650 mutable char _errbuf[PCAP_ERRBUF_SIZE]; // holds error strings from libpcap
641 QMap<QString, int> _stats; // statistics; 651 QMap<QString, int> _stats; // statistics;
642}; 652};
643 653
644#endif // OPCAP_H 654#endif // OPCAP_H
645 655