summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/opcap.cpp39
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,476 +1,479 @@
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>
36using 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
48using namespace Opie::Core;
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( 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
90OPacket::~OPacket() 92OPacket::~OPacket()
91{ 93{
92 qDebug( "OPacket::~OPacket( %s )", name() ); 94 odebug << "~OPacket( " << name() << " )" << oendl;
95 delete _data;
93} 96}
94 97
95 98
96timevalstruct OPacket::timeval() const 99timevalstruct OPacket::timeval() const
97{ 100{
98 return _hdr.ts; 101 return _hdr.ts;
99} 102}
100 103
101 104
102int OPacket::caplen() const 105int OPacket::caplen() const
103{ 106{
104 return _hdr.caplen; 107 return _hdr.caplen;
105} 108}
106 109
107 110
108void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 111void 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
121QString OPacket::dumpStructure() const 124QString 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
127QString OPacket::_dumpStructure( QObjectList* l ) const 130QString 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
143QString OPacket::dump( int bpl ) const 146QString 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
183int OPacket::len() const 186int OPacket::len() const
184{ 187{
185 return _hdr.len; 188 return _hdr.len;
186} 189}
187 190
188 191
189QTextStream& operator<<( QTextStream& s, const OPacket& p ) 192QTextStream& 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
199OEthernetPacket::OEthernetPacket( const unsigned char* end, const struct ether_header* data, QObject* parent ) 202OEthernetPacket::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
222OEthernetPacket::~OEthernetPacket() 225OEthernetPacket::~OEthernetPacket()
223{ 226{
224} 227}
225 228
226 229
227OMacAddress OEthernetPacket::sourceAddress() const 230OMacAddress OEthernetPacket::sourceAddress() const
228{ 231{
229 return OMacAddress( _ether->ether_shost ); 232 return OMacAddress( _ether->ether_shost );
230} 233}
231 234
232 235
233OMacAddress OEthernetPacket::destinationAddress() const 236OMacAddress OEthernetPacket::destinationAddress() const
234{ 237{
235 return OMacAddress( _ether->ether_dhost ); 238 return OMacAddress( _ether->ether_dhost );
236} 239}
237 240
238int OEthernetPacket::type() const 241int 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
249OIPPacket::OIPPacket( const unsigned char* end, const struct iphdr* data, QObject* parent ) 252OIPPacket::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
266OIPPacket::~OIPPacket() 269OIPPacket::~OIPPacket()
267{ 270{
268} 271}
269 272
270 273
271QHostAddress OIPPacket::fromIPAddress() const 274QHostAddress OIPPacket::fromIPAddress() const
272{ 275{
273 return EXTRACT_32BITS( &_iphdr->saddr ); 276 return EXTRACT_32BITS( &_iphdr->saddr );
274} 277}
275 278
276 279
277QHostAddress OIPPacket::toIPAddress() const 280QHostAddress OIPPacket::toIPAddress() const
278{ 281{
279 return EXTRACT_32BITS( &_iphdr->saddr ); 282 return EXTRACT_32BITS( &_iphdr->saddr );
280} 283}
281 284
282 285
283int OIPPacket::tos() const 286int OIPPacket::tos() const
284{ 287{
285 return _iphdr->tos; 288 return _iphdr->tos;
286} 289}
287 290
288 291
289int OIPPacket::len() const 292int 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
295int OIPPacket::id() const 298int OIPPacket::id() const
296{ 299{
297 return EXTRACT_16BITS( &_iphdr->id ); 300 return EXTRACT_16BITS( &_iphdr->id );
298} 301}
299 302
300 303
301int OIPPacket::offset() const 304int 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
307int OIPPacket::ttl() const 310int OIPPacket::ttl() const
308{ 311{
309 return _iphdr->ttl; 312 return _iphdr->ttl;
310} 313}
311 314
312 315
313int OIPPacket::protocol() const 316int OIPPacket::protocol() const
314{ 317{
315 return _iphdr->protocol; 318 return _iphdr->protocol;
316} 319}
317 320
318 321
319int OIPPacket::checksum() const 322int 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
329OARPPacket::OARPPacket( const unsigned char* end, const struct myarphdr* data, QObject* parent ) 332OARPPacket::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
339OARPPacket::~OARPPacket() 342OARPPacket::~OARPPacket()
340{ 343{
341} 344}
342 345
343 346
344QString OARPPacket::type() const 347QString 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
360QHostAddress OARPPacket::senderIPV4Address() const 363QHostAddress 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
366QHostAddress OARPPacket::targetIPV4Address() const 369QHostAddress 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
372OMacAddress OARPPacket::senderMacAddress() const 375OMacAddress OARPPacket::senderMacAddress() const
373{ 376{
374 return OMacAddress( _arphdr->ar_sha ); 377 return OMacAddress( _arphdr->ar_sha );
375} 378}
376 379
377 380
378OMacAddress OARPPacket::targetMacAddress() const 381OMacAddress 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
389OUDPPacket::OUDPPacket( const unsigned char* end, const struct udphdr* data, QObject* parent ) 392OUDPPacket::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
408OUDPPacket::~OUDPPacket() 411OUDPPacket::~OUDPPacket()
409{ 412{
410} 413}
411 414
412 415
413int OUDPPacket::fromPort() const 416int OUDPPacket::fromPort() const
414{ 417{
415 return EXTRACT_16BITS( &_udphdr->source ); 418 return EXTRACT_16BITS( &_udphdr->source );
416} 419}
417 420
418 421
419int OUDPPacket::toPort() const 422int OUDPPacket::toPort() const
420{ 423{
421 return EXTRACT_16BITS( &_udphdr->dest ); 424 return EXTRACT_16BITS( &_udphdr->dest );
422} 425}
423 426
424 427
425int OUDPPacket::length() const 428int OUDPPacket::length() const
426{ 429{
427 return EXTRACT_16BITS( &_udphdr->len ); 430 return EXTRACT_16BITS( &_udphdr->len );
428} 431}
429 432
430 433
431int OUDPPacket::checksum() const 434int 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
442ODHCPPacket::ODHCPPacket( const unsigned char* end, const struct dhcp_packet* data, QObject* parent ) 445ODHCPPacket::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;