summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-05-05 22:25:58 (UTC)
committer mickeyl <mickeyl>2003-05-05 22:25:58 (UTC)
commit3f8c29b3cbbb32864694fe9c95b43d1cb777360e (patch) (unidiff)
treedd749f9d27bfb8c9ad02bea8545fecba33555a67
parent3b193b852133a82b5c1708b68a7e460c63629768 (diff)
downloadopie-3f8c29b3cbbb32864694fe9c95b43d1cb777360e.zip
opie-3f8c29b3cbbb32864694fe9c95b43d1cb777360e.tar.gz
opie-3f8c29b3cbbb32864694fe9c95b43d1cb777360e.tar.bz2
fix typos
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp2
-rw-r--r--libopie2/opienet/opcap.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
index 34d32d2..c49daa0 100644
--- a/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
+++ b/libopie2/examples/opienet/miniwellenreiter/miniwellenreiter.cpp
@@ -1,217 +1,217 @@
1#include <qdict.h> 1#include <qdict.h>
2#include <qsocketnotifier.h> 2#include <qsocketnotifier.h>
3#include <qstring.h> 3#include <qstring.h>
4#include <opie2/onetwork.h> 4#include <opie2/onetwork.h>
5#include <qapplication.h> 5#include <qapplication.h>
6#include <opie2/opcap.h> 6#include <opie2/opcap.h>
7#include <cerrno> 7#include <cerrno>
8#include <cstdio> 8#include <cstdio>
9#include <cstdlib> 9#include <cstdlib>
10#include <cstring> 10#include <cstring>
11 11
12//======================== Station help class =============================== 12//======================== Station help class ===============================
13 13
14class Station 14class Station
15{ 15{
16 public: 16 public:
17 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {}; 17 Station( QString t, int c, bool w ) : type(t), channel(c), wep(w), beacons(1) {};
18 ~Station() {}; 18 ~Station() {};
19 19
20 QString type; 20 QString type;
21 int channel; 21 int channel;
22 bool wep; 22 bool wep;
23 int beacons; 23 int beacons;
24}; 24};
25 25
26QDict<Station> stations; 26QDict<Station> stations;
27 27
28//======================== Application class =============================== 28//======================== Application class ===============================
29 29
30class Wellenreiter : public QApplication 30class Wellenreiter : public QApplication
31{ 31{
32Q_OBJECT 32Q_OBJECT
33public: 33public:
34 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv ) 34 Wellenreiter( int argc, char** argv ) : QApplication( argc, argv )
35 { 35 {
36 36
37 ONetwork* net = ONetwork::instance(); 37 ONetwork* net = ONetwork::instance();
38 38
39 if ( argc < 3 ) 39 if ( argc < 3 )
40 { 40 {
41 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] ); 41 printf( "Usage: ./%s <interface> <driver> <interval>\n", argv[0] );
42 printf( "\n" ); 42 printf( "\n" );
43 printf( "Valid wireless interfaces (detected) are:\n" ); 43 printf( "Valid wireless interfaces (detected) are:\n" );
44 44
45 ONetwork::InterfaceIterator it = net->iterator(); 45 ONetwork::InterfaceIterator it = net->iterator();
46 while ( it.current() ) 46 while ( it.current() )
47 { 47 {
48 if ( it.current()->isWireless() ) 48 if ( it.current()->isWireless() )
49 { 49 {
50 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(), 50 printf( " - '%s' (MAC=%s) (IPv4=%s)\n", (const char*) it.current()->name(),
51 (const char*) it.current()->macAddress().toString(), 51 (const char*) it.current()->macAddress().toString(),
52 (const char*) it.current()->ipV4Address() ); 52 (const char*) it.current()->ipV4Address() );
53 } 53 }
54 ++it; 54 ++it;
55 } 55 }
56 exit( -1 ); 56 exit( -1 );
57 } 57 }
58 58
59 printf( "****************************************************\n" ); 59 printf( "****************************************************\n" );
60 printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" ); 60 printf( "* Wellenreiter mini edition 1.0 (C) 2003 M-M-M *\n" );
61 printf( "****************************************************\n" ); 61 printf( "****************************************************\n" );
62 printf( "\n\n" ); 62 printf( "\n\n" );
63 63
64 QString interface( argv[1] ); 64 QString interface( argv[1] );
65 QString driver( argv[2] ); 65 QString driver( argv[2] );
66 66
67 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver ); 67 printf( "Trying to use '%s' as %s-controlled device...\n", (const char*) interface, (const char*) driver );
68 68
69 // sanity checks before downcasting 69 // sanity checks before downcasting
70 ONetworkInterface* iface = net->interface( interface ); 70 ONetworkInterface* iface = net->interface( interface );
71 if ( !iface ) 71 if ( !iface )
72 { 72 {
73 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface ); 73 printf( "Interface '%s' doesn't exist. Exiting.\n", (const char*) interface );
74 exit( -1 ); 74 exit( -1 );
75 } 75 }
76 if ( !iface->isWireless() ) 76 if ( !iface->isWireless() )
77 { 77 {
78 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface ); 78 printf( "Interface '%s' doesn't support wireless extensions. Exiting.\n", (const char*) interface );
79 exit( -1 ); 79 exit( -1 );
80 } 80 }
81 81
82 // downcast should be safe now 82 // downcast should be safe now
83 wiface = (OWirelessNetworkInterface*) iface; 83 wiface = (OWirelessNetworkInterface*) iface;
84 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() ); 84 printf( "Using wireless interface '%s' for scanning (current SSID is '%s')...\n", (const char*) interface, (const char*) wiface->SSID() );
85 85
86 // ifconfig +promisc the interface to receive all packets 86 // ifconfig +promisc the interface to receive all packets
87 if ( !wiface->promiscuousMode() ) 87 if ( !wiface->promiscuousMode() )
88 { 88 {
89 printf( "Interface status is not promisc... switching to promisc... " ); 89 printf( "Interface status is not promisc... switching to promisc... " );
90 wiface->setPromiscuousMode( true ); 90 wiface->setPromiscuousMode( true );
91 if ( !wiface->promiscuousMode() ) 91 if ( !wiface->promiscuousMode() )
92 { 92 {
93 printf( "failed (%s). Exiting.\n", strerror( errno ) ); 93 printf( "failed (%s). Exiting.\n", strerror( errno ) );
94 exit( -1 ); 94 exit( -1 );
95 } 95 }
96 else 96 else
97 { 97 {
98 printf( "ok.\n" ); 98 printf( "ok.\n" );
99 } 99 }
100 } 100 }
101 else 101 else
102 printf( "Interface status is already promisc - good.\n" ); 102 printf( "Interface status is already promisc - good.\n" );
103 103
104 // connect a monitoring strategy to the interface 104 // connect a monitoring strategy to the interface
105 if ( driver == "orinoco" ) 105 if ( driver == "orinoco" )
106 new OOrinocoMonitoringInterface( wiface ); 106 new OOrinocoMonitoringInterface( wiface, false );
107 else 107 else
108 { 108 {
109 printf( "Unknown driver. Exiting\n" ); 109 printf( "Unknown driver. Exiting\n" );
110 exit( -1 ); 110 exit( -1 );
111 } 111 }
112 112
113 // enable monitoring mode 113 // enable monitoring mode
114 printf( "Enabling monitor mode...\n" ); 114 printf( "Enabling monitor mode...\n" );
115 //wiface->setMonitorMode( true ); 115 //wiface->setMonitorMode( true );
116 116
117 // open a packet capturer 117 // open a packet capturer
118 cap = new OPacketCapturer(); 118 cap = new OPacketCapturer();
119 cap->open( interface ); 119 cap->open( interface );
120 if ( !cap->isOpen() ) 120 if ( !cap->isOpen() )
121 { 121 {
122 printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) ); 122 printf( "Unable to open libpcap (%s). Exiting.\n", strerror( errno ) );
123 exit( -1 ); 123 exit( -1 );
124 } 124 }
125 125
126 // set capturer to non-blocking mode 126 // set capturer to non-blocking mode
127 cap->setBlocking( false ); 127 cap->setBlocking( false );
128 128
129 // start channel hopper 129 // start channel hopper
130 //wiface->setChannelHopping( 1000 ); 130 //wiface->setChannelHopping( 1000 );
131 131
132 // connect 132 // connect
133 connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); 133 connect( cap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
134 134
135 } 135 }
136 136
137 ~Wellenreiter() {}; 137 ~Wellenreiter() {};
138 138
139public slots: 139public slots:
140 void receivePacket(OPacket* p) 140 void receivePacket(OPacket* p)
141 { 141 {
142 if (!p) 142 if (!p)
143 { 143 {
144 printf( "(empty packet received)\n" ); 144 printf( "(empty packet received)\n" );
145 return; 145 return;
146 } 146 }
147 147
148 OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" ); 148 OWaveLanManagementPacket* beacon = (OWaveLanManagementPacket*) p->child( "802.11 Management" );
149 if ( beacon ) 149 if ( beacon )
150 { 150 {
151 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 151 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
152 QString essid = ssid ? ssid->ID() : "<unknown>"; 152 QString essid = ssid ? ssid->ID() : "<unknown>";
153 153
154 if ( stations.find( essid ) ) 154 if ( stations.find( essid ) )
155 stations[essid]->beacons++; 155 stations[essid]->beacons++;
156 else 156 else
157 { 157 {
158 printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid ); 158 printf( "found new network @ channel %d, SSID = '%s'\n", wiface->channel(), (const char*) essid );
159 stations.insert( essid, new Station( "unknown", wiface->channel(), 159 stations.insert( essid, new Station( "unknown", wiface->channel(),
160 ((OWaveLanPacket*) beacon->parent())->usesWep() ) ); 160 ((OWaveLanPacket*) beacon->parent())->usesWep() ) );
161 } 161 }
162 return; 162 return;
163 } 163 }
164 164
165 OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" ); 165 OWaveLanDataPacket* data = (OWaveLanDataPacket*) p->child( "802.11 Data" );
166 if ( data ) 166 if ( data )
167 { 167 {
168 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); 168 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" );
169 if ( wlan->fromDS() && !wlan->toDS() ) 169 if ( wlan->fromDS() && !wlan->toDS() )
170 { 170 {
171 printf( "FromDS: '%s' -> '%s' via '%s'\n", 171 printf( "FromDS: '%s' -> '%s' via '%s'\n",
172 (const char*) wlan->macAddress3().toString(true), 172 (const char*) wlan->macAddress3().toString(true),
173 (const char*) wlan->macAddress1().toString(true), 173 (const char*) wlan->macAddress1().toString(true),
174 (const char*) wlan->macAddress2().toString(true) ); 174 (const char*) wlan->macAddress2().toString(true) );
175 } 175 }
176 else 176 else
177 if ( !wlan->fromDS() && wlan->toDS() ) 177 if ( !wlan->fromDS() && wlan->toDS() )
178 { 178 {
179 printf( "ToDS: '%s' -> '%s' via '%s'\n", 179 printf( "ToDS: '%s' -> '%s' via '%s'\n",
180 (const char*) wlan->macAddress2().toString(true), 180 (const char*) wlan->macAddress2().toString(true),
181 (const char*) wlan->macAddress3().toString(true), 181 (const char*) wlan->macAddress3().toString(true),
182 (const char*) wlan->macAddress1().toString(true) ); 182 (const char*) wlan->macAddress1().toString(true) );
183 } 183 }
184 else 184 else
185 if ( wlan->fromDS() && wlan->toDS() ) 185 if ( wlan->fromDS() && wlan->toDS() )
186 { 186 {
187 printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n", 187 printf( "WSD(bridge): '%s' -> '%s' via '%s' and '%s'\n",
188 (const char*) wlan->macAddress4().toString(true), 188 (const char*) wlan->macAddress4().toString(true),
189 (const char*) wlan->macAddress3().toString(true), 189 (const char*) wlan->macAddress3().toString(true),
190 (const char*) wlan->macAddress1().toString(true), 190 (const char*) wlan->macAddress1().toString(true),
191 (const char*) wlan->macAddress2().toString(true) ); 191 (const char*) wlan->macAddress2().toString(true) );
192 } 192 }
193 else 193 else
194 { 194 {
195 printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n", 195 printf( "IBSS(AdHoc): '%s' -> '%s' (Cell: '%s')'\n",
196 (const char*) wlan->macAddress2().toString(true), 196 (const char*) wlan->macAddress2().toString(true),
197 (const char*) wlan->macAddress1().toString(true), 197 (const char*) wlan->macAddress1().toString(true),
198 (const char*) wlan->macAddress3().toString(true) ); 198 (const char*) wlan->macAddress3().toString(true) );
199 } 199 }
200 return; 200 return;
201 } 201 }
202 } 202 }
203private: 203private:
204 OPacketCapturer* cap; 204 OPacketCapturer* cap;
205 OWirelessNetworkInterface* wiface; 205 OWirelessNetworkInterface* wiface;
206}; 206};
207 207
208 208
209int main( int argc, char** argv ) 209int main( int argc, char** argv )
210{ 210{
211 Wellenreiter w( argc, argv ); 211 Wellenreiter w( argc, argv );
212 w.exec(); 212 w.exec();
213 return 0; 213 return 0;
214} 214}
215 215
216#include "miniwellenreiter.moc" 216#include "miniwellenreiter.moc"
217 217
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index f6d05ea..523be3e 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -41,1017 +41,1017 @@
41#include <qsocketnotifier.h> 41#include <qsocketnotifier.h>
42#include <qobjectlist.h> 42#include <qobjectlist.h>
43 43
44/*====================================================================================== 44/*======================================================================================
45 * OPacket 45 * OPacket
46 *======================================================================================*/ 46 *======================================================================================*/
47 47
48OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 48OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
49 :QObject( parent, "Generic" ), _hdr( header ), _data( data ) 49 :QObject( parent, "Generic" ), _hdr( header ), _data( data )
50{ 50{
51 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); 51 //qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen );
52 52
53 _end = (unsigned char*) data + header.len; 53 _end = (unsigned char*) data + header.len;
54 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); 54 //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end );
55 55
56 switch ( datalink ) 56 switch ( datalink )
57 { 57 {
58 case DLT_EN10MB: 58 case DLT_EN10MB:
59 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" ); 59 qDebug( "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" );
60 new OEthernetPacket( _end, (const struct ether_header*) data, this ); 60 new OEthernetPacket( _end, (const struct ether_header*) data, this );
61 break; 61 break;
62 62
63 case DLT_IEEE802_11: 63 case DLT_IEEE802_11:
64 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" ); 64 qDebug( "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" );
65 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); 65 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this );
66 break; 66 break;
67 67
68 case DLT_PRISM_HEADER: 68 case DLT_PRISM_HEADER:
69 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" ); 69 qDebug( "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" );
70 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); 70 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this );
71 break; 71 break;
72 72
73 default: 73 default:
74 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink ); 74 qWarning( "OPacket::OPacket(): Received Packet over unsupported datalink (type %d)!", datalink );
75 } 75 }
76} 76}
77 77
78 78
79OPacket::~OPacket() 79OPacket::~OPacket()
80{ 80{
81} 81}
82 82
83 83
84timevalstruct OPacket::timeval() const 84timevalstruct OPacket::timeval() const
85{ 85{
86 return _hdr.ts; 86 return _hdr.ts;
87} 87}
88 88
89 89
90int OPacket::caplen() const 90int OPacket::caplen() const
91{ 91{
92 return _hdr.caplen; 92 return _hdr.caplen;
93} 93}
94 94
95 95
96void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 96void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
97{ 97{
98 if (!l) return; 98 if (!l) return;
99 QObject* o = l->first(); 99 QObject* o = l->first();
100 while ( o ) 100 while ( o )
101 { 101 {
102 stats[o->name()]++; 102 stats[o->name()]++;
103 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 103 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
104 o = l->next(); 104 o = l->next();
105 } 105 }
106} 106}
107 107
108 108
109QString OPacket::dump( int bpl ) const 109QString OPacket::dump( int bpl ) const
110{ 110{
111 static int index = 0; 111 static int index = 0;
112 index++; 112 index++;
113 int len = _hdr.caplen; 113 int len = _hdr.caplen;
114 QString str; 114 QString str;
115 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); 115 str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len );
116 str.append( "0000: " ); 116 str.append( "0000: " );
117 QString tmp; 117 QString tmp;
118 QString bytes; 118 QString bytes;
119 QString chars; 119 QString chars;
120 120
121 for ( int i = 0; i < len; ++i ) 121 for ( int i = 0; i < len; ++i )
122 { 122 {
123 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 123 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
124 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 124 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
125 else chars.append( '.' ); 125 else chars.append( '.' );
126 126
127 if ( !((i+1) % bpl) ) 127 if ( !((i+1) % bpl) )
128 { 128 {
129 str.append( bytes ); 129 str.append( bytes );
130 str.append( ' ' ); 130 str.append( ' ' );
131 str.append( chars ); 131 str.append( chars );
132 str.append( '\n' ); 132 str.append( '\n' );
133 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); 133 tmp.sprintf( "%04X: ", i+1 ); str.append( tmp );
134 bytes = ""; 134 bytes = "";
135 chars = ""; 135 chars = "";
136 } 136 }
137 137
138 } 138 }
139 if ( (len % bpl) ) 139 if ( (len % bpl) )
140 { 140 {
141 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 141 str.append( bytes.leftJustify( 1 + 3*bpl ) );
142 str.append( chars ); 142 str.append( chars );
143 } 143 }
144 str.append( '\n' ); 144 str.append( '\n' );
145 return str; 145 return str;
146} 146}
147 147
148 148
149int OPacket::len() const 149int OPacket::len() const
150{ 150{
151 return _hdr.len; 151 return _hdr.len;
152} 152}
153 153
154 154
155/*====================================================================================== 155/*======================================================================================
156 * OEthernetPacket 156 * OEthernetPacket
157 *======================================================================================*/ 157 *======================================================================================*/
158 158
159OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 159OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
160 :QObject( parent, "Ethernet" ), _ether( data ) 160 :QObject( parent, "Ethernet" ), _ether( data )
161{ 161{
162 162
163 qDebug( "Source = %s", (const char*) sourceAddress().toString() ); 163 qDebug( "Source = %s", (const char*) sourceAddress().toString() );
164 qDebug( "Destination = %s", (const char*) destinationAddress().toString() ); 164 qDebug( "Destination = %s", (const char*) destinationAddress().toString() );
165 165
166 if ( sourceAddress() == OMacAddress::broadcast ) 166 if ( sourceAddress() == OMacAddress::broadcast )
167 qDebug( "Source is broadcast address" ); 167 qDebug( "Source is broadcast address" );
168 if ( destinationAddress() == OMacAddress::broadcast ) 168 if ( destinationAddress() == OMacAddress::broadcast )
169 qDebug( "Destination is broadcast address" ); 169 qDebug( "Destination is broadcast address" );
170 170
171 switch ( type() ) 171 switch ( type() )
172 { 172 {
173 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 173 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
174 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; } 174 case ETHERTYPE_ARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = ARP" ); break; }
175 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; } 175 case ETHERTYPE_REVARP: { qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" ); break; }
176 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" ); 176 default: qDebug( "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" );
177 } 177 }
178 178
179} 179}
180 180
181 181
182OEthernetPacket::~OEthernetPacket() 182OEthernetPacket::~OEthernetPacket()
183{ 183{
184} 184}
185 185
186 186
187OMacAddress OEthernetPacket::sourceAddress() const 187OMacAddress OEthernetPacket::sourceAddress() const
188{ 188{
189 return OMacAddress( _ether->ether_shost ); 189 return OMacAddress( _ether->ether_shost );
190} 190}
191 191
192 192
193OMacAddress OEthernetPacket::destinationAddress() const 193OMacAddress OEthernetPacket::destinationAddress() const
194{ 194{
195 return OMacAddress( _ether->ether_dhost ); 195 return OMacAddress( _ether->ether_dhost );
196} 196}
197 197
198int OEthernetPacket::type() const 198int OEthernetPacket::type() const
199{ 199{
200 return ntohs( _ether->ether_type ); 200 return ntohs( _ether->ether_type );
201} 201}
202 202
203 203
204/*====================================================================================== 204/*======================================================================================
205 * OIPPacket 205 * OIPPacket
206 *======================================================================================*/ 206 *======================================================================================*/
207 207
208 208
209OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) 209OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
210 :QObject( parent, "IP" ), _iphdr( data ) 210 :QObject( parent, "IP" ), _iphdr( data )
211{ 211{
212 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." ); 212 qDebug( "OIPPacket::OIPPacket(): decoding IP header..." );
213 213
214 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) ); 214 //qDebug( "FromAddress: %s", (const char*) inet_ntoa( *src ) );
215 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) ); 215 //qDebug( " ToAddress: %s", (const char*) inet_ntoa( *dst ) );
216 216
217 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() ); 217 qDebug( "FromAddress: %s", (const char*) fromIPAddress().toString() );
218 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() ); 218 qDebug( " toAddress: %s", (const char*) toIPAddress().toString() );
219 219
220 switch ( protocol() ) 220 switch ( protocol() )
221 { 221 {
222 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; 222 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
223 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; 223 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
224 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() ); 224 default: qDebug( "OIPPacket::OIPPacket(): unknown IP protocol type = %d", protocol() );
225 } 225 }
226 226
227} 227}
228 228
229OIPPacket::~OIPPacket() 229OIPPacket::~OIPPacket()
230{ 230{
231} 231}
232 232
233 233
234QHostAddress OIPPacket::fromIPAddress() const 234QHostAddress OIPPacket::fromIPAddress() const
235{ 235{
236 return EXTRACT_32BITS( &_iphdr->saddr ); 236 return EXTRACT_32BITS( &_iphdr->saddr );
237} 237}
238 238
239 239
240QHostAddress OIPPacket::toIPAddress() const 240QHostAddress OIPPacket::toIPAddress() const
241{ 241{
242 return EXTRACT_32BITS( &_iphdr->saddr ); 242 return EXTRACT_32BITS( &_iphdr->saddr );
243} 243}
244 244
245 245
246int OIPPacket::tos() const 246int OIPPacket::tos() const
247{ 247{
248 return _iphdr->tos; 248 return _iphdr->tos;
249} 249}
250 250
251 251
252int OIPPacket::len() const 252int OIPPacket::len() const
253{ 253{
254 return EXTRACT_16BITS( &_iphdr->tot_len ); 254 return EXTRACT_16BITS( &_iphdr->tot_len );
255} 255}
256 256
257 257
258int OIPPacket::id() const 258int OIPPacket::id() const
259{ 259{
260 return EXTRACT_16BITS( &_iphdr->id ); 260 return EXTRACT_16BITS( &_iphdr->id );
261} 261}
262 262
263 263
264int OIPPacket::offset() const 264int OIPPacket::offset() const
265{ 265{
266 return EXTRACT_16BITS( &_iphdr->frag_off ); 266 return EXTRACT_16BITS( &_iphdr->frag_off );
267} 267}
268 268
269 269
270int OIPPacket::ttl() const 270int OIPPacket::ttl() const
271{ 271{
272 return _iphdr->ttl; 272 return _iphdr->ttl;
273} 273}
274 274
275 275
276int OIPPacket::protocol() const 276int OIPPacket::protocol() const
277{ 277{
278 return _iphdr->protocol; 278 return _iphdr->protocol;
279} 279}
280 280
281 281
282int OIPPacket::checksum() const 282int OIPPacket::checksum() const
283{ 283{
284 return EXTRACT_16BITS( &_iphdr->check ); 284 return EXTRACT_16BITS( &_iphdr->check );
285} 285}
286 286
287/*====================================================================================== 287/*======================================================================================
288 * OARPPacket 288 * OARPPacket
289 *======================================================================================*/ 289 *======================================================================================*/
290 290
291 291
292OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) 292OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent )
293 :QObject( parent, "ARP" ), _arphdr( data ) 293 :QObject( parent, "ARP" ), _arphdr( data )
294{ 294{
295 qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." ); 295 qDebug( "OARPPacket::OARPPacket(): decoding ARP header..." );
296 qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() ); 296 qDebug( "ARP type seems to be %02d - '%s'", EXTRACT_16BITS( &_arphdr->ar_op ), (const char*) type() );
297 qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() ); 297 qDebug( "Sender: MAC %s = IP %s", (const char*) senderMacAddress().toString(), (const char*) senderIPV4Address().toString() );
298 qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() ); 298 qDebug( "Target: MAC %s = IP %s", (const char*) targetMacAddress().toString(), (const char*) targetIPV4Address().toString() );
299} 299}
300 300
301 301
302OARPPacket::~OARPPacket() 302OARPPacket::~OARPPacket()
303{ 303{
304} 304}
305 305
306 306
307QString OARPPacket::type() const 307QString OARPPacket::type() const
308{ 308{
309 switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) 309 switch ( EXTRACT_16BITS( &_arphdr->ar_op ) )
310 { 310 {
311 case 1: return "REQUEST"; 311 case 1: return "REQUEST";
312 case 2: return "REPLY"; 312 case 2: return "REPLY";
313 case 3: return "RREQUEST"; 313 case 3: return "RREQUEST";
314 case 4: return "RREPLY"; 314 case 4: return "RREPLY";
315 case 8: return "InREQUEST"; 315 case 8: return "InREQUEST";
316 case 9: return "InREPLY"; 316 case 9: return "InREPLY";
317 case 10: return "NAK"; 317 case 10: return "NAK";
318 default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>"; 318 default: qWarning( "OARPPacket::type(): invalid ARP type!" ); return "<unknown>";
319 } 319 }
320} 320}
321 321
322 322
323QHostAddress OARPPacket::senderIPV4Address() const 323QHostAddress OARPPacket::senderIPV4Address() const
324{ 324{
325 return EXTRACT_32BITS( &_arphdr->ar_sip ); 325 return EXTRACT_32BITS( &_arphdr->ar_sip );
326} 326}
327 327
328 328
329QHostAddress OARPPacket::targetIPV4Address() const 329QHostAddress OARPPacket::targetIPV4Address() const
330{ 330{
331 return EXTRACT_32BITS( &_arphdr->ar_tip ); 331 return EXTRACT_32BITS( &_arphdr->ar_tip );
332} 332}
333 333
334 334
335OMacAddress OARPPacket::senderMacAddress() const 335OMacAddress OARPPacket::senderMacAddress() const
336{ 336{
337 return OMacAddress( _arphdr->ar_sha ); 337 return OMacAddress( _arphdr->ar_sha );
338} 338}
339 339
340 340
341OMacAddress OARPPacket::targetMacAddress() const 341OMacAddress OARPPacket::targetMacAddress() const
342{ 342{
343 return OMacAddress( _arphdr->ar_tha ); 343 return OMacAddress( _arphdr->ar_tha );
344} 344}
345 345
346 346
347/*====================================================================================== 347/*======================================================================================
348 * OUDPPacket 348 * OUDPPacket
349 *======================================================================================*/ 349 *======================================================================================*/
350 350
351 351
352OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) 352OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
353 :QObject( parent, "UDP" ), _udphdr( data ) 353 :QObject( parent, "UDP" ), _udphdr( data )
354 354
355{ 355{
356 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." ); 356 qDebug( "OUDPPacket::OUDPPacket(): decoding UDP header..." );
357} 357}
358 358
359OUDPPacket::~OUDPPacket() 359OUDPPacket::~OUDPPacket()
360{ 360{
361} 361}
362 362
363 363
364/*====================================================================================== 364/*======================================================================================
365 * OTCPPacket 365 * OTCPPacket
366 *======================================================================================*/ 366 *======================================================================================*/
367 367
368 368
369OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) 369OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
370 :QObject( parent, "TCP" ), _tcphdr( data ) 370 :QObject( parent, "TCP" ), _tcphdr( data )
371 371
372{ 372{
373 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." ); 373 qDebug( "OTCPPacket::OTCPPacket(): decoding TCP header..." );
374} 374}
375 375
376OTCPPacket::~OTCPPacket() 376OTCPPacket::~OTCPPacket()
377{ 377{
378} 378}
379 379
380 380
381/*====================================================================================== 381/*======================================================================================
382 * OPrismHeaderPacket 382 * OPrismHeaderPacket
383 *======================================================================================*/ 383 *======================================================================================*/
384 384
385 385
386OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) 386OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent )
387 :QObject( parent, "Prism" ), _header( data ) 387 :QObject( parent, "Prism" ), _header( data )
388 388
389{ 389{
390 qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." ); 390 qDebug( "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." );
391 391
392 qDebug( "Signal Strength = %d", data->signal.data ); 392 qDebug( "Signal Strength = %d", data->signal.data );
393 393
394 new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); 394 new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this );
395} 395}
396 396
397OPrismHeaderPacket::~OPrismHeaderPacket() 397OPrismHeaderPacket::~OPrismHeaderPacket()
398{ 398{
399} 399}
400 400
401 401
402unsigned int OPrismHeaderPacket::signalStrength() const 402unsigned int OPrismHeaderPacket::signalStrength() const
403{ 403{
404 return _header->signal.data; 404 return _header->signal.data;
405} 405}
406 406
407/*====================================================================================== 407/*======================================================================================
408 * OWaveLanPacket 408 * OWaveLanPacket
409 *======================================================================================*/ 409 *======================================================================================*/
410 410
411 411
412OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) 412OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent )
413 :QObject( parent, "802.11" ), _wlanhdr( data ) 413 :QObject( parent, "802.11" ), _wlanhdr( data )
414 414
415{ 415{
416 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." ); 416 qDebug( "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." );
417 qDebug( "type: %0X", type() ); 417 qDebug( "type: %0X", type() );
418 qDebug( "subType: %0X", subType() ); 418 qDebug( "subType: %0X", subType() );
419 qDebug( "duration: %d", duration() ); 419 qDebug( "duration: %d", duration() );
420 qDebug( "powermanagement: %d", usesPowerManagement() ); 420 qDebug( "powermanagement: %d", usesPowerManagement() );
421 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" ); 421 qDebug( "payload is encrypted: %s", usesWep() ? "yes" : "no" );
422 qDebug( "MAC1: %s", (const char*) macAddress1().toString() ); 422 qDebug( "MAC1: %s", (const char*) macAddress1().toString() );
423 qDebug( "MAC2: %s", (const char*) macAddress2().toString() ); 423 qDebug( "MAC2: %s", (const char*) macAddress2().toString() );
424 qDebug( "MAC3: %s", (const char*) macAddress3().toString() ); 424 qDebug( "MAC3: %s", (const char*) macAddress3().toString() );
425 qDebug( "MAC4: %s", (const char*) macAddress4().toString() ); 425 qDebug( "MAC4: %s", (const char*) macAddress4().toString() );
426 426
427 switch ( type() ) 427 switch ( type() )
428 { 428 {
429 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; 429 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
430 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; 430 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
431 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; 431 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break;
432 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); 432 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() );
433 } 433 }
434} 434}
435 435
436OWaveLanPacket::~OWaveLanPacket() 436OWaveLanPacket::~OWaveLanPacket()
437{ 437{
438} 438}
439 439
440 440
441int OWaveLanPacket::duration() const 441int OWaveLanPacket::duration() const
442{ 442{
443 return _wlanhdr->duration; 443 return _wlanhdr->duration;
444} 444}
445 445
446 446
447OMacAddress OWaveLanPacket::macAddress1() const 447OMacAddress OWaveLanPacket::macAddress1() const
448{ 448{
449 return OMacAddress( _wlanhdr->mac1 ); 449 return OMacAddress( _wlanhdr->mac1 );
450} 450}
451 451
452 452
453OMacAddress OWaveLanPacket::macAddress2() const 453OMacAddress OWaveLanPacket::macAddress2() const
454{ 454{
455 return OMacAddress( _wlanhdr->mac2 ); 455 return OMacAddress( _wlanhdr->mac2 );
456} 456}
457 457
458 458
459OMacAddress OWaveLanPacket::macAddress3() const 459OMacAddress OWaveLanPacket::macAddress3() const
460{ 460{
461 return OMacAddress( _wlanhdr->mac3 ); 461 return OMacAddress( _wlanhdr->mac3 );
462} 462}
463 463
464 464
465OMacAddress OWaveLanPacket::macAddress4() const 465OMacAddress OWaveLanPacket::macAddress4() const
466{ 466{
467 return OMacAddress( _wlanhdr->mac4 ); 467 return OMacAddress( _wlanhdr->mac4 );
468} 468}
469 469
470 470
471int OWaveLanPacket::subType() const 471int OWaveLanPacket::subType() const
472{ 472{
473 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 473 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
474} 474}
475 475
476 476
477int OWaveLanPacket::type() const 477int OWaveLanPacket::type() const
478{ 478{
479 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 479 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
480} 480}
481 481
482 482
483int OWaveLanPacket::version() const 483int OWaveLanPacket::version() const
484{ 484{
485 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 485 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
486} 486}
487 487
488 488
489bool OWaveLanPacket::fromDS() const 489bool OWaveLanPacket::fromDS() const
490{ 490{
491 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 491 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
492} 492}
493 493
494 494
495bool OWaveLanPacket::toDS() const 495bool OWaveLanPacket::toDS() const
496{ 496{
497 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 497 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
498} 498}
499 499
500 500
501bool OWaveLanPacket::usesPowerManagement() const 501bool OWaveLanPacket::usesPowerManagement() const
502{ 502{
503 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 503 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
504} 504}
505 505
506 506
507bool OWaveLanPacket::usesWep() const 507bool OWaveLanPacket::usesWep() const
508{ 508{
509 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 509 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
510} 510}
511 511
512 512
513/*====================================================================================== 513/*======================================================================================
514 * OWaveLanManagementPacket 514 * OWaveLanManagementPacket
515 *======================================================================================*/ 515 *======================================================================================*/
516 516
517OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 517OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
518 :QObject( parent, "802.11 Management" ), _header( data ), 518 :QObject( parent, "802.11 Management" ), _header( data ),
519 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 519 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
520{ 520{
521 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); 521 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." );
522 qDebug( "Detected subtype is '%s'", (const char*) managementType() ); 522 qDebug( "Detected subtype is '%s'", (const char*) managementType() );
523 523
524 // grab tagged values 524 // grab tagged values
525 const unsigned char* ptr = (const unsigned char*) (_body+1); 525 const unsigned char* ptr = (const unsigned char*) (_body+1);
526 while (ptr < end) 526 while (ptr < end)
527 { 527 {
528 switch ( *ptr ) 528 switch ( *ptr )
529 { 529 {
530 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; 530 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
531 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; 531 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
532 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; 532 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
533 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; 533 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
534 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; 534 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
535 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; 535 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
536 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; 536 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
537 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; 537 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
538 } 538 }
539 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value 539 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
540 ptr+= 2; // skip tag ID and length 540 ptr+= 2; // skip tag ID and length
541 } 541 }
542} 542}
543 543
544 544
545OWaveLanManagementPacket::~OWaveLanManagementPacket() 545OWaveLanManagementPacket::~OWaveLanManagementPacket()
546{ 546{
547} 547}
548 548
549 549
550QString OWaveLanManagementPacket::managementType() const 550QString OWaveLanManagementPacket::managementType() const
551{ 551{
552 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) 552 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
553 { 553 {
554 case ST_ASSOC_REQUEST: return "AssociationRequest"; break; 554 case ST_ASSOC_REQUEST: return "AssociationRequest"; break;
555 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; 555 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break;
556 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; 556 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break;
557 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; 557 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break;
558 case ST_PROBE_REQUEST: return "ProbeRequest"; break; 558 case ST_PROBE_REQUEST: return "ProbeRequest"; break;
559 case ST_PROBE_RESPONSE: return "ProbeResponse"; break; 559 case ST_PROBE_RESPONSE: return "ProbeResponse"; break;
560 case ST_BEACON: return "Beacon"; break; 560 case ST_BEACON: return "Beacon"; break;
561 case ST_ATIM: return "Atim"; break; 561 case ST_ATIM: return "Atim"; break;
562 case ST_DISASSOC: return "Disassociation"; break; 562 case ST_DISASSOC: return "Disassociation"; break;
563 case ST_AUTH: return "Authentication"; break; 563 case ST_AUTH: return "Authentication"; break;
564 case ST_DEAUTH: return "Deathentication"; break; 564 case ST_DEAUTH: return "Deathentication"; break;
565 default: 565 default:
566 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); 566 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) );
567 return "Unknown"; 567 return "Unknown";
568 } 568 }
569} 569}
570 570
571 571
572int OWaveLanManagementPacket::beaconInterval() const 572int OWaveLanManagementPacket::beaconInterval() const
573{ 573{
574 return EXTRACT_LE_16BITS( &_body->beacon_interval ); 574 return EXTRACT_LE_16BITS( &_body->beacon_interval );
575} 575}
576 576
577 577
578int OWaveLanManagementPacket::capabilities() const 578int OWaveLanManagementPacket::capabilities() const
579{ 579{
580 return EXTRACT_LE_16BITS( &_body->capability_info ); 580 return EXTRACT_LE_16BITS( &_body->capability_info );
581} 581}
582 582
583 583
584bool OWaveLanManagementPacket::canESS() const 584bool OWaveLanManagementPacket::canESS() const
585{ 585{
586 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 586 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
587} 587}
588 588
589 589
590bool OWaveLanManagementPacket::canIBSS() const 590bool OWaveLanManagementPacket::canIBSS() const
591{ 591{
592 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 592 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
593} 593}
594 594
595 595
596bool OWaveLanManagementPacket::canCFP() const 596bool OWaveLanManagementPacket::canCFP() const
597{ 597{
598 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); 598 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) );
599} 599}
600 600
601 601
602bool OWaveLanManagementPacket::canCFP_REQ() const 602bool OWaveLanManagementPacket::canCFP_REQ() const
603{ 603{
604 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); 604 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) );
605} 605}
606 606
607 607
608bool OWaveLanManagementPacket::canPrivacy() const 608bool OWaveLanManagementPacket::canPrivacy() const
609{ 609{
610 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); 610 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) );
611} 611}
612 612
613 613
614/*====================================================================================== 614/*======================================================================================
615 * OWaveLanManagementSSID 615 * OWaveLanManagementSSID
616 *======================================================================================*/ 616 *======================================================================================*/
617 617
618OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) 618OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
619 :QObject( parent, "802.11 SSID" ), _data( data ) 619 :QObject( parent, "802.11 SSID" ), _data( data )
620{ 620{
621 qDebug( "OWaveLanManagementSSID()" ); 621 qDebug( "OWaveLanManagementSSID()" );
622} 622}
623 623
624 624
625OWaveLanManagementSSID::~OWaveLanManagementSSID() 625OWaveLanManagementSSID::~OWaveLanManagementSSID()
626{ 626{
627} 627}
628 628
629 629
630QString OWaveLanManagementSSID::ID() const 630QString OWaveLanManagementSSID::ID() const
631{ 631{
632 int length = _data->length; 632 int length = _data->length;
633 if ( length > 32 ) length = 32; 633 if ( length > 32 ) length = 32;
634 char essid[length+1]; 634 char essid[length+1];
635 memcpy( &essid, &_data->ssid, length ); 635 memcpy( &essid, &_data->ssid, length );
636 essid[length] = 0x0; 636 essid[length] = 0x0;
637 return essid; 637 return essid;
638} 638}
639 639
640 640
641/*====================================================================================== 641/*======================================================================================
642 * OWaveLanManagementRates 642 * OWaveLanManagementRates
643 *======================================================================================*/ 643 *======================================================================================*/
644 644
645OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) 645OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
646 :QObject( parent, "802.11 Rates" ), _data( data ) 646 :QObject( parent, "802.11 Rates" ), _data( data )
647{ 647{
648 qDebug( "OWaveLanManagementRates()" ); 648 qDebug( "OWaveLanManagementRates()" );
649} 649}
650 650
651 651
652OWaveLanManagementRates::~OWaveLanManagementRates() 652OWaveLanManagementRates::~OWaveLanManagementRates()
653{ 653{
654} 654}
655 655
656/*====================================================================================== 656/*======================================================================================
657 * OWaveLanManagementCF 657 * OWaveLanManagementCF
658 *======================================================================================*/ 658 *======================================================================================*/
659 659
660OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) 660OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
661 :QObject( parent, "802.11 CF" ), _data( data ) 661 :QObject( parent, "802.11 CF" ), _data( data )
662{ 662{
663 qDebug( "OWaveLanManagementCF()" ); 663 qDebug( "OWaveLanManagementCF()" );
664} 664}
665 665
666 666
667OWaveLanManagementCF::~OWaveLanManagementCF() 667OWaveLanManagementCF::~OWaveLanManagementCF()
668{ 668{
669} 669}
670 670
671/*====================================================================================== 671/*======================================================================================
672 * OWaveLanManagementFH 672 * OWaveLanManagementFH
673 *======================================================================================*/ 673 *======================================================================================*/
674 674
675OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) 675OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
676 :QObject( parent, "802.11 FH" ), _data( data ) 676 :QObject( parent, "802.11 FH" ), _data( data )
677{ 677{
678 qDebug( "OWaveLanManagementFH()" ); 678 qDebug( "OWaveLanManagementFH()" );
679} 679}
680 680
681 681
682OWaveLanManagementFH::~OWaveLanManagementFH() 682OWaveLanManagementFH::~OWaveLanManagementFH()
683{ 683{
684} 684}
685 685
686/*====================================================================================== 686/*======================================================================================
687 * OWaveLanManagementDS 687 * OWaveLanManagementDS
688 *======================================================================================*/ 688 *======================================================================================*/
689 689
690OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) 690OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
691 :QObject( parent, "802.11 DS" ), _data( data ) 691 :QObject( parent, "802.11 DS" ), _data( data )
692{ 692{
693 qDebug( "OWaveLanManagementDS()" ); 693 qDebug( "OWaveLanManagementDS()" );
694} 694}
695 695
696 696
697OWaveLanManagementDS::~OWaveLanManagementDS() 697OWaveLanManagementDS::~OWaveLanManagementDS()
698{ 698{
699} 699}
700 700
701 701
702int OWaveLanManagementDS::channel() const 702int OWaveLanManagementDS::channel() const
703{ 703{
704 return _data->channel; 704 return _data->channel;
705} 705}
706 706
707/*====================================================================================== 707/*======================================================================================
708 * OWaveLanManagementTim 708 * OWaveLanManagementTim
709 *======================================================================================*/ 709 *======================================================================================*/
710 710
711OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) 711OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
712 :QObject( parent, "802.11 Tim" ), _data( data ) 712 :QObject( parent, "802.11 Tim" ), _data( data )
713{ 713{
714 qDebug( "OWaveLanManagementTim()" ); 714 qDebug( "OWaveLanManagementTim()" );
715} 715}
716 716
717 717
718OWaveLanManagementTim::~OWaveLanManagementTim() 718OWaveLanManagementTim::~OWaveLanManagementTim()
719{ 719{
720} 720}
721 721
722/*====================================================================================== 722/*======================================================================================
723 * OWaveLanManagementIBSS 723 * OWaveLanManagementIBSS
724 *======================================================================================*/ 724 *======================================================================================*/
725 725
726OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) 726OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
727 :QObject( parent, "802.11 IBSS" ), _data( data ) 727 :QObject( parent, "802.11 IBSS" ), _data( data )
728{ 728{
729 qDebug( "OWaveLanManagementIBSS()" ); 729 qDebug( "OWaveLanManagementIBSS()" );
730} 730}
731 731
732 732
733OWaveLanManagementIBSS::~OWaveLanManagementIBSS() 733OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
734{ 734{
735} 735}
736 736
737/*====================================================================================== 737/*======================================================================================
738 * OWaveLanManagementChallenge 738 * OWaveLanManagementChallenge
739 *======================================================================================*/ 739 *======================================================================================*/
740 740
741OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) 741OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
742 :QObject( parent, "802.11 Challenge" ), _data( data ) 742 :QObject( parent, "802.11 Challenge" ), _data( data )
743{ 743{
744 qDebug( "OWaveLanManagementChallenge()" ); 744 qDebug( "OWaveLanManagementChallenge()" );
745} 745}
746 746
747 747
748OWaveLanManagementChallenge::~OWaveLanManagementChallenge() 748OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
749{ 749{
750} 750}
751 751
752/*====================================================================================== 752/*======================================================================================
753 * OWaveLanDataPacket 753 * OWaveLanDataPacket
754 *======================================================================================*/ 754 *======================================================================================*/
755 755
756OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 756OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
757 :QObject( parent, "802.11 Data" ), _header( data ) 757 :QObject( parent, "802.11 Data" ), _header( data )
758{ 758{
759 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); 759 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." );
760 760
761 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 761 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
762 762
763 #warning The next line works for most cases, but can not be correct generally! 763 #warning The next line works for most cases, but can not be correct generally!
764 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 764 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
765 765
766 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); 766 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
767} 767}
768 768
769 769
770OWaveLanDataPacket::~OWaveLanDataPacket() 770OWaveLanDataPacket::~OWaveLanDataPacket()
771{ 771{
772} 772}
773 773
774 774
775/*====================================================================================== 775/*======================================================================================
776 * OLLCPacket 776 * OLLCPacket
777 *======================================================================================*/ 777 *======================================================================================*/
778 778
779OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 779OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
780 :QObject( parent, "802.11 LLC" ), _header( data ) 780 :QObject( parent, "802.11 LLC" ), _header( data )
781{ 781{
782 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 782 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
783 783
784 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 784 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
785 { 785 {
786 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 786 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
787 787
788 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 788 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
789 { 789 {
790 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 790 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
791 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; 791 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
792 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 792 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) );
793 } 793 }
794 794
795 } 795 }
796} 796}
797 797
798 798
799OLLCPacket::~OLLCPacket() 799OLLCPacket::~OLLCPacket()
800{ 800{
801} 801}
802 802
803 803
804/*====================================================================================== 804/*======================================================================================
805 * OWaveLanControlPacket 805 * OWaveLanControlPacket
806 *======================================================================================*/ 806 *======================================================================================*/
807 807
808OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) 808OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
809 :QObject( parent, "802.11 Data" ), _header( data ) 809 :QObject( parent, "802.11 Control" ), _header( data )
810{ 810{
811 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); 811 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
812 //TODO: Implement this 812 //TODO: Implement this
813} 813}
814 814
815 815
816OWaveLanControlPacket::~OWaveLanControlPacket() 816OWaveLanControlPacket::~OWaveLanControlPacket()
817{ 817{
818} 818}
819 819
820 820
821/*====================================================================================== 821/*======================================================================================
822 * OPacketCapturer 822 * OPacketCapturer
823 *======================================================================================*/ 823 *======================================================================================*/
824 824
825OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 825OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
826 :QObject( parent, name ), _name( QString::null ), _open( false ), 826 :QObject( parent, name ), _name( QString::null ), _open( false ),
827 _pch( 0 ), _pcd( 0 ), _sn( 0 ) 827 _pch( 0 ), _pcd( 0 ), _sn( 0 )
828{ 828{
829} 829}
830 830
831 831
832OPacketCapturer::~OPacketCapturer() 832OPacketCapturer::~OPacketCapturer()
833{ 833{
834 if ( _open ) 834 if ( _open )
835 { 835 {
836 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 836 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
837 close(); 837 close();
838 } 838 }
839} 839}
840 840
841 841
842void OPacketCapturer::setBlocking( bool b ) 842void OPacketCapturer::setBlocking( bool b )
843{ 843{
844 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 844 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
845 { 845 {
846 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 846 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
847 } 847 }
848 else 848 else
849 { 849 {
850 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 850 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
851 } 851 }
852} 852}
853 853
854 854
855bool OPacketCapturer::blocking() const 855bool OPacketCapturer::blocking() const
856{ 856{
857 int b = pcap_getnonblock( _pch, _errbuf ); 857 int b = pcap_getnonblock( _pch, _errbuf );
858 if ( b == -1 ) 858 if ( b == -1 )
859 { 859 {
860 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 860 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
861 return -1; 861 return -1;
862 } 862 }
863 return !b; 863 return !b;
864} 864}
865 865
866 866
867void OPacketCapturer::close() 867void OPacketCapturer::close()
868{ 868{
869 if ( _open ) 869 if ( _open )
870 { 870 {
871 if ( _sn ) 871 if ( _sn )
872 { 872 {
873 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 873 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
874 delete _sn; 874 delete _sn;
875 } 875 }
876 if ( _pcd ) 876 if ( _pcd )
877 { 877 {
878 pcap_dump_close( _pcd ); 878 pcap_dump_close( _pcd );
879 _pcd = 0; 879 _pcd = 0;
880 } 880 }
881 pcap_close( _pch ); 881 pcap_close( _pch );
882 _open = false; 882 _open = false;
883 } 883 }
884 884
885 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 885 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
886 qDebug( "--------------------------------------------------" ); 886 qDebug( "--------------------------------------------------" );
887 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 887 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
888 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 888 qDebug( "%s : %d", (const char*) it.key(), it.data() );
889 qDebug( "--------------------------------------------------" ); 889 qDebug( "--------------------------------------------------" );
890 890
891} 891}
892 892
893 893
894int OPacketCapturer::dataLink() const 894int OPacketCapturer::dataLink() const
895{ 895{
896 return pcap_datalink( _pch ); 896 return pcap_datalink( _pch );
897} 897}
898 898
899 899
900int OPacketCapturer::fileno() const 900int OPacketCapturer::fileno() const
901{ 901{
902 if ( _open ) 902 if ( _open )
903 { 903 {
904 return pcap_fileno( _pch ); 904 return pcap_fileno( _pch );
905 } 905 }
906 else 906 else
907 { 907 {
908 return -1; 908 return -1;
909 } 909 }
910} 910}
911 911
912OPacket* OPacketCapturer::next() 912OPacket* OPacketCapturer::next()
913{ 913{
914 packetheaderstruct header; 914 packetheaderstruct header;
915 qDebug( "==> OPacketCapturer::next()" ); 915 qDebug( "==> OPacketCapturer::next()" );
916 const unsigned char* pdata = pcap_next( _pch, &header ); 916 const unsigned char* pdata = pcap_next( _pch, &header );
917 qDebug( "<== OPacketCapturer::next()" ); 917 qDebug( "<== OPacketCapturer::next()" );
918 if ( _pcd ) 918 if ( _pcd )
919 pcap_dump( (u_char*) _pcd, &header, pdata ); 919 pcap_dump( (u_char*) _pcd, &header, pdata );
920 920
921 if ( pdata && header.len ) 921 if ( pdata && header.len )
922 { 922 {
923 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 923 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
924 // packets shouldn't be inserted in the QObject child-parent hierarchy, 924 // packets shouldn't be inserted in the QObject child-parent hierarchy,
925 // because due to memory constraints they will be deleted as soon 925 // because due to memory constraints they will be deleted as soon
926 // as possible - that is right after they have been processed 926 // as possible - that is right after they have been processed
927 // by emit() [ see below ] 927 // by emit() [ see below ]
928 //TODO: make gathering statistics optional, because it takes time 928 //TODO: make gathering statistics optional, because it takes time
929 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 929 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
930 930
931 return p; 931 return p;
932 } 932 }
933 else 933 else
934 { 934 {
935 qWarning( "OPacketCapturer::next() - no packet received!" ); 935 qWarning( "OPacketCapturer::next() - no packet received!" );
936 return 0; 936 return 0;
937 } 937 }
938} 938}
939 939
940 940
941bool OPacketCapturer::open( const QString& name, const QString& filename ) 941bool OPacketCapturer::open( const QString& name, const QString& filename )
942{ 942{
943 if ( _open ) 943 if ( _open )
944 { 944 {
945 if ( name == _name ) // ignore opening an already openend device 945 if ( name == _name ) // ignore opening an already openend device
946 { 946 {
947 return true; 947 return true;
948 } 948 }
949 else // close the last opened device 949 else // close the last opened device
950 { 950 {
951 close(); 951 close();
952 } 952 }
953 } 953 }
954 954
955 _name = name; 955 _name = name;
956 956
957 // open libpcap 957 // open libpcap
958 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 958 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
959 959
960 if ( !handle ) 960 if ( !handle )
961 { 961 {
962 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 962 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
963 return false; 963 return false;
964 } 964 }
965 965
966 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 966 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
967 _pch = handle; 967 _pch = handle;
968 _open = true; 968 _open = true;
969 _stats.clear(); 969 _stats.clear();
970 970
971 // in case we have an application object, create a socket notifier 971 // in case we have an application object, create a socket notifier
972 if ( qApp ) //TODO: I don't like this here... 972 if ( qApp ) //TODO: I don't like this here...
973 { 973 {
974 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 974 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
975 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 975 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
976 } 976 }
977 977
978 // if requested, open a dump 978 // if requested, open a dump
979 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 979 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
980 if ( !dump ) 980 if ( !dump )
981 { 981 {
982 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 982 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
983 return false; 983 return false;
984 } 984 }
985 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); 985 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
986 _pcd = dump; 986 _pcd = dump;
987 987
988 return true; 988 return true;
989} 989}
990 990
991 991
992bool OPacketCapturer::open( const QFile& file ) 992bool OPacketCapturer::open( const QFile& file )
993{ 993{
994 QString name = file.name(); 994 QString name = file.name();
995 995
996 if ( _open ) 996 if ( _open )
997 { 997 {
998 close(); 998 close();
999 if ( name == _name ) // ignore opening an already openend device 999 if ( name == _name ) // ignore opening an already openend device
1000 { 1000 {
1001 return true; 1001 return true;
1002 } 1002 }
1003 else // close the last opened device 1003 else // close the last opened device
1004 { 1004 {
1005 close(); 1005 close();
1006 } 1006 }
1007 } 1007 }
1008 1008
1009 _name = name; 1009 _name = name;
1010 1010
1011 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); 1011 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
1012 1012
1013 if ( handle ) 1013 if ( handle )
1014 { 1014 {
1015 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 1015 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
1016 _pch = handle; 1016 _pch = handle;
1017 _open = true; 1017 _open = true;
1018 1018
1019 // in case we have an application object, create a socket notifier 1019 // in case we have an application object, create a socket notifier
1020 if ( qApp ) 1020 if ( qApp )
1021 { 1021 {
1022 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1022 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1023 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1023 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1024 } 1024 }
1025 1025
1026 return true; 1026 return true;
1027 } 1027 }
1028 else 1028 else
1029 { 1029 {
1030 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1030 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1031 return false; 1031 return false;
1032 } 1032 }
1033 1033
1034} 1034}
1035 1035
1036 1036
1037bool OPacketCapturer::isOpen() const 1037bool OPacketCapturer::isOpen() const
1038{ 1038{
1039 return _open; 1039 return _open;
1040} 1040}
1041 1041
1042 1042
1043void OPacketCapturer::readyToReceive() 1043void OPacketCapturer::readyToReceive()
1044{ 1044{
1045 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); 1045 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" );
1046 OPacket* p = next(); 1046 OPacket* p = next();
1047 emit receivedPacket( p ); 1047 emit receivedPacket( p );
1048 // emit is synchronous - packet has been dealt with, now it's safe to delete 1048 // emit is synchronous - packet has been dealt with, now it's safe to delete
1049 delete p; 1049 delete p;
1050} 1050}
1051 1051
1052 1052
1053const QMap<QString,int>& OPacketCapturer::statistics() const 1053const QMap<QString,int>& OPacketCapturer::statistics() const
1054{ 1054{
1055 return _stats; 1055 return _stats;
1056} 1056}
1057 1057