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