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