author | mickeyl <mickeyl> | 2004-04-07 09:49:19 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-04-07 09:49:19 (UTC) |
commit | ab892edccddb983b844065e2a13b15ecaecefbbd (patch) (unidiff) | |
tree | 1fea3f8f6aee0246295d226168c49ec3193e6622 | |
parent | 837069ed5f048c99774c88f2ad05a057a0b76ce8 (diff) | |
download | opie-ab892edccddb983b844065e2a13b15ecaecefbbd.zip opie-ab892edccddb983b844065e2a13b15ecaecefbbd.tar.gz opie-ab892edccddb983b844065e2a13b15ecaecefbbd.tar.bz2 |
copy data handed over by libpcap because libpcap reuses the data area
-rw-r--r-- | libopie2/opienet/opcap.cpp | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp index 93176c0..067d6b7 100644 --- a/libopie2/opienet/opcap.cpp +++ b/libopie2/opienet/opcap.cpp | |||
@@ -1,860 +1,863 @@ | |||
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-2004 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 | #include "udp_ports.h" | ||
32 | #include "opcap.h" | ||
33 | |||
31 | /* OPIE */ | 34 | /* OPIE */ |
32 | #include <opie2/opcap.h> | ||
33 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | using namespace Opie::Core; | ||
34 | 37 | ||
35 | /* QT */ | 38 | /* QT */ |
36 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) | 39 | #include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) |
37 | #include <qsocketnotifier.h> | 40 | #include <qsocketnotifier.h> |
38 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
39 | 42 | ||
40 | /* SYSTEM */ | 43 | /* STD */ |
41 | #include <sys/time.h> | 44 | #include <sys/time.h> |
42 | #include <sys/types.h> | 45 | #include <sys/types.h> |
46 | #include <assert.h> | ||
43 | #include <unistd.h> | 47 | #include <unistd.h> |
44 | 48 | #include <string.h> | |
45 | /* LOCAL */ | ||
46 | #include "udp_ports.h" | ||
47 | |||
48 | using namespace Opie::Core; | ||
49 | 49 | ||
50 | namespace Opie { | 50 | namespace Opie { |
51 | namespace Net { | 51 | namespace Net { |
52 | 52 | ||
53 | /*====================================================================================== | 53 | /*====================================================================================== |
54 | * OPacket | 54 | * OPacket |
55 | *======================================================================================*/ | 55 | *======================================================================================*/ |
56 | 56 | ||
57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) |
58 | :QObject( parent, "Generic" ), _hdr( header ), _data( data ) | 58 | :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) |
59 | { | 59 | { |
60 | //FIXME: Copy the data structure here, because it isn't persistent. Check that. | ||
61 | |||
62 | qDebug( "OPacket::OPacket(): (Len %d, CapLen %d)" /*, ctime((const time_t*) header.ts.tv_sec)*/, header.len, header.caplen ); | ||
63 | 60 | ||
64 | _end = (unsigned char*) data + header.len; | 61 | _data = new unsigned char[sizeof data]; |
65 | //qDebug( "OPacket::data @ %0x, end @ %0x", data, _end ); | 62 | assert( _data ); |
63 | memcpy( const_cast<unsigned char*>(_data), data, sizeof data ); | ||
64 | // We have to copy the data structure here, because the 'data' pointer handed by libpcap | ||
65 | // points to an internal region which is reused by lipcap. | ||
66 | odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; | ||
67 | _end = (unsigned char*) _data + header.len; | ||
66 | 68 | ||
67 | switch ( datalink ) | 69 | switch ( datalink ) |
68 | { | 70 | { |
69 | case DLT_EN10MB: | 71 | case DLT_EN10MB: |
70 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; | 72 | odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; |
71 | new OEthernetPacket( _end, (const struct ether_header*) data, this ); | 73 | new OEthernetPacket( _end, (const struct ether_header*) _data, this ); |
72 | break; | 74 | break; |
73 | 75 | ||
74 | case DLT_IEEE802_11: | 76 | case DLT_IEEE802_11: |
75 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; | 77 | odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; |
76 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) data, this ); | 78 | new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); |
77 | break; | 79 | break; |
78 | 80 | ||
79 | case DLT_PRISM_HEADER: | 81 | case DLT_PRISM_HEADER: |
80 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; | 82 | odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; |
81 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) data, this ); | 83 | new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); |
82 | break; | 84 | break; |
83 | 85 | ||
84 | default: | 86 | default: |
85 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; | 87 | owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; |
86 | } | 88 | } |
87 | } | 89 | } |
88 | 90 | ||
89 | 91 | ||
90 | OPacket::~OPacket() | 92 | OPacket::~OPacket() |
91 | { | 93 | { |
92 | qDebug( "OPacket::~OPacket( %s )", name() ); | 94 | odebug << "~OPacket( " << name() << " )" << oendl; |
95 | delete _data; | ||
93 | } | 96 | } |
94 | 97 | ||
95 | 98 | ||
96 | timevalstruct OPacket::timeval() const | 99 | timevalstruct OPacket::timeval() const |
97 | { | 100 | { |
98 | return _hdr.ts; | 101 | return _hdr.ts; |
99 | } | 102 | } |
100 | 103 | ||
101 | 104 | ||
102 | int OPacket::caplen() const | 105 | int OPacket::caplen() const |
103 | { | 106 | { |
104 | return _hdr.caplen; | 107 | return _hdr.caplen; |
105 | } | 108 | } |
106 | 109 | ||
107 | 110 | ||
108 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) | 111 | void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) |
109 | { | 112 | { |
110 | if (!l) return; | 113 | if (!l) return; |
111 | QObject* o = l->first(); | 114 | QObject* o = l->first(); |
112 | while ( o ) | 115 | while ( o ) |
113 | { | 116 | { |
114 | stats[o->name()]++; | 117 | stats[o->name()]++; |
115 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); | 118 | updateStats( stats, const_cast<QObjectList*>( o->children() ) ); |
116 | o = l->next(); | 119 | o = l->next(); |
117 | } | 120 | } |
118 | } | 121 | } |
119 | 122 | ||
120 | 123 | ||
121 | QString OPacket::dumpStructure() const | 124 | QString OPacket::dumpStructure() const |
122 | { | 125 | { |
123 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; | 126 | return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; |
124 | } | 127 | } |
125 | 128 | ||
126 | 129 | ||
127 | QString OPacket::_dumpStructure( QObjectList* l ) const | 130 | QString OPacket::_dumpStructure( QObjectList* l ) const |
128 | { | 131 | { |
129 | if (!l) return QString::null; | 132 | if (!l) return QString::null; |
130 | QObject* o = l->first(); | 133 | QObject* o = l->first(); |
131 | QString str(" "); | 134 | QString str(" "); |
132 | 135 | ||
133 | while ( o ) | 136 | while ( o ) |
134 | { | 137 | { |
135 | str.append( o->name() ); | 138 | str.append( o->name() ); |
136 | str.append( " |" ); | 139 | str.append( " |" ); |
137 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); | 140 | str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); |
138 | o = l->next(); | 141 | o = l->next(); |
139 | } | 142 | } |
140 | return str; | 143 | return str; |
141 | } | 144 | } |
142 | 145 | ||
143 | QString OPacket::dump( int bpl ) const | 146 | QString OPacket::dump( int bpl ) const |
144 | { | 147 | { |
145 | static int index = 0; | 148 | static int index = 0; |
146 | index++; | 149 | index++; |
147 | int len = _hdr.caplen; | 150 | int len = _hdr.caplen; |
148 | QString str; | 151 | QString str; |
149 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); | 152 | str.sprintf( "\n<----- Packet #%04d Len = 0x%X (%d) ----->\n\n", index, len, len ); |
150 | str.append( "0000: " ); | 153 | str.append( "0000: " ); |
151 | QString tmp; | 154 | QString tmp; |
152 | QString bytes; | 155 | QString bytes; |
153 | QString chars; | 156 | QString chars; |
154 | 157 | ||
155 | for ( int i = 0; i < len; ++i ) | 158 | for ( int i = 0; i < len; ++i ) |
156 | { | 159 | { |
157 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); | 160 | tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); |
158 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); | 161 | if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); |
159 | else chars.append( '.' ); | 162 | else chars.append( '.' ); |
160 | 163 | ||
161 | if ( !((i+1) % bpl) ) | 164 | if ( !((i+1) % bpl) ) |
162 | { | 165 | { |
163 | str.append( bytes ); | 166 | str.append( bytes ); |
164 | str.append( ' ' ); | 167 | str.append( ' ' ); |
165 | str.append( chars ); | 168 | str.append( chars ); |
166 | str.append( '\n' ); | 169 | str.append( '\n' ); |
167 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); | 170 | tmp.sprintf( "%04X: ", i+1 ); str.append( tmp ); |
168 | bytes = ""; | 171 | bytes = ""; |
169 | chars = ""; | 172 | chars = ""; |
170 | } | 173 | } |
171 | 174 | ||
172 | } | 175 | } |
173 | if ( (len % bpl) ) | 176 | if ( (len % bpl) ) |
174 | { | 177 | { |
175 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); | 178 | str.append( bytes.leftJustify( 1 + 3*bpl ) ); |
176 | str.append( chars ); | 179 | str.append( chars ); |
177 | } | 180 | } |
178 | str.append( '\n' ); | 181 | str.append( '\n' ); |
179 | return str; | 182 | return str; |
180 | } | 183 | } |
181 | 184 | ||
182 | 185 | ||
183 | int OPacket::len() const | 186 | int OPacket::len() const |
184 | { | 187 | { |
185 | return _hdr.len; | 188 | return _hdr.len; |
186 | } | 189 | } |
187 | 190 | ||
188 | 191 | ||
189 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) | 192 | QTextStream& operator<<( QTextStream& s, const OPacket& p ) |
190 | { | 193 | { |
191 | s << p.dumpStructure(); | 194 | s << p.dumpStructure(); |
192 | } | 195 | } |
193 | 196 | ||
194 | 197 | ||
195 | /*====================================================================================== | 198 | /*====================================================================================== |
196 | * OEthernetPacket | 199 | * OEthernetPacket |
197 | *======================================================================================*/ | 200 | *======================================================================================*/ |
198 | 201 | ||
199 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) | 202 | OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) |
200 | :QObject( parent, "Ethernet" ), _ether( data ) | 203 | :QObject( parent, "Ethernet" ), _ether( data ) |
201 | { | 204 | { |
202 | 205 | ||
203 | odebug << "Source = " << sourceAddress().toString(); | 206 | odebug << "Source = " << sourceAddress().toString(); |
204 | odebug << "Destination = " << destinationAddress().toString(); | 207 | odebug << "Destination = " << destinationAddress().toString(); |
205 | 208 | ||
206 | if ( sourceAddress() == OMacAddress::broadcast ) | 209 | if ( sourceAddress() == OMacAddress::broadcast ) |
207 | odebug << "Source is broadcast address" << oendl; | 210 | odebug << "Source is broadcast address" << oendl; |
208 | if ( destinationAddress() == OMacAddress::broadcast ) | 211 | if ( destinationAddress() == OMacAddress::broadcast ) |
209 | odebug << "Destination is broadcast address" << oendl; | 212 | odebug << "Destination is broadcast address" << oendl; |
210 | 213 | ||
211 | switch ( type() ) | 214 | switch ( type() ) |
212 | { | 215 | { |
213 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; | 216 | case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; |
214 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; | 217 | case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; |
215 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } | 218 | case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } |
216 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; | 219 | default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; |
217 | } | 220 | } |
218 | 221 | ||
219 | } | 222 | } |
220 | 223 | ||
221 | 224 | ||
222 | OEthernetPacket::~OEthernetPacket() | 225 | OEthernetPacket::~OEthernetPacket() |
223 | { | 226 | { |
224 | } | 227 | } |
225 | 228 | ||
226 | 229 | ||
227 | OMacAddress OEthernetPacket::sourceAddress() const | 230 | OMacAddress OEthernetPacket::sourceAddress() const |
228 | { | 231 | { |
229 | return OMacAddress( _ether->ether_shost ); | 232 | return OMacAddress( _ether->ether_shost ); |
230 | } | 233 | } |
231 | 234 | ||
232 | 235 | ||
233 | OMacAddress OEthernetPacket::destinationAddress() const | 236 | OMacAddress OEthernetPacket::destinationAddress() const |
234 | { | 237 | { |
235 | return OMacAddress( _ether->ether_dhost ); | 238 | return OMacAddress( _ether->ether_dhost ); |
236 | } | 239 | } |
237 | 240 | ||
238 | int OEthernetPacket::type() const | 241 | int OEthernetPacket::type() const |
239 | { | 242 | { |
240 | return ntohs( _ether->ether_type ); | 243 | return ntohs( _ether->ether_type ); |
241 | } | 244 | } |
242 | 245 | ||
243 | 246 | ||
244 | /*====================================================================================== | 247 | /*====================================================================================== |
245 | * OIPPacket | 248 | * OIPPacket |
246 | *======================================================================================*/ | 249 | *======================================================================================*/ |
247 | 250 | ||
248 | 251 | ||
249 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) | 252 | OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) |
250 | :QObject( parent, "IP" ), _iphdr( data ) | 253 | :QObject( parent, "IP" ), _iphdr( data ) |
251 | { | 254 | { |
252 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; | 255 | odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; |
253 | 256 | ||
254 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; | 257 | odebug << "FromAddress = " << fromIPAddress().toString() << oendl; |
255 | odebug << " toAddress = " << toIPAddress().toString() << oendl; | 258 | odebug << " toAddress = " << toIPAddress().toString() << oendl; |
256 | 259 | ||
257 | switch ( protocol() ) | 260 | switch ( protocol() ) |
258 | { | 261 | { |
259 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; | 262 | case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; |
260 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; | 263 | case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; |
261 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; | 264 | default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; |
262 | } | 265 | } |
263 | 266 | ||
264 | } | 267 | } |
265 | 268 | ||
266 | OIPPacket::~OIPPacket() | 269 | OIPPacket::~OIPPacket() |
267 | { | 270 | { |
268 | } | 271 | } |
269 | 272 | ||
270 | 273 | ||
271 | QHostAddress OIPPacket::fromIPAddress() const | 274 | QHostAddress OIPPacket::fromIPAddress() const |
272 | { | 275 | { |
273 | return EXTRACT_32BITS( &_iphdr->saddr ); | 276 | return EXTRACT_32BITS( &_iphdr->saddr ); |
274 | } | 277 | } |
275 | 278 | ||
276 | 279 | ||
277 | QHostAddress OIPPacket::toIPAddress() const | 280 | QHostAddress OIPPacket::toIPAddress() const |
278 | { | 281 | { |
279 | return EXTRACT_32BITS( &_iphdr->saddr ); | 282 | return EXTRACT_32BITS( &_iphdr->saddr ); |
280 | } | 283 | } |
281 | 284 | ||
282 | 285 | ||
283 | int OIPPacket::tos() const | 286 | int OIPPacket::tos() const |
284 | { | 287 | { |
285 | return _iphdr->tos; | 288 | return _iphdr->tos; |
286 | } | 289 | } |
287 | 290 | ||
288 | 291 | ||
289 | int OIPPacket::len() const | 292 | int OIPPacket::len() const |
290 | { | 293 | { |
291 | return EXTRACT_16BITS( &_iphdr->tot_len ); | 294 | return EXTRACT_16BITS( &_iphdr->tot_len ); |
292 | } | 295 | } |
293 | 296 | ||
294 | 297 | ||
295 | int OIPPacket::id() const | 298 | int OIPPacket::id() const |
296 | { | 299 | { |
297 | return EXTRACT_16BITS( &_iphdr->id ); | 300 | return EXTRACT_16BITS( &_iphdr->id ); |
298 | } | 301 | } |
299 | 302 | ||
300 | 303 | ||
301 | int OIPPacket::offset() const | 304 | int OIPPacket::offset() const |
302 | { | 305 | { |
303 | return EXTRACT_16BITS( &_iphdr->frag_off ); | 306 | return EXTRACT_16BITS( &_iphdr->frag_off ); |
304 | } | 307 | } |
305 | 308 | ||
306 | 309 | ||
307 | int OIPPacket::ttl() const | 310 | int OIPPacket::ttl() const |
308 | { | 311 | { |
309 | return _iphdr->ttl; | 312 | return _iphdr->ttl; |
310 | } | 313 | } |
311 | 314 | ||
312 | 315 | ||
313 | int OIPPacket::protocol() const | 316 | int OIPPacket::protocol() const |
314 | { | 317 | { |
315 | return _iphdr->protocol; | 318 | return _iphdr->protocol; |
316 | } | 319 | } |
317 | 320 | ||
318 | 321 | ||
319 | int OIPPacket::checksum() const | 322 | int OIPPacket::checksum() const |
320 | { | 323 | { |
321 | return EXTRACT_16BITS( &_iphdr->check ); | 324 | return EXTRACT_16BITS( &_iphdr->check ); |
322 | } | 325 | } |
323 | 326 | ||
324 | /*====================================================================================== | 327 | /*====================================================================================== |
325 | * OARPPacket | 328 | * OARPPacket |
326 | *======================================================================================*/ | 329 | *======================================================================================*/ |
327 | 330 | ||
328 | 331 | ||
329 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) | 332 | OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) |
330 | :QObject( parent, "ARP" ), _arphdr( data ) | 333 | :QObject( parent, "ARP" ), _arphdr( data ) |
331 | { | 334 | { |
332 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; | 335 | odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; |
333 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; | 336 | odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; |
334 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; | 337 | odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; |
335 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; | 338 | odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; |
336 | } | 339 | } |
337 | 340 | ||
338 | 341 | ||
339 | OARPPacket::~OARPPacket() | 342 | OARPPacket::~OARPPacket() |
340 | { | 343 | { |
341 | } | 344 | } |
342 | 345 | ||
343 | 346 | ||
344 | QString OARPPacket::type() const | 347 | QString OARPPacket::type() const |
345 | { | 348 | { |
346 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) | 349 | switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) |
347 | { | 350 | { |
348 | case 1: return "REQUEST"; | 351 | case 1: return "REQUEST"; |
349 | case 2: return "REPLY"; | 352 | case 2: return "REPLY"; |
350 | case 3: return "RREQUEST"; | 353 | case 3: return "RREQUEST"; |
351 | case 4: return "RREPLY"; | 354 | case 4: return "RREPLY"; |
352 | case 8: return "InREQUEST"; | 355 | case 8: return "InREQUEST"; |
353 | case 9: return "InREPLY"; | 356 | case 9: return "InREPLY"; |
354 | case 10: return "NAK"; | 357 | case 10: return "NAK"; |
355 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; | 358 | default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; |
356 | } | 359 | } |
357 | } | 360 | } |
358 | 361 | ||
359 | 362 | ||
360 | QHostAddress OARPPacket::senderIPV4Address() const | 363 | QHostAddress OARPPacket::senderIPV4Address() const |
361 | { | 364 | { |
362 | return EXTRACT_32BITS( &_arphdr->ar_sip ); | 365 | return EXTRACT_32BITS( &_arphdr->ar_sip ); |
363 | } | 366 | } |
364 | 367 | ||
365 | 368 | ||
366 | QHostAddress OARPPacket::targetIPV4Address() const | 369 | QHostAddress OARPPacket::targetIPV4Address() const |
367 | { | 370 | { |
368 | return EXTRACT_32BITS( &_arphdr->ar_tip ); | 371 | return EXTRACT_32BITS( &_arphdr->ar_tip ); |
369 | } | 372 | } |
370 | 373 | ||
371 | 374 | ||
372 | OMacAddress OARPPacket::senderMacAddress() const | 375 | OMacAddress OARPPacket::senderMacAddress() const |
373 | { | 376 | { |
374 | return OMacAddress( _arphdr->ar_sha ); | 377 | return OMacAddress( _arphdr->ar_sha ); |
375 | } | 378 | } |
376 | 379 | ||
377 | 380 | ||
378 | OMacAddress OARPPacket::targetMacAddress() const | 381 | OMacAddress OARPPacket::targetMacAddress() const |
379 | { | 382 | { |
380 | return OMacAddress( _arphdr->ar_tha ); | 383 | return OMacAddress( _arphdr->ar_tha ); |
381 | } | 384 | } |
382 | 385 | ||
383 | 386 | ||
384 | /*====================================================================================== | 387 | /*====================================================================================== |
385 | * OUDPPacket | 388 | * OUDPPacket |
386 | *======================================================================================*/ | 389 | *======================================================================================*/ |
387 | 390 | ||
388 | 391 | ||
389 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) | 392 | OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) |
390 | :QObject( parent, "UDP" ), _udphdr( data ) | 393 | :QObject( parent, "UDP" ), _udphdr( data ) |
391 | 394 | ||
392 | { | 395 | { |
393 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; | 396 | odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; |
394 | odebug << "fromPort = " << fromPort() << oendl; | 397 | odebug << "fromPort = " << fromPort() << oendl; |
395 | odebug << " toPort = " << toPort() << oendl; | 398 | odebug << " toPort = " << toPort() << oendl; |
396 | 399 | ||
397 | // TODO: Make this a case or a hash if we know more udp protocols | 400 | // TODO: Make this a case or a hash if we know more udp protocols |
398 | 401 | ||
399 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || | 402 | if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || |
400 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) | 403 | toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) |
401 | { | 404 | { |
402 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; | 405 | odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; |
403 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); | 406 | new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); |
404 | } | 407 | } |
405 | } | 408 | } |
406 | 409 | ||
407 | 410 | ||
408 | OUDPPacket::~OUDPPacket() | 411 | OUDPPacket::~OUDPPacket() |
409 | { | 412 | { |
410 | } | 413 | } |
411 | 414 | ||
412 | 415 | ||
413 | int OUDPPacket::fromPort() const | 416 | int OUDPPacket::fromPort() const |
414 | { | 417 | { |
415 | return EXTRACT_16BITS( &_udphdr->source ); | 418 | return EXTRACT_16BITS( &_udphdr->source ); |
416 | } | 419 | } |
417 | 420 | ||
418 | 421 | ||
419 | int OUDPPacket::toPort() const | 422 | int OUDPPacket::toPort() const |
420 | { | 423 | { |
421 | return EXTRACT_16BITS( &_udphdr->dest ); | 424 | return EXTRACT_16BITS( &_udphdr->dest ); |
422 | } | 425 | } |
423 | 426 | ||
424 | 427 | ||
425 | int OUDPPacket::length() const | 428 | int OUDPPacket::length() const |
426 | { | 429 | { |
427 | return EXTRACT_16BITS( &_udphdr->len ); | 430 | return EXTRACT_16BITS( &_udphdr->len ); |
428 | } | 431 | } |
429 | 432 | ||
430 | 433 | ||
431 | int OUDPPacket::checksum() const | 434 | int OUDPPacket::checksum() const |
432 | { | 435 | { |
433 | return EXTRACT_16BITS( &_udphdr->check ); | 436 | return EXTRACT_16BITS( &_udphdr->check ); |
434 | } | 437 | } |
435 | 438 | ||
436 | 439 | ||
437 | /*====================================================================================== | 440 | /*====================================================================================== |
438 | * ODHCPPacket | 441 | * ODHCPPacket |
439 | *======================================================================================*/ | 442 | *======================================================================================*/ |
440 | 443 | ||
441 | 444 | ||
442 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) | 445 | ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) |
443 | :QObject( parent, "DHCP" ), _dhcphdr( data ) | 446 | :QObject( parent, "DHCP" ), _dhcphdr( data ) |
444 | 447 | ||
445 | { | 448 | { |
446 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; | 449 | odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; |
447 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; | 450 | odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; |
448 | odebug << "clientAddress = " << clientAddress().toString() << oendl; | 451 | odebug << "clientAddress = " << clientAddress().toString() << oendl; |
449 | odebug << " yourAddress = " << yourAddress().toString() << oendl; | 452 | odebug << " yourAddress = " << yourAddress().toString() << oendl; |
450 | odebug << "serverAddress = " << serverAddress().toString() << oendl; | 453 | odebug << "serverAddress = " << serverAddress().toString() << oendl; |
451 | odebug << " relayAddress = " << relayAddress().toString() << oendl; | 454 | odebug << " relayAddress = " << relayAddress().toString() << oendl; |
452 | odebug << "parsing DHCP options..." << oendl; | 455 | odebug << "parsing DHCP options..." << oendl; |
453 | 456 | ||
454 | _type = 0; | 457 | _type = 0; |
455 | 458 | ||
456 | const unsigned char* option = &_dhcphdr->options[4]; | 459 | const unsigned char* option = &_dhcphdr->options[4]; |
457 | char tag = -1; | 460 | char tag = -1; |
458 | char len = -1; | 461 | char len = -1; |
459 | 462 | ||
460 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) | 463 | while ( ( tag = *option++ ) != -1 /* end of option field */ ) |
461 | { | 464 | { |
462 | len = *option++; | 465 | len = *option++; |
463 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; | 466 | odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; |
464 | 467 | ||
465 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) | 468 | if ( tag == DHO_DHCP_MESSAGE_TYPE ) |
466 | _type = *option; | 469 | _type = *option; |
467 | 470 | ||
468 | option += len; | 471 | option += len; |
469 | if ( option >= end ) | 472 | if ( option >= end ) |
470 | { | 473 | { |
471 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; | 474 | owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; |
472 | break; | 475 | break; |
473 | } | 476 | } |
474 | } | 477 | } |
475 | 478 | ||
476 | odebug << "DHCP type seems to be << " << type() << oendl; | 479 | odebug << "DHCP type seems to be << " << type() << oendl; |
477 | } | 480 | } |
478 | 481 | ||
479 | 482 | ||
480 | ODHCPPacket::~ODHCPPacket() | 483 | ODHCPPacket::~ODHCPPacket() |
481 | { | 484 | { |
482 | } | 485 | } |
483 | 486 | ||
484 | 487 | ||
485 | bool ODHCPPacket::isRequest() const | 488 | bool ODHCPPacket::isRequest() const |
486 | { | 489 | { |
487 | return ( _dhcphdr->op == 01 ); | 490 | return ( _dhcphdr->op == 01 ); |
488 | } | 491 | } |
489 | 492 | ||
490 | 493 | ||
491 | bool ODHCPPacket::isReply() const | 494 | bool ODHCPPacket::isReply() const |
492 | { | 495 | { |
493 | return ( _dhcphdr->op == 02 ); | 496 | return ( _dhcphdr->op == 02 ); |
494 | } | 497 | } |
495 | 498 | ||
496 | 499 | ||
497 | QString ODHCPPacket::type() const | 500 | QString ODHCPPacket::type() const |
498 | { | 501 | { |
499 | switch ( _type ) | 502 | switch ( _type ) |
500 | { | 503 | { |
501 | case 1: return "DISCOVER"; | 504 | case 1: return "DISCOVER"; |
502 | case 2: return "OFFER"; | 505 | case 2: return "OFFER"; |
503 | case 3: return "REQUEST"; | 506 | case 3: return "REQUEST"; |
504 | case 4: return "DECLINE"; | 507 | case 4: return "DECLINE"; |
505 | case 5: return "ACK"; | 508 | case 5: return "ACK"; |
506 | case 6: return "NAK"; | 509 | case 6: return "NAK"; |
507 | case 7: return "RELEASE"; | 510 | case 7: return "RELEASE"; |
508 | case 8: return "INFORM"; | 511 | case 8: return "INFORM"; |
509 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; | 512 | default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; |
510 | } | 513 | } |
511 | } | 514 | } |
512 | 515 | ||
513 | 516 | ||
514 | QHostAddress ODHCPPacket::clientAddress() const | 517 | QHostAddress ODHCPPacket::clientAddress() const |
515 | { | 518 | { |
516 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); | 519 | return EXTRACT_32BITS( &_dhcphdr->ciaddr ); |
517 | } | 520 | } |
518 | 521 | ||
519 | 522 | ||
520 | QHostAddress ODHCPPacket::yourAddress() const | 523 | QHostAddress ODHCPPacket::yourAddress() const |
521 | { | 524 | { |
522 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); | 525 | return EXTRACT_32BITS( &_dhcphdr->yiaddr ); |
523 | } | 526 | } |
524 | 527 | ||
525 | 528 | ||
526 | QHostAddress ODHCPPacket::serverAddress() const | 529 | QHostAddress ODHCPPacket::serverAddress() const |
527 | { | 530 | { |
528 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); | 531 | return EXTRACT_32BITS( &_dhcphdr->siaddr ); |
529 | } | 532 | } |
530 | 533 | ||
531 | 534 | ||
532 | QHostAddress ODHCPPacket::relayAddress() const | 535 | QHostAddress ODHCPPacket::relayAddress() const |
533 | { | 536 | { |
534 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); | 537 | return EXTRACT_32BITS( &_dhcphdr->giaddr ); |
535 | } | 538 | } |
536 | 539 | ||
537 | 540 | ||
538 | OMacAddress ODHCPPacket::clientMacAddress() const | 541 | OMacAddress ODHCPPacket::clientMacAddress() const |
539 | { | 542 | { |
540 | return OMacAddress( _dhcphdr->chaddr ); | 543 | return OMacAddress( _dhcphdr->chaddr ); |
541 | } | 544 | } |
542 | 545 | ||
543 | 546 | ||
544 | /*====================================================================================== | 547 | /*====================================================================================== |
545 | * OTCPPacket | 548 | * OTCPPacket |
546 | *======================================================================================*/ | 549 | *======================================================================================*/ |
547 | 550 | ||
548 | 551 | ||
549 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) | 552 | OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) |
550 | :QObject( parent, "TCP" ), _tcphdr( data ) | 553 | :QObject( parent, "TCP" ), _tcphdr( data ) |
551 | 554 | ||
552 | { | 555 | { |
553 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; | 556 | odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; |
554 | } | 557 | } |
555 | 558 | ||
556 | 559 | ||
557 | OTCPPacket::~OTCPPacket() | 560 | OTCPPacket::~OTCPPacket() |
558 | { | 561 | { |
559 | } | 562 | } |
560 | 563 | ||
561 | 564 | ||
562 | int OTCPPacket::fromPort() const | 565 | int OTCPPacket::fromPort() const |
563 | { | 566 | { |
564 | return EXTRACT_16BITS( &_tcphdr->source ); | 567 | return EXTRACT_16BITS( &_tcphdr->source ); |
565 | } | 568 | } |
566 | 569 | ||
567 | 570 | ||
568 | int OTCPPacket::toPort() const | 571 | int OTCPPacket::toPort() const |
569 | { | 572 | { |
570 | return EXTRACT_16BITS( &_tcphdr->dest ); | 573 | return EXTRACT_16BITS( &_tcphdr->dest ); |
571 | } | 574 | } |
572 | 575 | ||
573 | 576 | ||
574 | int OTCPPacket::seq() const | 577 | int OTCPPacket::seq() const |
575 | { | 578 | { |
576 | return EXTRACT_16BITS( &_tcphdr->seq ); | 579 | return EXTRACT_16BITS( &_tcphdr->seq ); |
577 | } | 580 | } |
578 | 581 | ||
579 | 582 | ||
580 | int OTCPPacket::ack() const | 583 | int OTCPPacket::ack() const |
581 | { | 584 | { |
582 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); | 585 | return EXTRACT_16BITS( &_tcphdr->ack_seq ); |
583 | } | 586 | } |
584 | 587 | ||
585 | 588 | ||
586 | int OTCPPacket::window() const | 589 | int OTCPPacket::window() const |
587 | { | 590 | { |
588 | return EXTRACT_16BITS( &_tcphdr->window ); | 591 | return EXTRACT_16BITS( &_tcphdr->window ); |
589 | } | 592 | } |
590 | 593 | ||
591 | 594 | ||
592 | int OTCPPacket::checksum() const | 595 | int OTCPPacket::checksum() const |
593 | { | 596 | { |
594 | return EXTRACT_16BITS( &_tcphdr->check ); | 597 | return EXTRACT_16BITS( &_tcphdr->check ); |
595 | } | 598 | } |
596 | 599 | ||
597 | /*====================================================================================== | 600 | /*====================================================================================== |
598 | * OPrismHeaderPacket | 601 | * OPrismHeaderPacket |
599 | *======================================================================================*/ | 602 | *======================================================================================*/ |
600 | 603 | ||
601 | 604 | ||
602 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) | 605 | OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) |
603 | :QObject( parent, "Prism" ), _header( data ) | 606 | :QObject( parent, "Prism" ), _header( data ) |
604 | 607 | ||
605 | { | 608 | { |
606 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; | 609 | odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; |
607 | 610 | ||
608 | odebug << "Signal Strength = " << data->signal.data << oendl; | 611 | odebug << "Signal Strength = " << data->signal.data << oendl; |
609 | 612 | ||
610 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); | 613 | new OWaveLanPacket( end, (const struct ieee_802_11_header*) (data+1), this ); |
611 | } | 614 | } |
612 | 615 | ||
613 | OPrismHeaderPacket::~OPrismHeaderPacket() | 616 | OPrismHeaderPacket::~OPrismHeaderPacket() |
614 | { | 617 | { |
615 | } | 618 | } |
616 | 619 | ||
617 | 620 | ||
618 | unsigned int OPrismHeaderPacket::signalStrength() const | 621 | unsigned int OPrismHeaderPacket::signalStrength() const |
619 | { | 622 | { |
620 | return _header->signal.data; | 623 | return _header->signal.data; |
621 | } | 624 | } |
622 | 625 | ||
623 | /*====================================================================================== | 626 | /*====================================================================================== |
624 | * OWaveLanPacket | 627 | * OWaveLanPacket |
625 | *======================================================================================*/ | 628 | *======================================================================================*/ |
626 | 629 | ||
627 | 630 | ||
628 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) | 631 | OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_11_header* data, QObject* parent ) |
629 | :QObject( parent, "802.11" ), _wlanhdr( data ) | 632 | :QObject( parent, "802.11" ), _wlanhdr( data ) |
630 | 633 | ||
631 | { | 634 | { |
632 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; | 635 | odebug << "OWaveLanPacket::OWaveLanPacket(): decoding IEEE 802.11 header..." << oendl; |
633 | odebug << "type = " << type() << oendl; | 636 | odebug << "type = " << type() << oendl; |
634 | odebug << "subType = " << subType() << oendl; | 637 | odebug << "subType = " << subType() << oendl; |
635 | odebug << "duration = " << duration() << oendl; | 638 | odebug << "duration = " << duration() << oendl; |
636 | odebug << "powermanagement = " << usesPowerManagement() << oendl; | 639 | odebug << "powermanagement = " << usesPowerManagement() << oendl; |
637 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; | 640 | odebug << "payload is encrypted = " << ( usesWep() ? "yes" : "no" ) << oendl; |
638 | odebug << "MAC1 = " << macAddress1().toString() << oendl; | 641 | odebug << "MAC1 = " << macAddress1().toString() << oendl; |
639 | odebug << "MAC2 = " << macAddress2().toString() << oendl; | 642 | odebug << "MAC2 = " << macAddress2().toString() << oendl; |
640 | odebug << "MAC3 = " << macAddress3().toString() << oendl; | 643 | odebug << "MAC3 = " << macAddress3().toString() << oendl; |
641 | odebug << "MAC4 = " << macAddress4().toString() << oendl; | 644 | odebug << "MAC4 = " << macAddress4().toString() << oendl; |
642 | 645 | ||
643 | switch ( type() ) | 646 | switch ( type() ) |
644 | { | 647 | { |
645 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; | 648 | case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; |
646 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; | 649 | case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; |
647 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; | 650 | case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; |
648 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; | 651 | default: odebug << "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type = " << type() << oendl; |
649 | } | 652 | } |
650 | } | 653 | } |
651 | 654 | ||
652 | OWaveLanPacket::~OWaveLanPacket() | 655 | OWaveLanPacket::~OWaveLanPacket() |
653 | { | 656 | { |
654 | } | 657 | } |
655 | 658 | ||
656 | 659 | ||
657 | int OWaveLanPacket::duration() const | 660 | int OWaveLanPacket::duration() const |
658 | { | 661 | { |
659 | return _wlanhdr->duration; | 662 | return _wlanhdr->duration; |
660 | } | 663 | } |
661 | 664 | ||
662 | 665 | ||
663 | OMacAddress OWaveLanPacket::macAddress1() const | 666 | OMacAddress OWaveLanPacket::macAddress1() const |
664 | { | 667 | { |
665 | return OMacAddress( _wlanhdr->mac1 ); | 668 | return OMacAddress( _wlanhdr->mac1 ); |
666 | } | 669 | } |
667 | 670 | ||
668 | 671 | ||
669 | OMacAddress OWaveLanPacket::macAddress2() const | 672 | OMacAddress OWaveLanPacket::macAddress2() const |
670 | { | 673 | { |
671 | return OMacAddress( _wlanhdr->mac2 ); | 674 | return OMacAddress( _wlanhdr->mac2 ); |
672 | } | 675 | } |
673 | 676 | ||
674 | 677 | ||
675 | OMacAddress OWaveLanPacket::macAddress3() const | 678 | OMacAddress OWaveLanPacket::macAddress3() const |
676 | { | 679 | { |
677 | return OMacAddress( _wlanhdr->mac3 ); | 680 | return OMacAddress( _wlanhdr->mac3 ); |
678 | } | 681 | } |
679 | 682 | ||
680 | 683 | ||
681 | OMacAddress OWaveLanPacket::macAddress4() const | 684 | OMacAddress OWaveLanPacket::macAddress4() const |
682 | { | 685 | { |
683 | return OMacAddress( _wlanhdr->mac4 ); | 686 | return OMacAddress( _wlanhdr->mac4 ); |
684 | } | 687 | } |
685 | 688 | ||
686 | 689 | ||
687 | int OWaveLanPacket::subType() const | 690 | int OWaveLanPacket::subType() const |
688 | { | 691 | { |
689 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 692 | return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
690 | } | 693 | } |
691 | 694 | ||
692 | 695 | ||
693 | int OWaveLanPacket::type() const | 696 | int OWaveLanPacket::type() const |
694 | { | 697 | { |
695 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 698 | return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
696 | } | 699 | } |
697 | 700 | ||
698 | 701 | ||
699 | int OWaveLanPacket::version() const | 702 | int OWaveLanPacket::version() const |
700 | { | 703 | { |
701 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 704 | return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
702 | } | 705 | } |
703 | 706 | ||
704 | 707 | ||
705 | bool OWaveLanPacket::fromDS() const | 708 | bool OWaveLanPacket::fromDS() const |
706 | { | 709 | { |
707 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 710 | return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
708 | } | 711 | } |
709 | 712 | ||
710 | 713 | ||
711 | bool OWaveLanPacket::toDS() const | 714 | bool OWaveLanPacket::toDS() const |
712 | { | 715 | { |
713 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 716 | return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
714 | } | 717 | } |
715 | 718 | ||
716 | 719 | ||
717 | bool OWaveLanPacket::usesPowerManagement() const | 720 | bool OWaveLanPacket::usesPowerManagement() const |
718 | { | 721 | { |
719 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 722 | return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
720 | } | 723 | } |
721 | 724 | ||
722 | 725 | ||
723 | bool OWaveLanPacket::usesWep() const | 726 | bool OWaveLanPacket::usesWep() const |
724 | { | 727 | { |
725 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); | 728 | return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); |
726 | } | 729 | } |
727 | 730 | ||
728 | 731 | ||
729 | /*====================================================================================== | 732 | /*====================================================================================== |
730 | * OWaveLanManagementPacket | 733 | * OWaveLanManagementPacket |
731 | *======================================================================================*/ | 734 | *======================================================================================*/ |
732 | 735 | ||
733 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) | 736 | OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) |
734 | :QObject( parent, "802.11 Management" ), _header( data ), | 737 | :QObject( parent, "802.11 Management" ), _header( data ), |
735 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) | 738 | _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) |
736 | { | 739 | { |
737 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; | 740 | odebug << "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." << oendl; |
738 | odebug << "Detected subtype is " << managementType() << oendl; | 741 | odebug << "Detected subtype is " << managementType() << oendl; |
739 | 742 | ||
740 | // Grab tagged values. | 743 | // Grab tagged values. |
741 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, | 744 | // Beacons contain a 12 byte long fixed parameters set before the tagged parameters come, |
742 | // Other management frames don't - which is why we have to inspect the subtype here. | 745 | // Other management frames don't - which is why we have to inspect the subtype here. |
743 | 746 | ||
744 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); | 747 | const unsigned char* ptr = managementType() == "Beacon" ? (const unsigned char*) (_body+1) : (const unsigned char*) (_header+1); |
745 | 748 | ||
746 | while (ptr < end) | 749 | while (ptr < end) |
747 | { | 750 | { |
748 | switch ( *ptr ) | 751 | switch ( *ptr ) |
749 | { | 752 | { |
750 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; | 753 | case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; |
751 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; | 754 | case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; |
752 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; | 755 | case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; |
753 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; | 756 | case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; |
754 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; | 757 | case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; |
755 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; | 758 | case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; |
756 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; | 759 | case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; |
757 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; | 760 | case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; |
758 | } | 761 | } |
759 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value | 762 | ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value |
760 | ptr+= 2; // skip tag ID and length | 763 | ptr+= 2; // skip tag ID and length |
761 | } | 764 | } |
762 | } | 765 | } |
763 | 766 | ||
764 | 767 | ||
765 | OWaveLanManagementPacket::~OWaveLanManagementPacket() | 768 | OWaveLanManagementPacket::~OWaveLanManagementPacket() |
766 | { | 769 | { |
767 | } | 770 | } |
768 | 771 | ||
769 | 772 | ||
770 | QString OWaveLanManagementPacket::managementType() const | 773 | QString OWaveLanManagementPacket::managementType() const |
771 | { | 774 | { |
772 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) | 775 | switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) |
773 | { | 776 | { |
774 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; | 777 | case ST_ASSOC_REQUEST: return "AssociationRequest"; break; |
775 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; | 778 | case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; |
776 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; | 779 | case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; |
777 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; | 780 | case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; |
778 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; | 781 | case ST_PROBE_REQUEST: return "ProbeRequest"; break; |
779 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; | 782 | case ST_PROBE_RESPONSE: return "ProbeResponse"; break; |
780 | case ST_BEACON: return "Beacon"; break; | 783 | case ST_BEACON: return "Beacon"; break; |
781 | case ST_ATIM: return "Atim"; break; | 784 | case ST_ATIM: return "Atim"; break; |
782 | case ST_DISASSOC: return "Disassociation"; break; | 785 | case ST_DISASSOC: return "Disassociation"; break; |
783 | case ST_AUTH: return "Authentication"; break; | 786 | case ST_AUTH: return "Authentication"; break; |
784 | case ST_DEAUTH: return "Deathentication"; break; | 787 | case ST_DEAUTH: return "Deathentication"; break; |
785 | default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown"; | 788 | default: owarn << "OWaveLanManagementPacket::managementType(): unhandled subtype " << FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) << oendl; return "Unknown"; |
786 | } | 789 | } |
787 | } | 790 | } |
788 | 791 | ||
789 | 792 | ||
790 | int OWaveLanManagementPacket::beaconInterval() const | 793 | int OWaveLanManagementPacket::beaconInterval() const |
791 | { | 794 | { |
792 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); | 795 | return EXTRACT_LE_16BITS( &_body->beacon_interval ); |
793 | } | 796 | } |
794 | 797 | ||
795 | 798 | ||
796 | int OWaveLanManagementPacket::capabilities() const | 799 | int OWaveLanManagementPacket::capabilities() const |
797 | { | 800 | { |
798 | return EXTRACT_LE_16BITS( &_body->capability_info ); | 801 | return EXTRACT_LE_16BITS( &_body->capability_info ); |
799 | } | 802 | } |
800 | 803 | ||
801 | 804 | ||
802 | bool OWaveLanManagementPacket::canESS() const | 805 | bool OWaveLanManagementPacket::canESS() const |
803 | { | 806 | { |
804 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 807 | return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
805 | } | 808 | } |
806 | 809 | ||
807 | 810 | ||
808 | bool OWaveLanManagementPacket::canIBSS() const | 811 | bool OWaveLanManagementPacket::canIBSS() const |
809 | { | 812 | { |
810 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 813 | return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
811 | } | 814 | } |
812 | 815 | ||
813 | 816 | ||
814 | bool OWaveLanManagementPacket::canCFP() const | 817 | bool OWaveLanManagementPacket::canCFP() const |
815 | { | 818 | { |
816 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 819 | return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
817 | } | 820 | } |
818 | 821 | ||
819 | 822 | ||
820 | bool OWaveLanManagementPacket::canCFP_REQ() const | 823 | bool OWaveLanManagementPacket::canCFP_REQ() const |
821 | { | 824 | { |
822 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 825 | return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
823 | } | 826 | } |
824 | 827 | ||
825 | 828 | ||
826 | bool OWaveLanManagementPacket::canPrivacy() const | 829 | bool OWaveLanManagementPacket::canPrivacy() const |
827 | { | 830 | { |
828 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); | 831 | return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); |
829 | } | 832 | } |
830 | 833 | ||
831 | 834 | ||
832 | /*====================================================================================== | 835 | /*====================================================================================== |
833 | * OWaveLanManagementSSID | 836 | * OWaveLanManagementSSID |
834 | *======================================================================================*/ | 837 | *======================================================================================*/ |
835 | 838 | ||
836 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) | 839 | OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) |
837 | :QObject( parent, "802.11 SSID" ), _data( data ) | 840 | :QObject( parent, "802.11 SSID" ), _data( data ) |
838 | { | 841 | { |
839 | odebug << "OWaveLanManagementSSID()" << oendl; | 842 | odebug << "OWaveLanManagementSSID()" << oendl; |
840 | } | 843 | } |
841 | 844 | ||
842 | 845 | ||
843 | OWaveLanManagementSSID::~OWaveLanManagementSSID() | 846 | OWaveLanManagementSSID::~OWaveLanManagementSSID() |
844 | { | 847 | { |
845 | } | 848 | } |
846 | 849 | ||
847 | 850 | ||
848 | QString OWaveLanManagementSSID::ID( bool decloak ) const | 851 | QString OWaveLanManagementSSID::ID( bool decloak ) const |
849 | { | 852 | { |
850 | int length = _data->length; | 853 | int length = _data->length; |
851 | if ( length > 32 ) length = 32; | 854 | if ( length > 32 ) length = 32; |
852 | char essid[length+1]; | 855 | char essid[length+1]; |
853 | memcpy( &essid, &_data->ssid, length ); | 856 | memcpy( &essid, &_data->ssid, length ); |
854 | essid[length] = 0x0; | 857 | essid[length] = 0x0; |
855 | if ( !decloak || length < 2 || essid[0] != '\0' ) return essid; | 858 | if ( !decloak || length < 2 || essid[0] != '\0' ) return essid; |
856 | odebug << "OWaveLanManagementSSID:ID(): SSID is cloaked - decloaking..." << oendl; | 859 | odebug << "OWaveLanManagementSSID:ID(): SSID is cloaked - decloaking..." << oendl; |
857 | 860 | ||
858 | QString decloakedID; | 861 | QString decloakedID; |
859 | for ( int i = 1; i < length; ++i ) | 862 | for ( int i = 1; i < length; ++i ) |
860 | { | 863 | { |