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