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