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