summaryrefslogtreecommitdiff
path: root/libopie2/opienet/opcap.cpp
Unidiff
Diffstat (limited to 'libopie2/opienet/opcap.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index e362883..675818e 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -20,96 +20,101 @@
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/opcap.h> 36#include <opie2/opcap.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) 40#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects)
41#include <qsocketnotifier.h> 41#include <qsocketnotifier.h>
42#include <qobjectlist.h> 42#include <qobjectlist.h>
43 43
44/*====================================================================================== 44/*======================================================================================
45 * OPacket 45 * OPacket
46 *======================================================================================*/ 46 *======================================================================================*/
47 47
48OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 48OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
49 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 49 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
50{ 50{
51 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 51 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
52 52
53 _end = (unsigned char*) data + header.len; 53 _end = (unsigned char*) data + header.len;
54 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 54 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
55 55
56 switch ( datalink ) 56 switch ( datalink )
57 { 57 {
58 case DLT_EN10MB: 58 case DLT_EN10MB:
59 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 59 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
60 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 60 new OEthernetPacket( _end, (const struct ether_header*) data, this );
61 break; 61 break;
62 62
63 case DLT_IEEE802_11: 63 case DLT_IEEE802_11:
64 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 64 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
65 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 65 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
66 break; 66 break;
67 67
68 case DLT_PRISM_HEADER:
69 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" );
70 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this );
71 break;
72
68 default: 73 default:
69 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink ); 74 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink '%s'!", datalink );
70 } 75 }
71} 76}
72 77
73 78
74OPacket::~OPacket() 79OPacket::~OPacket()
75{ 80{
76} 81}
77 82
78 83
79timevalstruct OPacket::timeval() const 84timevalstruct OPacket::timeval() const
80{ 85{
81 return _hdr.ts; 86 return _hdr.ts;
82} 87}
83 88
84 89
85int OPacket::caplen() const 90int OPacket::caplen() const
86{ 91{
87 return _hdr.caplen; 92 return _hdr.caplen;
88} 93}
89 94
90 95
91void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 96void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
92{ 97{
93 if (!l) return; 98 if (!l) return;
94 QObject* o = l->first(); 99 QObject* o = l->first();
95 while ( o ) 100 while ( o )
96 { 101 {
97 stats[o->name()]++; 102 stats[o->name()]++;
98 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 103 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
99 o = l->next(); 104 o = l->next();
100 } 105 }
101} 106}
102 107
103 108
104QString OPacket::dump( int bpl ) const 109QString OPacket::dump( int bpl ) const
105{ 110{
106 static int index = 0; 111 static int index = 0;
107 index++; 112 index++;
108 int len = _hdr.caplen; 113 int len = _hdr.caplen;
109 QString str; 114 QString str;
110 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 115 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
111 str.append( "0000: " ); 116 str.append( "0000: " );
112 QString tmp; 117 QString tmp;
113 QString bytes; 118 QString bytes;
114 QString chars; 119 QString chars;
115 120
@@ -271,96 +276,122 @@ int OIPPacket::ttl() const
271 276
272 277
273int OIPPacket::protocol() const 278int OIPPacket::protocol() const
274{ 279{
275 return _iphdr->protocol; 280 return _iphdr->protocol;
276} 281}
277 282
278 283
279int OIPPacket::checksum() const 284int OIPPacket::checksum() const
280{ 285{
281 return EXTRACT_16BITS( &_iphdr->check ); 286 return EXTRACT_16BITS( &_iphdr->check );
282} 287}
283 288
284/*====================================================================================== 289/*======================================================================================
285 * OUDPPacket 290 * OUDPPacket
286 *======================================================================================*/ 291 *======================================================================================*/
287 292
288 293
289OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) 294OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
290 :QObject( parent, "UDP" ), _udphdr( data ) 295 :QObject( parent, "UDP" ), _udphdr( data )
291 296
292{ 297{
293 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); 298 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." );
294} 299}
295 300
296OUDPPacket::~OUDPPacket() 301OUDPPacket::~OUDPPacket()
297{ 302{
298} 303}
299 304
300 305
301/*====================================================================================== 306/*======================================================================================
302 * OTCPPacket 307 * OTCPPacket
303 *======================================================================================*/ 308 *======================================================================================*/
304 309
305 310
306OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) 311OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
307 :QObject( parent, "TCP" ), _tcphdr( data ) 312 :QObject( parent, "TCP" ), _tcphdr( data )
308 313
309{ 314{
310 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); 315 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." );
311} 316}
312 317
313OTCPPacket::~OTCPPacket() 318OTCPPacket::~OTCPPacket()
314{ 319{
315} 320}
316 321
317 322
318/*====================================================================================== 323/*======================================================================================
324 * OPrismHeaderPacket
325 *======================================================================================*/
326
327
328OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent )
329 :QObject( parent, "Prism" ), _header( data )
330
331{
332 qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." );
333
334 qDebug( "Signal Strength = %d", data->signal.data );
335
336 new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this );
337}
338
339OPrismHeaderPacket::~OPrismHeaderPacket()
340{
341}
342
343
344unsigned int OPrismHeaderPacket::signalStrength() const
345{
346 return _header->signal.data;
347}
348
349/*======================================================================================
319 * OWaveLanPacket 350 * OWaveLanPacket
320 *======================================================================================*/ 351 *======================================================================================*/
321 352
322 353
323OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) 354OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
324 :QObject( parent, "802.11" ), _wlanhdr( data ) 355 :QObject( parent, "802.11" ), _wlanhdr( data )
325 356
326{ 357{
327 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); 358 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." );
328 qDebug( "type: %0X", type() ); 359 qDebug( "type: %0X", type() );
329 qDebug( "subType: %0X", subType() ); 360 qDebug( "subType: %0X", subType() );
330 qDebug( "duration: %d", duration() ); 361 qDebug( "duration: %d", duration() );
331 qDebug( "powermanagement: %d", usesPowerManagement() ); 362 qDebug( "powermanagement: %d", usesPowerManagement() );
332 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); 363 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" );
333 qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); 364 qDebug( "MAC1: %s", (const char*) macAddress1().toString() );
334 qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); 365 qDebug( "MAC2: %s", (const char*) macAddress2().toString() );
335 qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); 366 qDebug( "MAC3: %s", (const char*) macAddress3().toString() );
336 qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); 367 qDebug( "MAC4: %s", (const char*) macAddress4().toString() );
337 368
338 switch ( type() ) 369 switch ( type() )
339 { 370 {
340 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; 371 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
341 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; 372 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
342 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; 373 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break;
343 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); 374 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() );
344 } 375 }
345} 376}
346 377
347OWaveLanPacket::~OWaveLanPacket() 378OWaveLanPacket::~OWaveLanPacket()
348{ 379{
349} 380}
350 381
351 382
352int OWaveLanPacket::duration() const 383int OWaveLanPacket::duration() const
353{ 384{
354 return _wlanhdr->duration; 385 return _wlanhdr->duration;
355} 386}
356 387
357 388
358OMacAddress OWaveLanPacket::macAddress1() const 389OMacAddress OWaveLanPacket::macAddress1() const
359{ 390{
360 return OMacAddress( _wlanhdr->mac1 ); 391 return OMacAddress( _wlanhdr->mac1 );
361} 392}
362 393
363 394
364OMacAddress OWaveLanPacket::macAddress2() const 395OMacAddress OWaveLanPacket::macAddress2() const
365{ 396{
366 return OMacAddress( _wlanhdr->mac2 ); 397 return OMacAddress( _wlanhdr->mac2 );