summaryrefslogtreecommitdiff
authorzecke <zecke>2004-05-07 16:45:46 (UTC)
committer zecke <zecke>2004-05-07 16:45:46 (UTC)
commitde674154922b40fd2c01e008c7a7871520a86209 (patch) (unidiff)
tree29155a26d71fa6c6f59bd01ad3dece7f15193905
parenta8c2ce4c6bc83223a32e6e803b1277a0db5ebd7f (diff)
downloadopie-de674154922b40fd2c01e008c7a7871520a86209.zip
opie-de674154922b40fd2c01e008c7a7871520a86209.tar.gz
opie-de674154922b40fd2c01e008c7a7871520a86209.tar.bz2
If you create an array, delete it as an array
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 8184f21..03e4502 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -1,607 +1,607 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003-2004 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" 31#include "udp_ports.h"
32#include "opcap.h" 32#include "opcap.h"
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36using namespace Opie::Core; 36using namespace Opie::Core;
37 37
38/* QT */ 38/* QT */
39#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)
40#include <qsocketnotifier.h> 40#include <qsocketnotifier.h>
41#include <qobjectlist.h> 41#include <qobjectlist.h>
42 42
43/* STD */ 43/* STD */
44#include <sys/time.h> 44#include <sys/time.h>
45#include <sys/types.h> 45#include <sys/types.h>
46#include <assert.h> 46#include <assert.h>
47#include <unistd.h> 47#include <unistd.h>
48#include <string.h> 48#include <string.h>
49 49
50namespace Opie { 50namespace Opie {
51namespace Net { 51namespace Net {
52 52
53/*====================================================================================== 53/*======================================================================================
54 * OPacket 54 * OPacket
55 *======================================================================================*/ 55 *======================================================================================*/
56 56
57OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 57OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
58 :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) 58 :QObject( parent, "Generic" ), _hdr( header ), _data( 0 )
59{ 59{
60 60
61 _data = new unsigned char[ header.len ]; 61 _data = new unsigned char[ header.len ];
62 assert( _data ); 62 assert( _data );
63 memcpy( const_cast<unsigned char*>(_data), data, header.len ); 63 memcpy( const_cast<unsigned char*>(_data), data, header.len );
64 // We have to copy the data structure here, because the 'data' pointer handed by libpcap 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. 65 // points to an internal region which is reused by lipcap.
66 odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; 66 odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl;
67 _end = (unsigned char*) _data + header.len; 67 _end = (unsigned char*) _data + header.len;
68 68
69 switch ( datalink ) 69 switch ( datalink )
70 { 70 {
71 case DLT_EN10MB: 71 case DLT_EN10MB:
72 odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; 72 odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl;
73 new OEthernetPacket( _end, (const struct ether_header*) _data, this ); 73 new OEthernetPacket( _end, (const struct ether_header*) _data, this );
74 break; 74 break;
75 75
76 case DLT_IEEE802_11: 76 case DLT_IEEE802_11:
77 odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; 77 odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl;
78 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); 78 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this );
79 break; 79 break;
80 80
81 case DLT_PRISM_HEADER: 81 case DLT_PRISM_HEADER:
82 odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; 82 odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl;
83 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); 83 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this );
84 break; 84 break;
85 85
86 default: 86 default:
87 owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; 87 owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl;
88 } 88 }
89} 89}
90 90
91 91
92OPacket::~OPacket() 92OPacket::~OPacket()
93{ 93{
94 odebug << "~OPacket( " << name() << " )" << oendl; 94 odebug << "~OPacket( " << name() << " )" << oendl;
95 delete _data; 95 delete [] _data;
96} 96}
97 97
98 98
99timevalstruct OPacket::timeval() const 99timevalstruct OPacket::timeval() const
100{ 100{
101 return _hdr.ts; 101 return _hdr.ts;
102} 102}
103 103
104 104
105int OPacket::caplen() const 105int OPacket::caplen() const
106{ 106{
107 return _hdr.caplen; 107 return _hdr.caplen;
108} 108}
109 109
110 110
111void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 111void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )
112{ 112{
113 if (!l) return; 113 if (!l) return;
114 QObject* o = l->first(); 114 QObject* o = l->first();
115 while ( o ) 115 while ( o )
116 { 116 {
117 stats[o->name()]++; 117 stats[o->name()]++;
118 updateStats( stats, const_cast<QObjectList*>( o->children() ) ); 118 updateStats( stats, const_cast<QObjectList*>( o->children() ) );
119 o = l->next(); 119 o = l->next();
120 } 120 }
121} 121}
122 122
123 123
124QString OPacket::dumpStructure() const 124QString OPacket::dumpStructure() const
125{ 125{
126 return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]"; 126 return "[ |" + _dumpStructure( const_cast<QObjectList*>( this->children() ) ) + " ]";
127} 127}
128 128
129 129
130QString OPacket::_dumpStructure( QObjectList* l ) const 130QString OPacket::_dumpStructure( QObjectList* l ) const
131{ 131{
132 if (!l) return QString::null; 132 if (!l) return QString::null;
133 QObject* o = l->first(); 133 QObject* o = l->first();
134 QString str(" "); 134 QString str(" ");
135 135
136 while ( o ) 136 while ( o )
137 { 137 {
138 str.append( o->name() ); 138 str.append( o->name() );
139 str.append( " |" ); 139 str.append( " |" );
140 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) ); 140 str += _dumpStructure( const_cast<QObjectList*>( o->children() ) );
141 o = l->next(); 141 o = l->next();
142 } 142 }
143 return str; 143 return str;
144} 144}
145 145
146QString OPacket::dump( int bpl ) const 146QString OPacket::dump( int bpl ) const
147{ 147{
148 static int index = 0; 148 static int index = 0;
149 index++; 149 index++;
150 int len = _hdr.caplen; 150 int len = _hdr.caplen;
151 QString str( "000:" ); 151 QString str( "000:" );
152 QString tmp; 152 QString tmp;
153 QString bytes; 153 QString bytes;
154 QString chars; 154 QString chars;
155 155
156 for ( int i = 0; i < len; ++i ) 156 for ( int i = 0; i < len; ++i )
157 { 157 {
158 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp ); 158 tmp.sprintf( "%02X ", _data[i] ); bytes.append( tmp );
159 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] ); 159 if ( (_data[i] > 31) && (_data[i]<128) ) chars.append( _data[i] );
160 else chars.append( '.' ); 160 else chars.append( '.' );
161 161
162 if ( !((i+1) % bpl) ) 162 if ( !((i+1) % bpl) )
163 { 163 {
164 str.append( bytes ); 164 str.append( bytes );
165 str.append( ' ' ); 165 str.append( ' ' );
166 str.append( chars ); 166 str.append( chars );
167 str.append( '\n' ); 167 str.append( '\n' );
168 tmp.sprintf( "%03X:", i+1 ); str.append( tmp ); 168 tmp.sprintf( "%03X:", i+1 ); str.append( tmp );
169 bytes = ""; 169 bytes = "";
170 chars = ""; 170 chars = "";
171 } 171 }
172 172
173 } 173 }
174 if ( (len % bpl) ) 174 if ( (len % bpl) )
175 { 175 {
176 str.append( bytes.leftJustify( 1 + 3*bpl ) ); 176 str.append( bytes.leftJustify( 1 + 3*bpl ) );
177 str.append( chars ); 177 str.append( chars );
178 } 178 }
179 str.append( '\n' ); 179 str.append( '\n' );
180 return str; 180 return str;
181} 181}
182 182
183 183
184int OPacket::len() const 184int OPacket::len() const
185{ 185{
186 return _hdr.len; 186 return _hdr.len;
187} 187}
188 188
189 189
190QTextStream& operator<<( QTextStream& s, const OPacket& p ) 190QTextStream& operator<<( QTextStream& s, const OPacket& p )
191{ 191{
192 s << p.dumpStructure(); 192 s << p.dumpStructure();
193} 193}
194 194
195 195
196/*====================================================================================== 196/*======================================================================================
197 * OEthernetPacket 197 * OEthernetPacket
198 *======================================================================================*/ 198 *======================================================================================*/
199 199
200OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 200OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent )
201 :QObject( parent, "Ethernet" ), _ether( data ) 201 :QObject( parent, "Ethernet" ), _ether( data )
202{ 202{
203 203
204 odebug << "Source = " << sourceAddress().toString() << oendl; 204 odebug << "Source = " << sourceAddress().toString() << oendl;
205 odebug << "Destination = " << destinationAddress().toString() << oendl; 205 odebug << "Destination = " << destinationAddress().toString() << oendl;
206 206
207 if ( sourceAddress() == OMacAddress::broadcast ) 207 if ( sourceAddress() == OMacAddress::broadcast )
208 odebug << "Source is broadcast address" << oendl; 208 odebug << "Source is broadcast address" << oendl;
209 if ( destinationAddress() == OMacAddress::broadcast ) 209 if ( destinationAddress() == OMacAddress::broadcast )
210 odebug << "Destination is broadcast address" << oendl; 210 odebug << "Destination is broadcast address" << oendl;
211 211
212 switch ( type() ) 212 switch ( type() )
213 { 213 {
214 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 214 case ETHERTYPE_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
215 case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; 215 case ETHERTYPE_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
216 case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; } 216 case ETHERTYPE_REVARP: { odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = RARP" << oendl; break; }
217 default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl; 217 default: odebug << "OPacket::OPacket(): Received Ethernet Packet : Type = UNKNOWN" << oendl;
218 } 218 }
219 219
220} 220}
221 221
222 222
223OEthernetPacket::~OEthernetPacket() 223OEthernetPacket::~OEthernetPacket()
224{ 224{
225} 225}
226 226
227 227
228OMacAddress OEthernetPacket::sourceAddress() const 228OMacAddress OEthernetPacket::sourceAddress() const
229{ 229{
230 return OMacAddress( _ether->ether_shost ); 230 return OMacAddress( _ether->ether_shost );
231} 231}
232 232
233 233
234OMacAddress OEthernetPacket::destinationAddress() const 234OMacAddress OEthernetPacket::destinationAddress() const
235{ 235{
236 return OMacAddress( _ether->ether_dhost ); 236 return OMacAddress( _ether->ether_dhost );
237} 237}
238 238
239int OEthernetPacket::type() const 239int OEthernetPacket::type() const
240{ 240{
241 return ntohs( _ether->ether_type ); 241 return ntohs( _ether->ether_type );
242} 242}
243 243
244 244
245/*====================================================================================== 245/*======================================================================================
246 * OIPPacket 246 * OIPPacket
247 *======================================================================================*/ 247 *======================================================================================*/
248 248
249 249
250OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) 250OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent )
251 :QObject( parent, "IP" ), _iphdr( data ) 251 :QObject( parent, "IP" ), _iphdr( data )
252{ 252{
253 odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl; 253 odebug << "OIPPacket::OIPPacket(): decoding IP header..." << oendl;
254 254
255 odebug << "FromAddress = " << fromIPAddress().toString() << oendl; 255 odebug << "FromAddress = " << fromIPAddress().toString() << oendl;
256 odebug << " toAddress = " << toIPAddress().toString() << oendl; 256 odebug << " toAddress = " << toIPAddress().toString() << oendl;
257 257
258 switch ( protocol() ) 258 switch ( protocol() )
259 { 259 {
260 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break; 260 case IPPROTO_UDP: new OUDPPacket( end, (const struct udphdr*) (data+1), this ); break;
261 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break; 261 case IPPROTO_TCP: new OTCPPacket( end, (const struct tcphdr*) (data+1), this ); break;
262 default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl; 262 default: odebug << "OIPPacket::OIPPacket(): unknown IP protocol, type = " << protocol() << oendl;
263 } 263 }
264 264
265} 265}
266 266
267OIPPacket::~OIPPacket() 267OIPPacket::~OIPPacket()
268{ 268{
269} 269}
270 270
271 271
272QHostAddress OIPPacket::fromIPAddress() const 272QHostAddress OIPPacket::fromIPAddress() const
273{ 273{
274 return EXTRACT_32BITS( &_iphdr->saddr ); 274 return EXTRACT_32BITS( &_iphdr->saddr );
275} 275}
276 276
277 277
278QHostAddress OIPPacket::toIPAddress() const 278QHostAddress OIPPacket::toIPAddress() const
279{ 279{
280 return EXTRACT_32BITS( &_iphdr->saddr ); 280 return EXTRACT_32BITS( &_iphdr->saddr );
281} 281}
282 282
283 283
284int OIPPacket::tos() const 284int OIPPacket::tos() const
285{ 285{
286 return _iphdr->tos; 286 return _iphdr->tos;
287} 287}
288 288
289 289
290int OIPPacket::len() const 290int OIPPacket::len() const
291{ 291{
292 return EXTRACT_16BITS( &_iphdr->tot_len ); 292 return EXTRACT_16BITS( &_iphdr->tot_len );
293} 293}
294 294
295 295
296int OIPPacket::id() const 296int OIPPacket::id() const
297{ 297{
298 return EXTRACT_16BITS( &_iphdr->id ); 298 return EXTRACT_16BITS( &_iphdr->id );
299} 299}
300 300
301 301
302int OIPPacket::offset() const 302int OIPPacket::offset() const
303{ 303{
304 return EXTRACT_16BITS( &_iphdr->frag_off ); 304 return EXTRACT_16BITS( &_iphdr->frag_off );
305} 305}
306 306
307 307
308int OIPPacket::ttl() const 308int OIPPacket::ttl() const
309{ 309{
310 return _iphdr->ttl; 310 return _iphdr->ttl;
311} 311}
312 312
313 313
314int OIPPacket::protocol() const 314int OIPPacket::protocol() const
315{ 315{
316 return _iphdr->protocol; 316 return _iphdr->protocol;
317} 317}
318 318
319 319
320int OIPPacket::checksum() const 320int OIPPacket::checksum() const
321{ 321{
322 return EXTRACT_16BITS( &_iphdr->check ); 322 return EXTRACT_16BITS( &_iphdr->check );
323} 323}
324 324
325/*====================================================================================== 325/*======================================================================================
326 * OARPPacket 326 * OARPPacket
327 *======================================================================================*/ 327 *======================================================================================*/
328 328
329 329
330OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) 330OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent )
331 :QObject( parent, "ARP" ), _arphdr( data ) 331 :QObject( parent, "ARP" ), _arphdr( data )
332{ 332{
333 odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl; 333 odebug << "OARPPacket::OARPPacket(): decoding ARP header..." << oendl;
334 odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl; 334 odebug << "ARP type seems to be " << EXTRACT_16BITS( &_arphdr->ar_op ) << " = " << type() << oendl;
335 odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl; 335 odebug << "Sender: MAC " << senderMacAddress().toString() << " = IP " << senderIPV4Address().toString() << oendl;
336 odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl; 336 odebug << "Target: MAC " << targetMacAddress().toString() << " = IP " << targetIPV4Address().toString() << oendl;
337} 337}
338 338
339 339
340OARPPacket::~OARPPacket() 340OARPPacket::~OARPPacket()
341{ 341{
342} 342}
343 343
344 344
345QString OARPPacket::type() const 345QString OARPPacket::type() const
346{ 346{
347 switch ( EXTRACT_16BITS( &_arphdr->ar_op ) ) 347 switch ( EXTRACT_16BITS( &_arphdr->ar_op ) )
348 { 348 {
349 case 1: return "REQUEST"; 349 case 1: return "REQUEST";
350 case 2: return "REPLY"; 350 case 2: return "REPLY";
351 case 3: return "RREQUEST"; 351 case 3: return "RREQUEST";
352 case 4: return "RREPLY"; 352 case 4: return "RREPLY";
353 case 8: return "InREQUEST"; 353 case 8: return "InREQUEST";
354 case 9: return "InREPLY"; 354 case 9: return "InREPLY";
355 case 10: return "NAK"; 355 case 10: return "NAK";
356 default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>"; 356 default: owarn << "OARPPacket::type(): invalid ARP type!" << oendl; return "<unknown>";
357 } 357 }
358} 358}
359 359
360 360
361QHostAddress OARPPacket::senderIPV4Address() const 361QHostAddress OARPPacket::senderIPV4Address() const
362{ 362{
363 return EXTRACT_32BITS( &_arphdr->ar_sip ); 363 return EXTRACT_32BITS( &_arphdr->ar_sip );
364} 364}
365 365
366 366
367QHostAddress OARPPacket::targetIPV4Address() const 367QHostAddress OARPPacket::targetIPV4Address() const
368{ 368{
369 return EXTRACT_32BITS( &_arphdr->ar_tip ); 369 return EXTRACT_32BITS( &_arphdr->ar_tip );
370} 370}
371 371
372 372
373OMacAddress OARPPacket::senderMacAddress() const 373OMacAddress OARPPacket::senderMacAddress() const
374{ 374{
375 return OMacAddress( _arphdr->ar_sha ); 375 return OMacAddress( _arphdr->ar_sha );
376} 376}
377 377
378 378
379OMacAddress OARPPacket::targetMacAddress() const 379OMacAddress OARPPacket::targetMacAddress() const
380{ 380{
381 return OMacAddress( _arphdr->ar_tha ); 381 return OMacAddress( _arphdr->ar_tha );
382} 382}
383 383
384 384
385/*====================================================================================== 385/*======================================================================================
386 * OUDPPacket 386 * OUDPPacket
387 *======================================================================================*/ 387 *======================================================================================*/
388 388
389 389
390OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) 390OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent )
391 :QObject( parent, "UDP" ), _udphdr( data ) 391 :QObject( parent, "UDP" ), _udphdr( data )
392 392
393{ 393{
394 odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl; 394 odebug << "OUDPPacket::OUDPPacket(): decoding UDP header..." << oendl;
395 odebug << "fromPort = " << fromPort() << oendl; 395 odebug << "fromPort = " << fromPort() << oendl;
396 odebug << " toPort = " << toPort() << oendl; 396 odebug << " toPort = " << toPort() << oendl;
397 397
398 // TODO: Make this a case or a hash if we know more udp protocols 398 // TODO: Make this a case or a hash if we know more udp protocols
399 399
400 if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC || 400 if ( fromPort() == UDP_PORT_BOOTPS || fromPort() == UDP_PORT_BOOTPC ||
401 toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC ) 401 toPort() == UDP_PORT_BOOTPS || toPort() == UDP_PORT_BOOTPC )
402 { 402 {
403 odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl; 403 odebug << "seems to be part of a DHCP conversation => creating DHCP packet." << oendl;
404 new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this ); 404 new ODHCPPacket( end, (const struct dhcp_packet*) (data+1), this );
405 } 405 }
406} 406}
407 407
408 408
409OUDPPacket::~OUDPPacket() 409OUDPPacket::~OUDPPacket()
410{ 410{
411} 411}
412 412
413 413
414int OUDPPacket::fromPort() const 414int OUDPPacket::fromPort() const
415{ 415{
416 return EXTRACT_16BITS( &_udphdr->source ); 416 return EXTRACT_16BITS( &_udphdr->source );
417} 417}
418 418
419 419
420int OUDPPacket::toPort() const 420int OUDPPacket::toPort() const
421{ 421{
422 return EXTRACT_16BITS( &_udphdr->dest ); 422 return EXTRACT_16BITS( &_udphdr->dest );
423} 423}
424 424
425 425
426int OUDPPacket::length() const 426int OUDPPacket::length() const
427{ 427{
428 return EXTRACT_16BITS( &_udphdr->len ); 428 return EXTRACT_16BITS( &_udphdr->len );
429} 429}
430 430
431 431
432int OUDPPacket::checksum() const 432int OUDPPacket::checksum() const
433{ 433{
434 return EXTRACT_16BITS( &_udphdr->check ); 434 return EXTRACT_16BITS( &_udphdr->check );
435} 435}
436 436
437 437
438/*====================================================================================== 438/*======================================================================================
439 * ODHCPPacket 439 * ODHCPPacket
440 *======================================================================================*/ 440 *======================================================================================*/
441 441
442 442
443ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) 443ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent )
444 :QObject( parent, "DHCP" ), _dhcphdr( data ) 444 :QObject( parent, "DHCP" ), _dhcphdr( data )
445 445
446{ 446{
447 odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl; 447 odebug << "ODHCPPacket::ODHCPPacket(): decoding DHCP information..." << oendl;
448 odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl; 448 odebug << "DHCP opcode seems to be " << _dhcphdr->op << ": " << ( isRequest() ? "REQUEST" : "REPLY" ) << oendl;
449 odebug << "clientAddress = " << clientAddress().toString() << oendl; 449 odebug << "clientAddress = " << clientAddress().toString() << oendl;
450 odebug << " yourAddress = " << yourAddress().toString() << oendl; 450 odebug << " yourAddress = " << yourAddress().toString() << oendl;
451 odebug << "serverAddress = " << serverAddress().toString() << oendl; 451 odebug << "serverAddress = " << serverAddress().toString() << oendl;
452 odebug << " relayAddress = " << relayAddress().toString() << oendl; 452 odebug << " relayAddress = " << relayAddress().toString() << oendl;
453 odebug << "parsing DHCP options..." << oendl; 453 odebug << "parsing DHCP options..." << oendl;
454 454
455 _type = 0; 455 _type = 0;
456 456
457 const unsigned char* option = &_dhcphdr->options[4]; 457 const unsigned char* option = &_dhcphdr->options[4];
458 char tag = -1; 458 char tag = -1;
459 char len = -1; 459 char len = -1;
460 460
461 while ( ( tag = *option++ ) != -1 /* end of option field */ ) 461 while ( ( tag = *option++ ) != -1 /* end of option field */ )
462 { 462 {
463 len = *option++; 463 len = *option++;
464 odebug << "recognized DHCP option #" << tag << ", length " << len << oendl; 464 odebug << "recognized DHCP option #" << tag << ", length " << len << oendl;
465 465
466 if ( tag == DHO_DHCP_MESSAGE_TYPE ) 466 if ( tag == DHO_DHCP_MESSAGE_TYPE )
467 _type = *option; 467 _type = *option;
468 468
469 option += len; 469 option += len;
470 if ( option >= end ) 470 if ( option >= end )
471 { 471 {
472 owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl; 472 owarn << "DHCP parsing ERROR: sanity check says the packet is at its end!" << oendl;
473 break; 473 break;
474 } 474 }
475 } 475 }
476 476
477 odebug << "DHCP type seems to be << " << type() << oendl; 477 odebug << "DHCP type seems to be << " << type() << oendl;
478} 478}
479 479
480 480
481ODHCPPacket::~ODHCPPacket() 481ODHCPPacket::~ODHCPPacket()
482{ 482{
483} 483}
484 484
485 485
486bool ODHCPPacket::isRequest() const 486bool ODHCPPacket::isRequest() const
487{ 487{
488 return ( _dhcphdr->op == 01 ); 488 return ( _dhcphdr->op == 01 );
489} 489}
490 490
491 491
492bool ODHCPPacket::isReply() const 492bool ODHCPPacket::isReply() const
493{ 493{
494 return ( _dhcphdr->op == 02 ); 494 return ( _dhcphdr->op == 02 );
495} 495}
496 496
497 497
498QString ODHCPPacket::type() const 498QString ODHCPPacket::type() const
499{ 499{
500 switch ( _type ) 500 switch ( _type )
501 { 501 {
502 case 1: return "DISCOVER"; 502 case 1: return "DISCOVER";
503 case 2: return "OFFER"; 503 case 2: return "OFFER";
504 case 3: return "REQUEST"; 504 case 3: return "REQUEST";
505 case 4: return "DECLINE"; 505 case 4: return "DECLINE";
506 case 5: return "ACK"; 506 case 5: return "ACK";
507 case 6: return "NAK"; 507 case 6: return "NAK";
508 case 7: return "RELEASE"; 508 case 7: return "RELEASE";
509 case 8: return "INFORM"; 509 case 8: return "INFORM";
510 default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>"; 510 default: owarn << "ODHCPPacket::type(): invalid DHCP type " << _dhcphdr->op << oendl; return "<unknown>";
511 } 511 }
512} 512}
513 513
514 514
515QHostAddress ODHCPPacket::clientAddress() const 515QHostAddress ODHCPPacket::clientAddress() const
516{ 516{
517 return EXTRACT_32BITS( &_dhcphdr->ciaddr ); 517 return EXTRACT_32BITS( &_dhcphdr->ciaddr );
518} 518}
519 519
520 520
521QHostAddress ODHCPPacket::yourAddress() const 521QHostAddress ODHCPPacket::yourAddress() const
522{ 522{
523 return EXTRACT_32BITS( &_dhcphdr->yiaddr ); 523 return EXTRACT_32BITS( &_dhcphdr->yiaddr );
524} 524}
525 525
526 526
527QHostAddress ODHCPPacket::serverAddress() const 527QHostAddress ODHCPPacket::serverAddress() const
528{ 528{
529 return EXTRACT_32BITS( &_dhcphdr->siaddr ); 529 return EXTRACT_32BITS( &_dhcphdr->siaddr );
530} 530}
531 531
532 532
533QHostAddress ODHCPPacket::relayAddress() const 533QHostAddress ODHCPPacket::relayAddress() const
534{ 534{
535 return EXTRACT_32BITS( &_dhcphdr->giaddr ); 535 return EXTRACT_32BITS( &_dhcphdr->giaddr );
536} 536}
537 537
538 538
539OMacAddress ODHCPPacket::clientMacAddress() const 539OMacAddress ODHCPPacket::clientMacAddress() const
540{ 540{
541 return OMacAddress( _dhcphdr->chaddr ); 541 return OMacAddress( _dhcphdr->chaddr );
542} 542}
543 543
544 544
545/*====================================================================================== 545/*======================================================================================
546 * OTCPPacket 546 * OTCPPacket
547 *======================================================================================*/ 547 *======================================================================================*/
548 548
549 549
550OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent ) 550OTCPPacket::OTCPPacket( const unsigned char* end, const struct tcphdr* data, QObject* parent )
551 :QObject( parent, "TCP" ), _tcphdr( data ) 551 :QObject( parent, "TCP" ), _tcphdr( data )
552 552
553{ 553{
554 odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl; 554 odebug << "OTCPPacket::OTCPPacket(): decoding TCP header..." << oendl;
555} 555}
556 556
557 557
558OTCPPacket::~OTCPPacket() 558OTCPPacket::~OTCPPacket()
559{ 559{
560} 560}
561 561
562 562
563int OTCPPacket::fromPort() const 563int OTCPPacket::fromPort() const
564{ 564{
565 return EXTRACT_16BITS( &_tcphdr->source ); 565 return EXTRACT_16BITS( &_tcphdr->source );
566} 566}
567 567
568 568
569int OTCPPacket::toPort() const 569int OTCPPacket::toPort() const
570{ 570{
571 return EXTRACT_16BITS( &_tcphdr->dest ); 571 return EXTRACT_16BITS( &_tcphdr->dest );
572} 572}
573 573
574 574
575int OTCPPacket::seq() const 575int OTCPPacket::seq() const
576{ 576{
577 return EXTRACT_16BITS( &_tcphdr->seq ); 577 return EXTRACT_16BITS( &_tcphdr->seq );
578} 578}
579 579
580 580
581int OTCPPacket::ack() const 581int OTCPPacket::ack() const
582{ 582{
583 return EXTRACT_16BITS( &_tcphdr->ack_seq ); 583 return EXTRACT_16BITS( &_tcphdr->ack_seq );
584} 584}
585 585
586 586
587int OTCPPacket::window() const 587int OTCPPacket::window() const
588{ 588{
589 return EXTRACT_16BITS( &_tcphdr->window ); 589 return EXTRACT_16BITS( &_tcphdr->window );
590} 590}
591 591
592 592
593int OTCPPacket::checksum() const 593int OTCPPacket::checksum() const
594{ 594{
595 return EXTRACT_16BITS( &_tcphdr->check ); 595 return EXTRACT_16BITS( &_tcphdr->check );
596} 596}
597 597
598/*====================================================================================== 598/*======================================================================================
599 * OPrismHeaderPacket 599 * OPrismHeaderPacket
600 *======================================================================================*/ 600 *======================================================================================*/
601 601
602 602
603OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent ) 603OPrismHeaderPacket::OPrismHeaderPacket( const unsigned char* end, const struct prism_hdr* data, QObject* parent )
604 :QObject( parent, "Prism" ), _header( data ) 604 :QObject( parent, "Prism" ), _header( data )
605 605
606{ 606{
607 odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl; 607 odebug << "OPrismHeaderPacket::OPrismHeaderPacket(): decoding PRISM header..." << oendl;