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