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