summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp2
-rw-r--r--libopie2/opienet/opcap.cpp2
2 files changed, 2 insertions, 2 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 767651e..dc2e388 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -84,965 +84,965 @@ void ONetwork::synchronize()
84 if ( !hasFile ) 84 if ( !hasFile )
85 { 85 {
86 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 86 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
87 return; 87 return;
88 } 88 }
89 QTextStream s( &f ); 89 QTextStream s( &f );
90 s.readLine(); 90 s.readLine();
91 s.readLine(); 91 s.readLine();
92 while ( !s.atEnd() ) 92 while ( !s.atEnd() )
93 { 93 {
94 s >> str; 94 s >> str;
95 str.truncate( str.find( ':' ) ); 95 str.truncate( str.find( ':' ) );
96 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 96 qDebug( "ONetwork: found interface '%s'", (const char*) str );
97 ONetworkInterface* iface; 97 ONetworkInterface* iface;
98 if ( isWirelessInterface( str ) ) 98 if ( isWirelessInterface( str ) )
99 { 99 {
100 iface = new OWirelessNetworkInterface( this, (const char*) str ); 100 iface = new OWirelessNetworkInterface( this, (const char*) str );
101 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 101 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
102 } 102 }
103 else 103 else
104 { 104 {
105 iface = new ONetworkInterface( this, (const char*) str ); 105 iface = new ONetworkInterface( this, (const char*) str );
106 } 106 }
107 _interfaces.insert( str, iface ); 107 _interfaces.insert( str, iface );
108 s.readLine(); 108 s.readLine();
109 } 109 }
110} 110}
111 111
112 112
113short ONetwork::wirelessExtensionVersion() 113short ONetwork::wirelessExtensionVersion()
114{ 114{
115 return WIRELESS_EXT; 115 return WIRELESS_EXT;
116} 116}
117 117
118 118
119int ONetwork::count() const 119int ONetwork::count() const
120{ 120{
121 return _interfaces.count(); 121 return _interfaces.count();
122} 122}
123 123
124 124
125ONetworkInterface* ONetwork::interface( const QString& iface ) const 125ONetworkInterface* ONetwork::interface( const QString& iface ) const
126{ 126{
127 return _interfaces[iface]; 127 return _interfaces[iface];
128} 128}
129 129
130 130
131ONetwork* ONetwork::instance() 131ONetwork* ONetwork::instance()
132{ 132{
133 if ( !_instance ) _instance = new ONetwork(); 133 if ( !_instance ) _instance = new ONetwork();
134 return _instance; 134 return _instance;
135} 135}
136 136
137 137
138ONetwork::InterfaceIterator ONetwork::iterator() const 138ONetwork::InterfaceIterator ONetwork::iterator() const
139{ 139{
140 return ONetwork::InterfaceIterator( _interfaces ); 140 return ONetwork::InterfaceIterator( _interfaces );
141} 141}
142 142
143 143
144bool ONetwork::isWirelessInterface( const char* name ) const 144bool ONetwork::isWirelessInterface( const char* name ) const
145{ 145{
146 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 146 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
147 struct iwreq iwr; 147 struct iwreq iwr;
148 memset( &iwr, 0, sizeof( struct iwreq ) ); 148 memset( &iwr, 0, sizeof( struct iwreq ) );
149 strcpy( (char*) &iwr.ifr_name, name ); 149 strcpy( (char*) &iwr.ifr_name, name );
150 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 150 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
151 return result != -1; 151 return result != -1;
152} 152}
153 153
154/*====================================================================================== 154/*======================================================================================
155 * ONetworkInterface 155 * ONetworkInterface
156 *======================================================================================*/ 156 *======================================================================================*/
157 157
158ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 158ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
159 :QObject( parent, name ), 159 :QObject( parent, name ),
160 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 160 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
161{ 161{
162 qDebug( "ONetworkInterface::ONetworkInterface()" ); 162 qDebug( "ONetworkInterface::ONetworkInterface()" );
163 init(); 163 init();
164} 164}
165 165
166 166
167struct ifreq& ONetworkInterface::ifr() const 167struct ifreq& ONetworkInterface::ifr() const
168{ 168{
169 return _ifr; 169 return _ifr;
170} 170}
171 171
172 172
173void ONetworkInterface::init() 173void ONetworkInterface::init()
174{ 174{
175 qDebug( "ONetworkInterface::init()" ); 175 qDebug( "ONetworkInterface::init()" );
176 176
177 memset( &_ifr, 0, sizeof( struct ifreq ) ); 177 memset( &_ifr, 0, sizeof( struct ifreq ) );
178 178
179 if ( _sfd == -1 ) 179 if ( _sfd == -1 )
180 { 180 {
181 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); 181 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() );
182 return; 182 return;
183 } 183 }
184} 184}
185 185
186 186
187bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 187bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
188{ 188{
189 int result = ::ioctl( _sfd, call, &ifreq ); 189 int result = ::ioctl( _sfd, call, &ifreq );
190 if ( result == -1 ) 190 if ( result == -1 )
191 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 191 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
192 else 192 else
193 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); 193 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call );
194 return ( result != -1 ); 194 return ( result != -1 );
195} 195}
196 196
197 197
198bool ONetworkInterface::ioctl( int call ) const 198bool ONetworkInterface::ioctl( int call ) const
199{ 199{
200 strcpy( _ifr.ifr_name, name() ); 200 strcpy( _ifr.ifr_name, name() );
201 return ioctl( call, _ifr ); 201 return ioctl( call, _ifr );
202} 202}
203 203
204 204
205bool ONetworkInterface::isLoopback() const 205bool ONetworkInterface::isLoopback() const
206{ 206{
207 ioctl( SIOCGIFFLAGS ); 207 ioctl( SIOCGIFFLAGS );
208 return _ifr.ifr_flags & IFF_LOOPBACK; 208 return _ifr.ifr_flags & IFF_LOOPBACK;
209} 209}
210 210
211 211
212bool ONetworkInterface::setUp( bool b ) 212bool ONetworkInterface::setUp( bool b )
213{ 213{
214 ioctl( SIOCGIFFLAGS ); 214 ioctl( SIOCGIFFLAGS );
215 if ( b ) _ifr.ifr_flags |= IFF_UP; 215 if ( b ) _ifr.ifr_flags |= IFF_UP;
216 else _ifr.ifr_flags &= (~IFF_UP); 216 else _ifr.ifr_flags &= (~IFF_UP);
217 return ioctl( SIOCSIFFLAGS ); 217 return ioctl( SIOCSIFFLAGS );
218} 218}
219 219
220 220
221bool ONetworkInterface::isUp() const 221bool ONetworkInterface::isUp() const
222{ 222{
223 ioctl( SIOCGIFFLAGS ); 223 ioctl( SIOCGIFFLAGS );
224 return _ifr.ifr_flags & IFF_UP; 224 return _ifr.ifr_flags & IFF_UP;
225} 225}
226 226
227 227
228void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) 228void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
229{ 229{
230 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 230 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
231 sa->sin_family = AF_INET; 231 sa->sin_family = AF_INET;
232 sa->sin_port = 0; 232 sa->sin_port = 0;
233 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 233 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
234 ioctl( SIOCSIFADDR ); 234 ioctl( SIOCSIFADDR );
235} 235}
236 236
237 237
238QString ONetworkInterface::ipV4Address() const 238QString ONetworkInterface::ipV4Address() const
239{ 239{
240 if ( ioctl( SIOCGIFADDR ) ) 240 if ( ioctl( SIOCGIFADDR ) )
241 { 241 {
242 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 242 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
243 //FIXME: Use QHostAddress here 243 //FIXME: Use QHostAddress here
244 return QString( inet_ntoa( sa->sin_addr ) ); 244 return QString( inet_ntoa( sa->sin_addr ) );
245 } 245 }
246 else 246 else
247 return "<unknown>"; 247 return "<unknown>";
248} 248}
249 249
250 250
251void ONetworkInterface::setMacAddress( const OMacAddress& addr ) 251void ONetworkInterface::setMacAddress( const OMacAddress& addr )
252{ 252{
253 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 253 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
254 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); 254 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
255 ioctl( SIOCSIFHWADDR ); 255 ioctl( SIOCSIFHWADDR );
256} 256}
257 257
258 258
259OMacAddress ONetworkInterface::macAddress() const 259OMacAddress ONetworkInterface::macAddress() const
260{ 260{
261 if ( ioctl( SIOCGIFHWADDR ) ) 261 if ( ioctl( SIOCGIFHWADDR ) )
262 { 262 {
263 return OMacAddress( _ifr ); 263 return OMacAddress( _ifr );
264 } 264 }
265 else 265 else
266 { 266 {
267 return OMacAddress::unknown; 267 return OMacAddress::unknown;
268 } 268 }
269} 269}
270 270
271 271
272void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) 272void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
273{ 273{
274 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 274 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
275 sa->sin_family = AF_INET; 275 sa->sin_family = AF_INET;
276 sa->sin_port = 0; 276 sa->sin_port = 0;
277 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 277 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
278 ioctl( SIOCSIFNETMASK ); 278 ioctl( SIOCSIFNETMASK );
279} 279}
280 280
281 281
282QString ONetworkInterface::ipV4Netmask() const 282QString ONetworkInterface::ipV4Netmask() const
283{ 283{
284 if ( ioctl( SIOCGIFNETMASK ) ) 284 if ( ioctl( SIOCGIFNETMASK ) )
285 { 285 {
286 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 286 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
287 //FIXME: Use QHostAddress here 287 //FIXME: Use QHostAddress here
288 return QString( inet_ntoa( sa->sin_addr ) ); 288 return QString( inet_ntoa( sa->sin_addr ) );
289 } 289 }
290 else 290 else
291 return "<unknown>"; 291 return "<unknown>";
292} 292}
293 293
294 294
295int ONetworkInterface::dataLinkType() const 295int ONetworkInterface::dataLinkType() const
296{ 296{
297 if ( ioctl( SIOCGIFHWADDR ) ) 297 if ( ioctl( SIOCGIFHWADDR ) )
298 { 298 {
299 return _ifr.ifr_hwaddr.sa_family; 299 return _ifr.ifr_hwaddr.sa_family;
300 } 300 }
301 else 301 else
302 { 302 {
303 return -1; 303 return -1;
304 } 304 }
305} 305}
306 306
307 307
308void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 308void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
309{ 309{
310 _mon = m; 310 _mon = m;
311 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); 311 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() );
312} 312}
313 313
314 314
315OMonitoringInterface* ONetworkInterface::monitoring() const 315OMonitoringInterface* ONetworkInterface::monitoring() const
316{ 316{
317 return _mon; 317 return _mon;
318} 318}
319 319
320 320
321ONetworkInterface::~ONetworkInterface() 321ONetworkInterface::~ONetworkInterface()
322{ 322{
323 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 323 qDebug( "ONetworkInterface::~ONetworkInterface()" );
324 if ( _sfd != -1 ) ::close( _sfd ); 324 if ( _sfd != -1 ) ::close( _sfd );
325} 325}
326 326
327 327
328bool ONetworkInterface::setPromiscuousMode( bool b ) 328bool ONetworkInterface::setPromiscuousMode( bool b )
329{ 329{
330 ioctl( SIOCGIFFLAGS ); 330 ioctl( SIOCGIFFLAGS );
331 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 331 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
332 else _ifr.ifr_flags &= (~IFF_PROMISC); 332 else _ifr.ifr_flags &= (~IFF_PROMISC);
333 return ioctl( SIOCSIFFLAGS ); 333 return ioctl( SIOCSIFFLAGS );
334} 334}
335 335
336 336
337bool ONetworkInterface::promiscuousMode() const 337bool ONetworkInterface::promiscuousMode() const
338{ 338{
339 ioctl( SIOCGIFFLAGS ); 339 ioctl( SIOCGIFFLAGS );
340 return _ifr.ifr_flags & IFF_PROMISC; 340 return _ifr.ifr_flags & IFF_PROMISC;
341} 341}
342 342
343 343
344bool ONetworkInterface::isWireless() const 344bool ONetworkInterface::isWireless() const
345{ 345{
346 return ioctl( SIOCGIWNAME ); 346 return ioctl( SIOCGIWNAME );
347} 347}
348 348
349 349
350/*====================================================================================== 350/*======================================================================================
351 * OChannelHopper 351 * OChannelHopper
352 *======================================================================================*/ 352 *======================================================================================*/
353 353
354OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 354OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
355 :QObject( 0, "Mickey's funky hopper" ), 355 :QObject( 0, "Mickey's funky hopper" ),
356 _iface( iface ), _interval( 0 ), _tid( 0 ) 356 _iface( iface ), _interval( 0 ), _tid( 0 )
357{ 357{
358 int _maxChannel = iface->channels()+1; 358 int _maxChannel = iface->channels()+1;
359 // generate fancy hopping sequence honoring the device capabilities 359 // generate fancy hopping sequence honoring the device capabilities
360 if ( _maxChannel >= 1 ) _channels.append( 1 ); 360 if ( _maxChannel >= 1 ) _channels.append( 1 );
361 if ( _maxChannel >= 7 ) _channels.append( 7 ); 361 if ( _maxChannel >= 7 ) _channels.append( 7 );
362 if ( _maxChannel >= 13 ) _channels.append( 13 ); 362 if ( _maxChannel >= 13 ) _channels.append( 13 );
363 if ( _maxChannel >= 2 ) _channels.append( 2 ); 363 if ( _maxChannel >= 2 ) _channels.append( 2 );
364 if ( _maxChannel >= 8 ) _channels.append( 8 ); 364 if ( _maxChannel >= 8 ) _channels.append( 8 );
365 if ( _maxChannel >= 3 ) _channels.append( 3 ); 365 if ( _maxChannel >= 3 ) _channels.append( 3 );
366 if ( _maxChannel >= 14 ) _channels.append( 14 ); 366 if ( _maxChannel >= 14 ) _channels.append( 14 );
367 if ( _maxChannel >= 9 ) _channels.append( 9 ); 367 if ( _maxChannel >= 9 ) _channels.append( 9 );
368 if ( _maxChannel >= 4 ) _channels.append( 4 ); 368 if ( _maxChannel >= 4 ) _channels.append( 4 );
369 if ( _maxChannel >= 10 ) _channels.append( 10 ); 369 if ( _maxChannel >= 10 ) _channels.append( 10 );
370 if ( _maxChannel >= 5 ) _channels.append( 5 ); 370 if ( _maxChannel >= 5 ) _channels.append( 5 );
371 if ( _maxChannel >= 11 ) _channels.append( 11 ); 371 if ( _maxChannel >= 11 ) _channels.append( 11 );
372 if ( _maxChannel >= 6 ) _channels.append( 6 ); 372 if ( _maxChannel >= 6 ) _channels.append( 6 );
373 if ( _maxChannel >= 12 ) _channels.append( 12 ); 373 if ( _maxChannel >= 12 ) _channels.append( 12 );
374 _channel = _channels.begin(); 374 _channel = _channels.begin();
375 375
376} 376}
377 377
378 378
379OChannelHopper::~OChannelHopper() 379OChannelHopper::~OChannelHopper()
380{ 380{
381} 381}
382 382
383 383
384bool OChannelHopper::isActive() const 384bool OChannelHopper::isActive() const
385{ 385{
386 return _tid; 386 return _tid;
387} 387}
388 388
389 389
390int OChannelHopper::channel() const 390int OChannelHopper::channel() const
391{ 391{
392 return *_channel; 392 return *_channel;
393} 393}
394 394
395 395
396void OChannelHopper::timerEvent( QTimerEvent* ) 396void OChannelHopper::timerEvent( QTimerEvent* )
397{ 397{
398 _iface->setChannel( *_channel ); 398 _iface->setChannel( *_channel );
399 emit( hopped( *_channel ) ); 399 emit( hopped( *_channel ) );
400 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 400 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
401 *_channel, (const char*) _iface->name() ); 401 *_channel, (const char*) _iface->name() );
402 if ( ++_channel == _channels.end() ) _channel = _channels.begin(); 402 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
403} 403}
404 404
405 405
406void OChannelHopper::setInterval( int interval ) 406void OChannelHopper::setInterval( int interval )
407{ 407{
408 if ( interval == _interval ) 408 if ( interval == _interval )
409 return; 409 return;
410 410
411 if ( _interval ) 411 if ( _interval )
412 killTimer( _tid ); 412 killTimer( _tid );
413 413
414 _tid = 0; 414 _tid = 0;
415 _interval = interval; 415 _interval = interval;
416 416
417 if ( _interval ) 417 if ( _interval )
418 { 418 {
419 _tid = startTimer( interval ); 419 _tid = startTimer( interval );
420 } 420 }
421} 421}
422 422
423 423
424int OChannelHopper::interval() const 424int OChannelHopper::interval() const
425{ 425{
426 return _interval; 426 return _interval;
427} 427}
428 428
429 429
430/*====================================================================================== 430/*======================================================================================
431 * OWirelessNetworkInterface 431 * OWirelessNetworkInterface
432 *======================================================================================*/ 432 *======================================================================================*/
433 433
434OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 434OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
435 :ONetworkInterface( parent, name ), _hopper( 0 ) 435 :ONetworkInterface( parent, name ), _hopper( 0 )
436{ 436{
437 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 437 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
438 init(); 438 init();
439} 439}
440 440
441 441
442OWirelessNetworkInterface::~OWirelessNetworkInterface() 442OWirelessNetworkInterface::~OWirelessNetworkInterface()
443{ 443{
444} 444}
445 445
446 446
447struct iwreq& OWirelessNetworkInterface::iwr() const 447struct iwreq& OWirelessNetworkInterface::iwr() const
448{ 448{
449 return _iwr; 449 return _iwr;
450} 450}
451 451
452 452
453void OWirelessNetworkInterface::init() 453void OWirelessNetworkInterface::init()
454{ 454{
455 qDebug( "OWirelessNetworkInterface::init()" ); 455 qDebug( "OWirelessNetworkInterface::init()" );
456 memset( &_iwr, 0, sizeof( struct iwreq ) ); 456 memset( &_iwr, 0, sizeof( struct iwreq ) );
457 buildChannelList(); 457 buildChannelList();
458 buildPrivateList(); 458 buildPrivateList();
459} 459}
460 460
461 461
462QString OWirelessNetworkInterface::associatedAP() const 462QString OWirelessNetworkInterface::associatedAP() const
463{ 463{
464 //FIXME: use OMacAddress 464 //FIXME: use OMacAddress
465 QString mac; 465 QString mac;
466 466
467 if ( ioctl( SIOCGIWAP ) ) 467 if ( ioctl( SIOCGIWAP ) )
468 { 468 {
469 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 469 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
470 _ifr.ifr_hwaddr.sa_data[0]&0xff, 470 _ifr.ifr_hwaddr.sa_data[0]&0xff,
471 _ifr.ifr_hwaddr.sa_data[1]&0xff, 471 _ifr.ifr_hwaddr.sa_data[1]&0xff,
472 _ifr.ifr_hwaddr.sa_data[2]&0xff, 472 _ifr.ifr_hwaddr.sa_data[2]&0xff,
473 _ifr.ifr_hwaddr.sa_data[3]&0xff, 473 _ifr.ifr_hwaddr.sa_data[3]&0xff,
474 _ifr.ifr_hwaddr.sa_data[4]&0xff, 474 _ifr.ifr_hwaddr.sa_data[4]&0xff,
475 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 475 _ifr.ifr_hwaddr.sa_data[5]&0xff );
476 } 476 }
477 else 477 else
478 { 478 {
479 mac = "<Unknown>"; 479 mac = "<Unknown>";
480 } 480 }
481 return mac; 481 return mac;
482} 482}
483 483
484 484
485void OWirelessNetworkInterface::buildChannelList() 485void OWirelessNetworkInterface::buildChannelList()
486{ 486{
487 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 487 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
488 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 488 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
489 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 489 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
490 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 490 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
491 //ML: _too much_ space. This is damn shitty crap *sigh* 491 //ML: _too much_ space. This is damn shitty crap *sigh*
492 //ML: We allocate a large memory region in RAM and check whether the 492 //ML: We allocate a large memory region in RAM and check whether the
493 //ML: driver pollutes this extra space. The complaint will be made on stdout, 493 //ML: driver pollutes this extra space. The complaint will be made on stdout,
494 //ML: so please forward this... 494 //ML: so please forward this...
495 495
496 struct iwreq wrq; 496 struct iwreq wrq;
497 int len = sizeof( struct iw_range )*2; 497 int len = sizeof( struct iw_range )*2;
498 char *buffer = (char*) malloc( len ); 498 char *buffer = (char*) malloc( len );
499 //FIXME: Validate if we actually got the memory block 499 //FIXME: Validate if we actually got the memory block
500 memset( buffer, 0, len ); 500 memset( buffer, 0, len );
501 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 501 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
502 wrq.u.data.pointer = (caddr_t) buffer; 502 wrq.u.data.pointer = (caddr_t) buffer;
503 wrq.u.data.length = sizeof( struct iw_range ); 503 wrq.u.data.length = sizeof( struct iw_range );
504 wrq.u.data.flags = 0; 504 wrq.u.data.flags = 0;
505 505
506 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 506 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
507 { 507 {
508 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); 508 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) );
509 _channels.insert( 2412, 1 ); // 2.412 GHz 509 _channels.insert( 2412, 1 ); // 2.412 GHz
510 _channels.insert( 2417, 2 ); // 2.417 GHz 510 _channels.insert( 2417, 2 ); // 2.417 GHz
511 _channels.insert( 2422, 3 ); // 2.422 GHz 511 _channels.insert( 2422, 3 ); // 2.422 GHz
512 _channels.insert( 2427, 4 ); // 2.427 GHz 512 _channels.insert( 2427, 4 ); // 2.427 GHz
513 _channels.insert( 2432, 5 ); // 2.432 GHz 513 _channels.insert( 2432, 5 ); // 2.432 GHz
514 _channels.insert( 2437, 6 ); // 2.437 GHz 514 _channels.insert( 2437, 6 ); // 2.437 GHz
515 _channels.insert( 2442, 7 ); // 2.442 GHz 515 _channels.insert( 2442, 7 ); // 2.442 GHz
516 _channels.insert( 2447, 8 ); // 2.447 GHz 516 _channels.insert( 2447, 8 ); // 2.447 GHz
517 _channels.insert( 2452, 9 ); // 2.452 GHz 517 _channels.insert( 2452, 9 ); // 2.452 GHz
518 _channels.insert( 2457, 10 ); // 2.457 GHz 518 _channels.insert( 2457, 10 ); // 2.457 GHz
519 _channels.insert( 2462, 11 ); // 2.462 GHz 519 _channels.insert( 2462, 11 ); // 2.462 GHz
520 } 520 }
521 else 521 else
522 { 522 {
523 // <check if the driver overwrites stuff> 523 // <check if the driver overwrites stuff>
524 int max = 0; 524 int max = 0;
525 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 525 for ( int r = sizeof( struct iw_range ); r < len; r++ )
526 if (buffer[r] != 0) 526 if (buffer[r] != 0)
527 max = r; 527 max = r;
528 if (max > 0) 528 if (max > 0)
529 { 529 {
530 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" 530 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'"
531 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); 531 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
532 } 532 }
533 // </check if the driver overwrites stuff> 533 // </check if the driver overwrites stuff>
534 534
535 struct iw_range range; 535 struct iw_range range;
536 memcpy( &range, buffer, sizeof range ); 536 memcpy( &range, buffer, sizeof range );
537 537
538 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); 538 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency );
539 for ( int i = 0; i < range.num_frequency; ++i ) 539 for ( int i = 0; i < range.num_frequency; ++i )
540 { 540 {
541 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 541 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
542 _channels.insert( freq, i+1 ); 542 _channels.insert( freq, i+1 );
543 } 543 }
544 } 544 }
545 545
546 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); 546 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." );
547 free(buffer); 547 free(buffer);
548} 548}
549 549
550 550
551void OWirelessNetworkInterface::buildPrivateList() 551void OWirelessNetworkInterface::buildPrivateList()
552{ 552{
553 qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); 553 qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
554 554
555 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 555 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
556 556
557 _iwr.u.data.pointer = (char*) &priv; 557 _iwr.u.data.pointer = (char*) &priv;
558 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 558 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
559 _iwr.u.data.flags = 0; 559 _iwr.u.data.flags = 0;
560 560
561 if ( !wioctl( SIOCGIWPRIV ) ) 561 if ( !wioctl( SIOCGIWPRIV ) )
562 { 562 {
563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); 563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
564 return; 564 return;
565 } 565 }
566 566
567 for ( int i = 0; i < _iwr.u.data.length; ++i ) 567 for ( int i = 0; i < _iwr.u.data.length; ++i )
568 { 568 {
569 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 569 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
570 } 570 }
571 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 571 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
572} 572}
573 573
574 574
575int OWirelessNetworkInterface::channel() const 575int OWirelessNetworkInterface::channel() const
576{ 576{
577 //FIXME: When monitoring enabled, then use it 577 //FIXME: When monitoring enabled, then use it
578 //FIXME: to gather the current RF channel 578 //FIXME: to gather the current RF channel
579 //FIXME: Until then, get active channel from hopper. 579 //FIXME: Until then, get active channel from hopper.
580 if ( _hopper && _hopper->isActive() ) 580 if ( _hopper && _hopper->isActive() )
581 return _hopper->channel(); 581 return _hopper->channel();
582 582
583 if ( !wioctl( SIOCGIWFREQ ) ) 583 if ( !wioctl( SIOCGIWFREQ ) )
584 { 584 {
585 return -1; 585 return -1;
586 } 586 }
587 else 587 else
588 { 588 {
589 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 589 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
590 } 590 }
591} 591}
592 592
593 593
594void OWirelessNetworkInterface::setChannel( int c ) const 594void OWirelessNetworkInterface::setChannel( int c ) const
595{ 595{
596 if ( c ) 596 if ( !c )
597 { 597 {
598 qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" ); 598 qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" );
599 return; 599 return;
600 } 600 }
601 601
602 if ( !_mon ) 602 if ( !_mon )
603 { 603 {
604 memset( &_iwr, 0, sizeof( struct iwreq ) ); 604 memset( &_iwr, 0, sizeof( struct iwreq ) );
605 _iwr.u.freq.m = c; 605 _iwr.u.freq.m = c;
606 _iwr.u.freq.e = 0; 606 _iwr.u.freq.e = 0;
607 wioctl( SIOCSIWFREQ ); 607 wioctl( SIOCSIWFREQ );
608 } 608 }
609 else 609 else
610 { 610 {
611 _mon->setChannel( c ); 611 _mon->setChannel( c );
612 } 612 }
613} 613}
614 614
615 615
616double OWirelessNetworkInterface::frequency() const 616double OWirelessNetworkInterface::frequency() const
617{ 617{
618 if ( !wioctl( SIOCGIWFREQ ) ) 618 if ( !wioctl( SIOCGIWFREQ ) )
619 { 619 {
620 return -1.0; 620 return -1.0;
621 } 621 }
622 else 622 else
623 { 623 {
624 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 624 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
625 } 625 }
626} 626}
627 627
628 628
629int OWirelessNetworkInterface::channels() const 629int OWirelessNetworkInterface::channels() const
630{ 630{
631 return _channels.count(); 631 return _channels.count();
632} 632}
633 633
634 634
635void OWirelessNetworkInterface::setChannelHopping( int interval ) 635void OWirelessNetworkInterface::setChannelHopping( int interval )
636{ 636{
637 if ( !_hopper ) _hopper = new OChannelHopper( this ); 637 if ( !_hopper ) _hopper = new OChannelHopper( this );
638 _hopper->setInterval( interval ); 638 _hopper->setInterval( interval );
639 //FIXME: When and by whom will the channel hopper be deleted? 639 //FIXME: When and by whom will the channel hopper be deleted?
640 //TODO: rely on QObject hierarchy 640 //TODO: rely on QObject hierarchy
641} 641}
642 642
643 643
644int OWirelessNetworkInterface::channelHopping() const 644int OWirelessNetworkInterface::channelHopping() const
645{ 645{
646 return _hopper->interval(); 646 return _hopper->interval();
647} 647}
648 648
649 649
650OChannelHopper* OWirelessNetworkInterface::channelHopper() const 650OChannelHopper* OWirelessNetworkInterface::channelHopper() const
651{ 651{
652 return _hopper; 652 return _hopper;
653} 653}
654 654
655 655
656void OWirelessNetworkInterface::setMode( const QString& mode ) 656void OWirelessNetworkInterface::setMode( const QString& mode )
657{ 657{
658 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; 658 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO;
659 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; 659 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
660 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; 660 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
661 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; 661 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
662 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; 662 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
663 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; 663 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
664 #if WIRELESS_EXT > 14 664 #if WIRELESS_EXT > 14
665 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; 665 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
666 #endif 666 #endif
667 else 667 else
668 { 668 {
669 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); 669 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
670 return; 670 return;
671 } 671 }
672 wioctl( SIOCSIWMODE ); 672 wioctl( SIOCSIWMODE );
673} 673}
674 674
675 675
676QString OWirelessNetworkInterface::mode() const 676QString OWirelessNetworkInterface::mode() const
677{ 677{
678 if ( !wioctl( SIOCGIWMODE ) ) 678 if ( !wioctl( SIOCGIWMODE ) )
679 { 679 {
680 return "<unknown>"; 680 return "<unknown>";
681 } 681 }
682 switch ( _iwr.u.mode ) 682 switch ( _iwr.u.mode )
683 { 683 {
684 case IW_MODE_AUTO: return "auto"; 684 case IW_MODE_AUTO: return "auto";
685 case IW_MODE_ADHOC: return "adhoc"; 685 case IW_MODE_ADHOC: return "adhoc";
686 case IW_MODE_INFRA: return "managed"; 686 case IW_MODE_INFRA: return "managed";
687 case IW_MODE_MASTER: return "master"; 687 case IW_MODE_MASTER: return "master";
688 case IW_MODE_REPEAT: return "repeater"; 688 case IW_MODE_REPEAT: return "repeater";
689 case IW_MODE_SECOND: return "secondary"; 689 case IW_MODE_SECOND: return "secondary";
690 #if WIRELESS_EXT > 14 690 #if WIRELESS_EXT > 14
691 case IW_MODE_MONITOR: return "monitor"; 691 case IW_MODE_MONITOR: return "monitor";
692 #endif 692 #endif
693 default: assert( 0 ); // shouldn't happen 693 default: assert( 0 ); // shouldn't happen
694 } 694 }
695} 695}
696 696
697 697
698void OWirelessNetworkInterface::setMonitorMode( bool b ) 698void OWirelessNetworkInterface::setMonitorMode( bool b )
699{ 699{
700 if ( _mon ) 700 if ( _mon )
701 _mon->setEnabled( b ); 701 _mon->setEnabled( b );
702 else 702 else
703 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 703 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
704} 704}
705 705
706 706
707bool OWirelessNetworkInterface::monitorMode() const 707bool OWirelessNetworkInterface::monitorMode() const
708{ 708{
709 qDebug( "dataLinkType = %d", dataLinkType() ); 709 qDebug( "dataLinkType = %d", dataLinkType() );
710 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); 710 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
711 // 802 is the header type for PRISM - Linux support for this is pending... 711 // 802 is the header type for PRISM - Linux support for this is pending...
712} 712}
713 713
714 714
715void OWirelessNetworkInterface::setNickName( const QString& nickname ) 715void OWirelessNetworkInterface::setNickName( const QString& nickname )
716{ 716{
717 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 717 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
718 _iwr.u.essid.length = nickname.length(); 718 _iwr.u.essid.length = nickname.length();
719 wioctl( SIOCSIWNICKN ); 719 wioctl( SIOCSIWNICKN );
720} 720}
721 721
722 722
723QString OWirelessNetworkInterface::nickName() const 723QString OWirelessNetworkInterface::nickName() const
724{ 724{
725 char str[IW_ESSID_MAX_SIZE]; 725 char str[IW_ESSID_MAX_SIZE];
726 _iwr.u.data.pointer = &str[0]; 726 _iwr.u.data.pointer = &str[0];
727 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 727 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
728 if ( !wioctl( SIOCGIWNICKN ) ) 728 if ( !wioctl( SIOCGIWNICKN ) )
729 { 729 {
730 return "<unknown>"; 730 return "<unknown>";
731 } 731 }
732 else 732 else
733 { 733 {
734 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 734 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
735 return str; 735 return str;
736 } 736 }
737} 737}
738 738
739 739
740void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 740void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
741{ 741{
742 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 742 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
743 if ( !priv ) 743 if ( !priv )
744 { 744 {
745 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 745 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
746 return; 746 return;
747 } 747 }
748 if ( priv->numberSetArgs() != numargs ) 748 if ( priv->numberSetArgs() != numargs )
749 { 749 {
750 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 750 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
751 return; 751 return;
752 } 752 }
753 753
754 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 754 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
755 memset( &_iwr, 0, sizeof _iwr ); 755 memset( &_iwr, 0, sizeof _iwr );
756 va_list argp; 756 va_list argp;
757 va_start( argp, numargs ); 757 va_start( argp, numargs );
758 for ( int i = 0; i < numargs; ++i ) 758 for ( int i = 0; i < numargs; ++i )
759 { 759 {
760 priv->setParameter( i, va_arg( argp, int ) ); 760 priv->setParameter( i, va_arg( argp, int ) );
761 } 761 }
762 va_end( argp ); 762 va_end( argp );
763 priv->invoke(); 763 priv->invoke();
764} 764}
765 765
766 766
767void OWirelessNetworkInterface::getPrivate( const QString& call ) 767void OWirelessNetworkInterface::getPrivate( const QString& call )
768{ 768{
769 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); 769 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
770} 770}
771 771
772 772
773bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 773bool OWirelessNetworkInterface::hasPrivate( const QString& call )
774{ 774{
775 return child( (const char*) call ); 775 return child( (const char*) call );
776} 776}
777 777
778 778
779QString OWirelessNetworkInterface::SSID() const 779QString OWirelessNetworkInterface::SSID() const
780{ 780{
781 char str[IW_ESSID_MAX_SIZE]; 781 char str[IW_ESSID_MAX_SIZE];
782 _iwr.u.essid.pointer = &str[0]; 782 _iwr.u.essid.pointer = &str[0];
783 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 783 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
784 if ( !wioctl( SIOCGIWESSID ) ) 784 if ( !wioctl( SIOCGIWESSID ) )
785 { 785 {
786 return "<unknown>"; 786 return "<unknown>";
787 } 787 }
788 else 788 else
789 { 789 {
790 return str; 790 return str;
791 } 791 }
792} 792}
793 793
794 794
795void OWirelessNetworkInterface::setSSID( const QString& ssid ) 795void OWirelessNetworkInterface::setSSID( const QString& ssid )
796{ 796{
797 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 797 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
798 _iwr.u.essid.length = ssid.length(); 798 _iwr.u.essid.length = ssid.length();
799 wioctl( SIOCSIWESSID ); 799 wioctl( SIOCSIWESSID );
800} 800}
801 801
802 802
803bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 803bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
804{ 804{
805 int result = ::ioctl( _sfd, call, &iwreq ); 805 int result = ::ioctl( _sfd, call, &iwreq );
806 if ( result == -1 ) 806 if ( result == -1 )
807 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 807 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
808 else 808 else
809 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); 809 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call );
810 return ( result != -1 ); 810 return ( result != -1 );
811} 811}
812 812
813 813
814bool OWirelessNetworkInterface::wioctl( int call ) const 814bool OWirelessNetworkInterface::wioctl( int call ) const
815{ 815{
816 strcpy( _iwr.ifr_name, name() ); 816 strcpy( _iwr.ifr_name, name() );
817 return wioctl( call, _iwr ); 817 return wioctl( call, _iwr );
818} 818}
819 819
820 820
821/*====================================================================================== 821/*======================================================================================
822 * OMonitoringInterface 822 * OMonitoringInterface
823 *======================================================================================*/ 823 *======================================================================================*/
824 824
825OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 825OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
826 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) 826 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader )
827{ 827{
828} 828}
829 829
830 830
831OMonitoringInterface::~OMonitoringInterface() 831OMonitoringInterface::~OMonitoringInterface()
832{ 832{
833} 833}
834 834
835 835
836void OMonitoringInterface::setChannel( int c ) 836void OMonitoringInterface::setChannel( int c )
837{ 837{
838 // use standard WE channel switching protocol 838 // use standard WE channel switching protocol
839 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 839 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
840 _if->_iwr.u.freq.m = c; 840 _if->_iwr.u.freq.m = c;
841 _if->_iwr.u.freq.e = 0; 841 _if->_iwr.u.freq.e = 0;
842 _if->wioctl( SIOCSIWFREQ ); 842 _if->wioctl( SIOCSIWFREQ );
843} 843}
844 844
845 845
846bool OMonitoringInterface::enabled() const 846bool OMonitoringInterface::enabled() const
847{ 847{
848 return _if->monitorMode(); 848 return _if->monitorMode();
849} 849}
850 850
851 851
852void OMonitoringInterface::setEnabled( bool b ) 852void OMonitoringInterface::setEnabled( bool b )
853{ 853{
854} 854}
855 855
856 856
857/*====================================================================================== 857/*======================================================================================
858 * OCiscoMonitoringInterface 858 * OCiscoMonitoringInterface
859 *======================================================================================*/ 859 *======================================================================================*/
860 860
861OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 861OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
862 :OMonitoringInterface( iface, prismHeader ) 862 :OMonitoringInterface( iface, prismHeader )
863{ 863{
864 iface->setMonitoring( this ); 864 iface->setMonitoring( this );
865} 865}
866 866
867 867
868OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 868OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
869{ 869{
870} 870}
871 871
872 872
873void OCiscoMonitoringInterface::setEnabled( bool b ) 873void OCiscoMonitoringInterface::setEnabled( bool b )
874{ 874{
875 QString fname; 875 QString fname;
876 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 876 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
877 QFile f( fname ); 877 QFile f( fname );
878 if ( !f.exists() ) return; 878 if ( !f.exists() ) return;
879 879
880 if ( f.open( IO_WriteOnly ) ) 880 if ( f.open( IO_WriteOnly ) )
881 { 881 {
882 QTextStream s( &f ); 882 QTextStream s( &f );
883 s << "Mode: r"; 883 s << "Mode: r";
884 s << "Mode: y"; 884 s << "Mode: y";
885 s << "XmitPower: 1"; 885 s << "XmitPower: 1";
886 } 886 }
887 887
888 // flushing and closing will be done automatically when f goes out of scope 888 // flushing and closing will be done automatically when f goes out of scope
889} 889}
890 890
891 891
892QString OCiscoMonitoringInterface::name() const 892QString OCiscoMonitoringInterface::name() const
893{ 893{
894 return "cisco"; 894 return "cisco";
895} 895}
896 896
897 897
898void OCiscoMonitoringInterface::setChannel( int ) 898void OCiscoMonitoringInterface::setChannel( int )
899{ 899{
900 // cisco devices automatically switch channels when in monitor mode 900 // cisco devices automatically switch channels when in monitor mode
901} 901}
902 902
903 903
904/*====================================================================================== 904/*======================================================================================
905 * OWlanNGMonitoringInterface 905 * OWlanNGMonitoringInterface
906 *======================================================================================*/ 906 *======================================================================================*/
907 907
908 908
909OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 909OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
910 :OMonitoringInterface( iface, prismHeader ) 910 :OMonitoringInterface( iface, prismHeader )
911{ 911{
912 iface->setMonitoring( this ); 912 iface->setMonitoring( this );
913} 913}
914 914
915 915
916OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 916OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
917{ 917{
918} 918}
919 919
920 920
921void OWlanNGMonitoringInterface::setEnabled( bool b ) 921void OWlanNGMonitoringInterface::setEnabled( bool b )
922{ 922{
923 //FIXME: do nothing if its already in the same mode 923 //FIXME: do nothing if its already in the same mode
924 924
925 QString enable = b ? "true" : "false"; 925 QString enable = b ? "true" : "false";
926 QString prism = _prismHeader ? "true" : "false"; 926 QString prism = _prismHeader ? "true" : "false";
927 QString cmd; 927 QString cmd;
928 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 928 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
929 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); 929 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism );
930 system( cmd ); 930 system( cmd );
931} 931}
932 932
933 933
934QString OWlanNGMonitoringInterface::name() const 934QString OWlanNGMonitoringInterface::name() const
935{ 935{
936 return "wlan-ng"; 936 return "wlan-ng";
937} 937}
938 938
939 939
940void OWlanNGMonitoringInterface::setChannel( int c ) 940void OWlanNGMonitoringInterface::setChannel( int c )
941{ 941{
942 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. 942 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't.
943 943
944 QString enable = "true"; //_if->monitorMode() ? "true" : "false"; 944 QString enable = "true"; //_if->monitorMode() ? "true" : "false";
945 QString prism = _prismHeader ? "true" : "false"; 945 QString prism = _prismHeader ? "true" : "false";
946 QString cmd; 946 QString cmd;
947 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 947 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
948 (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); 948 (const char*) _if->name(), c, (const char*) enable, (const char*) prism );
949 system( cmd ); 949 system( cmd );
950} 950}
951 951
952 952
953/*====================================================================================== 953/*======================================================================================
954 * OHostAPMonitoringInterface 954 * OHostAPMonitoringInterface
955 *======================================================================================*/ 955 *======================================================================================*/
956 956
957OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 957OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
958 :OMonitoringInterface( iface, prismHeader ) 958 :OMonitoringInterface( iface, prismHeader )
959{ 959{
960 iface->setMonitoring( this ); 960 iface->setMonitoring( this );
961} 961}
962 962
963OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 963OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
964{ 964{
965} 965}
966 966
967void OHostAPMonitoringInterface::setEnabled( bool b ) 967void OHostAPMonitoringInterface::setEnabled( bool b )
968{ 968{
969 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 969 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
970 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 970 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
971 971
972 #if WIRELESS_EXT > 14 972 #if WIRELESS_EXT > 14
973 if ( b ) 973 if ( b )
974 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header 974 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
975 else 975 else
976 _if->setMode( "managed" ); 976 _if->setMode( "managed" );
977 #else 977 #else
978 int monitorCode = _prismHeader ? 1 : 2; 978 int monitorCode = _prismHeader ? 1 : 2;
979 if ( b ) 979 if ( b )
980 { 980 {
981 _if->setPrivate( "monitor", 1, monitorCode ); 981 _if->setPrivate( "monitor", 1, monitorCode );
982 } 982 }
983 else 983 else
984 { 984 {
985 _if->setPrivate( "monitor", 1, 0 ); 985 _if->setPrivate( "monitor", 1, 0 );
986 } 986 }
987 #endif 987 #endif
988} 988}
989 989
990 990
991QString OHostAPMonitoringInterface::name() const 991QString OHostAPMonitoringInterface::name() const
992{ 992{
993 return "hostap"; 993 return "hostap";
994} 994}
995 995
996 996
997/*====================================================================================== 997/*======================================================================================
998 * OOrinocoNetworkInterface 998 * OOrinocoNetworkInterface
999 *======================================================================================*/ 999 *======================================================================================*/
1000 1000
1001OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1001OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1002 :OMonitoringInterface( iface, prismHeader ) 1002 :OMonitoringInterface( iface, prismHeader )
1003{ 1003{
1004 iface->setMonitoring( this ); 1004 iface->setMonitoring( this );
1005} 1005}
1006 1006
1007 1007
1008OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 1008OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
1009{ 1009{
1010} 1010}
1011 1011
1012 1012
1013void OOrinocoMonitoringInterface::setChannel( int c ) 1013void OOrinocoMonitoringInterface::setChannel( int c )
1014{ 1014{
1015 int monitorCode = _prismHeader ? 1 : 2; 1015 int monitorCode = _prismHeader ? 1 : 2;
1016 _if->setPrivate( "monitor", 2, monitorCode, c ); 1016 _if->setPrivate( "monitor", 2, monitorCode, c );
1017} 1017}
1018 1018
1019 1019
1020void OOrinocoMonitoringInterface::setEnabled( bool b ) 1020void OOrinocoMonitoringInterface::setEnabled( bool b )
1021{ 1021{
1022 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 1022 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
1023 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 1023 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
1024 // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported 1024 // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported
1025 1025
1026 #if 0 1026 #if 0
1027 //#if WIRELESS_EXT > 14 1027 //#if WIRELESS_EXT > 14
1028 if ( b ) 1028 if ( b )
1029 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header 1029 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
1030 else 1030 else
1031 _if->setMode( "managed" ); 1031 _if->setMode( "managed" );
1032 #else 1032 #else
1033 if ( b ) 1033 if ( b )
1034 { 1034 {
1035 setChannel( 1 ); 1035 setChannel( 1 );
1036 } 1036 }
1037 else 1037 else
1038 { 1038 {
1039 _if->setPrivate( "monitor", 2, 0, 0 ); 1039 _if->setPrivate( "monitor", 2, 0, 0 );
1040 } 1040 }
1041 #endif 1041 #endif
1042} 1042}
1043 1043
1044 1044
1045QString OOrinocoMonitoringInterface::name() const 1045QString OOrinocoMonitoringInterface::name() const
1046{ 1046{
1047 return "orinoco"; 1047 return "orinoco";
1048} 1048}
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index 38ca1a1..6331b2d 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -634,690 +634,690 @@ OWaveLanPacket::OWaveLanPacket( const unsigned char* end, const struct ieee_802_
634 634
635 switch ( type() ) 635 switch ( type() )
636 { 636 {
637 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break; 637 case T_MGMT: new OWaveLanManagementPacket( end, (const struct ieee_802_11_mgmt_header*) data, this ); break;
638 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break; 638 case T_DATA: new OWaveLanDataPacket( end, (const struct ieee_802_11_data_header*) data, this ); break;
639 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break; 639 case T_CTRL: new OWaveLanControlPacket( end, (const struct ieee_802_11_control_header*) data, this ); break;
640 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() ); 640 default: qDebug( "OWaveLanPacket::OWaveLanPacket(): Warning: Unknown major type '%d'!", type() );
641 } 641 }
642} 642}
643 643
644OWaveLanPacket::~OWaveLanPacket() 644OWaveLanPacket::~OWaveLanPacket()
645{ 645{
646} 646}
647 647
648 648
649int OWaveLanPacket::duration() const 649int OWaveLanPacket::duration() const
650{ 650{
651 return _wlanhdr->duration; 651 return _wlanhdr->duration;
652} 652}
653 653
654 654
655OMacAddress OWaveLanPacket::macAddress1() const 655OMacAddress OWaveLanPacket::macAddress1() const
656{ 656{
657 return OMacAddress( _wlanhdr->mac1 ); 657 return OMacAddress( _wlanhdr->mac1 );
658} 658}
659 659
660 660
661OMacAddress OWaveLanPacket::macAddress2() const 661OMacAddress OWaveLanPacket::macAddress2() const
662{ 662{
663 return OMacAddress( _wlanhdr->mac2 ); 663 return OMacAddress( _wlanhdr->mac2 );
664} 664}
665 665
666 666
667OMacAddress OWaveLanPacket::macAddress3() const 667OMacAddress OWaveLanPacket::macAddress3() const
668{ 668{
669 return OMacAddress( _wlanhdr->mac3 ); 669 return OMacAddress( _wlanhdr->mac3 );
670} 670}
671 671
672 672
673OMacAddress OWaveLanPacket::macAddress4() const 673OMacAddress OWaveLanPacket::macAddress4() const
674{ 674{
675 return OMacAddress( _wlanhdr->mac4 ); 675 return OMacAddress( _wlanhdr->mac4 );
676} 676}
677 677
678 678
679int OWaveLanPacket::subType() const 679int OWaveLanPacket::subType() const
680{ 680{
681 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 681 return FC_SUBTYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
682} 682}
683 683
684 684
685int OWaveLanPacket::type() const 685int OWaveLanPacket::type() const
686{ 686{
687 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 687 return FC_TYPE( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
688} 688}
689 689
690 690
691int OWaveLanPacket::version() const 691int OWaveLanPacket::version() const
692{ 692{
693 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 693 return FC_VERSION( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
694} 694}
695 695
696 696
697bool OWaveLanPacket::fromDS() const 697bool OWaveLanPacket::fromDS() const
698{ 698{
699 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 699 return FC_FROM_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
700} 700}
701 701
702 702
703bool OWaveLanPacket::toDS() const 703bool OWaveLanPacket::toDS() const
704{ 704{
705 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 705 return FC_TO_DS( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
706} 706}
707 707
708 708
709bool OWaveLanPacket::usesPowerManagement() const 709bool OWaveLanPacket::usesPowerManagement() const
710{ 710{
711 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 711 return FC_POWER_MGMT( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
712} 712}
713 713
714 714
715bool OWaveLanPacket::usesWep() const 715bool OWaveLanPacket::usesWep() const
716{ 716{
717 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) ); 717 return FC_WEP( EXTRACT_LE_16BITS( &_wlanhdr->frame_control ) );
718} 718}
719 719
720 720
721/*====================================================================================== 721/*======================================================================================
722 * OWaveLanManagementPacket 722 * OWaveLanManagementPacket
723 *======================================================================================*/ 723 *======================================================================================*/
724 724
725OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent ) 725OWaveLanManagementPacket::OWaveLanManagementPacket( const unsigned char* end, const struct ieee_802_11_mgmt_header* data, OWaveLanPacket* parent )
726 :QObject( parent, "802.11 Management" ), _header( data ), 726 :QObject( parent, "802.11 Management" ), _header( data ),
727 _body( (const struct ieee_802_11_mgmt_body*) (data+1) ) 727 _body( (const struct ieee_802_11_mgmt_body*) (data+1) )
728{ 728{
729 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." ); 729 qDebug( "OWaveLanManagementPacket::OWaveLanManagementPacket(): decoding frame..." );
730 qDebug( "Detected subtype is '%s'", (const char*) managementType() ); 730 qDebug( "Detected subtype is '%s'", (const char*) managementType() );
731 731
732 // grab tagged values 732 // grab tagged values
733 const unsigned char* ptr = (const unsigned char*) (_body+1); 733 const unsigned char* ptr = (const unsigned char*) (_body+1);
734 while (ptr < end) 734 while (ptr < end)
735 { 735 {
736 switch ( *ptr ) 736 switch ( *ptr )
737 { 737 {
738 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break; 738 case E_SSID: new OWaveLanManagementSSID( end, (struct ssid_t*) ptr, this ); break;
739 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break; 739 case E_FH: new OWaveLanManagementFH( end, (struct fh_t*) ptr, this ); break;
740 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break; 740 case E_DS: new OWaveLanManagementDS( end, (struct ds_t*) ptr, this ); break;
741 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break; 741 case E_RATES: new OWaveLanManagementRates( end, (struct rates_t*) ptr, this ); break;
742 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break; 742 case E_CF: new OWaveLanManagementCF( end, (struct cf_t*) ptr, this ); break;
743 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break; 743 case E_TIM: new OWaveLanManagementTim( end, (struct tim_t*) ptr, this ); break;
744 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break; 744 case E_IBSS: new OWaveLanManagementIBSS( end, (struct ibss_t*) ptr, this ); break;
745 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break; 745 case E_CHALLENGE: new OWaveLanManagementChallenge( end, (struct challenge_t*) ptr, this ); break;
746 } 746 }
747 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value 747 ptr+= ( ( struct ssid_t* ) ptr )->length; // skip length of tagged value
748 ptr+= 2; // skip tag ID and length 748 ptr+= 2; // skip tag ID and length
749 } 749 }
750} 750}
751 751
752 752
753OWaveLanManagementPacket::~OWaveLanManagementPacket() 753OWaveLanManagementPacket::~OWaveLanManagementPacket()
754{ 754{
755} 755}
756 756
757 757
758QString OWaveLanManagementPacket::managementType() const 758QString OWaveLanManagementPacket::managementType() const
759{ 759{
760 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ) 760 switch ( FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) )
761 { 761 {
762 case ST_ASSOC_REQUEST: return "AssociationRequest"; break; 762 case ST_ASSOC_REQUEST: return "AssociationRequest"; break;
763 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break; 763 case ST_ASSOC_RESPONSE: return "AssociationResponse"; break;
764 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break; 764 case ST_REASSOC_REQUEST: return "ReassociationRequest"; break;
765 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break; 765 case ST_REASSOC_RESPONSE: return "ReassociationResponse"; break;
766 case ST_PROBE_REQUEST: return "ProbeRequest"; break; 766 case ST_PROBE_REQUEST: return "ProbeRequest"; break;
767 case ST_PROBE_RESPONSE: return "ProbeResponse"; break; 767 case ST_PROBE_RESPONSE: return "ProbeResponse"; break;
768 case ST_BEACON: return "Beacon"; break; 768 case ST_BEACON: return "Beacon"; break;
769 case ST_ATIM: return "Atim"; break; 769 case ST_ATIM: return "Atim"; break;
770 case ST_DISASSOC: return "Disassociation"; break; 770 case ST_DISASSOC: return "Disassociation"; break;
771 case ST_AUTH: return "Authentication"; break; 771 case ST_AUTH: return "Authentication"; break;
772 case ST_DEAUTH: return "Deathentication"; break; 772 case ST_DEAUTH: return "Deathentication"; break;
773 default: 773 default:
774 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) ); 774 qWarning( "OWaveLanManagementPacket::managementType(): unhandled subtype %d", FC_SUBTYPE( EXTRACT_LE_16BITS( &_header->fc ) ) );
775 return "Unknown"; 775 return "Unknown";
776 } 776 }
777} 777}
778 778
779 779
780int OWaveLanManagementPacket::beaconInterval() const 780int OWaveLanManagementPacket::beaconInterval() const
781{ 781{
782 return EXTRACT_LE_16BITS( &_body->beacon_interval ); 782 return EXTRACT_LE_16BITS( &_body->beacon_interval );
783} 783}
784 784
785 785
786int OWaveLanManagementPacket::capabilities() const 786int OWaveLanManagementPacket::capabilities() const
787{ 787{
788 return EXTRACT_LE_16BITS( &_body->capability_info ); 788 return EXTRACT_LE_16BITS( &_body->capability_info );
789} 789}
790 790
791 791
792bool OWaveLanManagementPacket::canESS() const 792bool OWaveLanManagementPacket::canESS() const
793{ 793{
794 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 794 return CAPABILITY_ESS( EXTRACT_LE_16BITS( &_body->capability_info ) );
795} 795}
796 796
797 797
798bool OWaveLanManagementPacket::canIBSS() const 798bool OWaveLanManagementPacket::canIBSS() const
799{ 799{
800 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) ); 800 return CAPABILITY_IBSS( EXTRACT_LE_16BITS( &_body->capability_info ) );
801} 801}
802 802
803 803
804bool OWaveLanManagementPacket::canCFP() const 804bool OWaveLanManagementPacket::canCFP() const
805{ 805{
806 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) ); 806 return CAPABILITY_CFP( EXTRACT_LE_16BITS( &_body->capability_info ) );
807} 807}
808 808
809 809
810bool OWaveLanManagementPacket::canCFP_REQ() const 810bool OWaveLanManagementPacket::canCFP_REQ() const
811{ 811{
812 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) ); 812 return CAPABILITY_CFP_REQ( EXTRACT_LE_16BITS( &_body->capability_info ) );
813} 813}
814 814
815 815
816bool OWaveLanManagementPacket::canPrivacy() const 816bool OWaveLanManagementPacket::canPrivacy() const
817{ 817{
818 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) ); 818 return CAPABILITY_PRIVACY( EXTRACT_LE_16BITS( &_body->capability_info ) );
819} 819}
820 820
821 821
822/*====================================================================================== 822/*======================================================================================
823 * OWaveLanManagementSSID 823 * OWaveLanManagementSSID
824 *======================================================================================*/ 824 *======================================================================================*/
825 825
826OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent ) 826OWaveLanManagementSSID::OWaveLanManagementSSID( const unsigned char* end, const struct ssid_t* data, QObject* parent )
827 :QObject( parent, "802.11 SSID" ), _data( data ) 827 :QObject( parent, "802.11 SSID" ), _data( data )
828{ 828{
829 qDebug( "OWaveLanManagementSSID()" ); 829 qDebug( "OWaveLanManagementSSID()" );
830} 830}
831 831
832 832
833OWaveLanManagementSSID::~OWaveLanManagementSSID() 833OWaveLanManagementSSID::~OWaveLanManagementSSID()
834{ 834{
835} 835}
836 836
837 837
838QString OWaveLanManagementSSID::ID() const 838QString OWaveLanManagementSSID::ID() const
839{ 839{
840 int length = _data->length; 840 int length = _data->length;
841 if ( length > 32 ) length = 32; 841 if ( length > 32 ) length = 32;
842 char essid[length+1]; 842 char essid[length+1];
843 memcpy( &essid, &_data->ssid, length ); 843 memcpy( &essid, &_data->ssid, length );
844 essid[length] = 0x0; 844 essid[length] = 0x0;
845 return essid; 845 return essid;
846} 846}
847 847
848 848
849/*====================================================================================== 849/*======================================================================================
850 * OWaveLanManagementRates 850 * OWaveLanManagementRates
851 *======================================================================================*/ 851 *======================================================================================*/
852 852
853OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent ) 853OWaveLanManagementRates::OWaveLanManagementRates( const unsigned char* end, const struct rates_t* data, QObject* parent )
854 :QObject( parent, "802.11 Rates" ), _data( data ) 854 :QObject( parent, "802.11 Rates" ), _data( data )
855{ 855{
856 qDebug( "OWaveLanManagementRates()" ); 856 qDebug( "OWaveLanManagementRates()" );
857} 857}
858 858
859 859
860OWaveLanManagementRates::~OWaveLanManagementRates() 860OWaveLanManagementRates::~OWaveLanManagementRates()
861{ 861{
862} 862}
863 863
864/*====================================================================================== 864/*======================================================================================
865 * OWaveLanManagementCF 865 * OWaveLanManagementCF
866 *======================================================================================*/ 866 *======================================================================================*/
867 867
868OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent ) 868OWaveLanManagementCF::OWaveLanManagementCF( const unsigned char* end, const struct cf_t* data, QObject* parent )
869 :QObject( parent, "802.11 CF" ), _data( data ) 869 :QObject( parent, "802.11 CF" ), _data( data )
870{ 870{
871 qDebug( "OWaveLanManagementCF()" ); 871 qDebug( "OWaveLanManagementCF()" );
872} 872}
873 873
874 874
875OWaveLanManagementCF::~OWaveLanManagementCF() 875OWaveLanManagementCF::~OWaveLanManagementCF()
876{ 876{
877} 877}
878 878
879/*====================================================================================== 879/*======================================================================================
880 * OWaveLanManagementFH 880 * OWaveLanManagementFH
881 *======================================================================================*/ 881 *======================================================================================*/
882 882
883OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent ) 883OWaveLanManagementFH::OWaveLanManagementFH( const unsigned char* end, const struct fh_t* data, QObject* parent )
884 :QObject( parent, "802.11 FH" ), _data( data ) 884 :QObject( parent, "802.11 FH" ), _data( data )
885{ 885{
886 qDebug( "OWaveLanManagementFH()" ); 886 qDebug( "OWaveLanManagementFH()" );
887} 887}
888 888
889 889
890OWaveLanManagementFH::~OWaveLanManagementFH() 890OWaveLanManagementFH::~OWaveLanManagementFH()
891{ 891{
892} 892}
893 893
894/*====================================================================================== 894/*======================================================================================
895 * OWaveLanManagementDS 895 * OWaveLanManagementDS
896 *======================================================================================*/ 896 *======================================================================================*/
897 897
898OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent ) 898OWaveLanManagementDS::OWaveLanManagementDS( const unsigned char* end, const struct ds_t* data, QObject* parent )
899 :QObject( parent, "802.11 DS" ), _data( data ) 899 :QObject( parent, "802.11 DS" ), _data( data )
900{ 900{
901 qDebug( "OWaveLanManagementDS()" ); 901 qDebug( "OWaveLanManagementDS()" );
902} 902}
903 903
904 904
905OWaveLanManagementDS::~OWaveLanManagementDS() 905OWaveLanManagementDS::~OWaveLanManagementDS()
906{ 906{
907} 907}
908 908
909 909
910int OWaveLanManagementDS::channel() const 910int OWaveLanManagementDS::channel() const
911{ 911{
912 return _data->channel; 912 return _data->channel;
913} 913}
914 914
915/*====================================================================================== 915/*======================================================================================
916 * OWaveLanManagementTim 916 * OWaveLanManagementTim
917 *======================================================================================*/ 917 *======================================================================================*/
918 918
919OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent ) 919OWaveLanManagementTim::OWaveLanManagementTim( const unsigned char* end, const struct tim_t* data, QObject* parent )
920 :QObject( parent, "802.11 Tim" ), _data( data ) 920 :QObject( parent, "802.11 Tim" ), _data( data )
921{ 921{
922 qDebug( "OWaveLanManagementTim()" ); 922 qDebug( "OWaveLanManagementTim()" );
923} 923}
924 924
925 925
926OWaveLanManagementTim::~OWaveLanManagementTim() 926OWaveLanManagementTim::~OWaveLanManagementTim()
927{ 927{
928} 928}
929 929
930/*====================================================================================== 930/*======================================================================================
931 * OWaveLanManagementIBSS 931 * OWaveLanManagementIBSS
932 *======================================================================================*/ 932 *======================================================================================*/
933 933
934OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent ) 934OWaveLanManagementIBSS::OWaveLanManagementIBSS( const unsigned char* end, const struct ibss_t* data, QObject* parent )
935 :QObject( parent, "802.11 IBSS" ), _data( data ) 935 :QObject( parent, "802.11 IBSS" ), _data( data )
936{ 936{
937 qDebug( "OWaveLanManagementIBSS()" ); 937 qDebug( "OWaveLanManagementIBSS()" );
938} 938}
939 939
940 940
941OWaveLanManagementIBSS::~OWaveLanManagementIBSS() 941OWaveLanManagementIBSS::~OWaveLanManagementIBSS()
942{ 942{
943} 943}
944 944
945/*====================================================================================== 945/*======================================================================================
946 * OWaveLanManagementChallenge 946 * OWaveLanManagementChallenge
947 *======================================================================================*/ 947 *======================================================================================*/
948 948
949OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent ) 949OWaveLanManagementChallenge::OWaveLanManagementChallenge( const unsigned char* end, const struct challenge_t* data, QObject* parent )
950 :QObject( parent, "802.11 Challenge" ), _data( data ) 950 :QObject( parent, "802.11 Challenge" ), _data( data )
951{ 951{
952 qDebug( "OWaveLanManagementChallenge()" ); 952 qDebug( "OWaveLanManagementChallenge()" );
953} 953}
954 954
955 955
956OWaveLanManagementChallenge::~OWaveLanManagementChallenge() 956OWaveLanManagementChallenge::~OWaveLanManagementChallenge()
957{ 957{
958} 958}
959 959
960/*====================================================================================== 960/*======================================================================================
961 * OWaveLanDataPacket 961 * OWaveLanDataPacket
962 *======================================================================================*/ 962 *======================================================================================*/
963 963
964OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent ) 964OWaveLanDataPacket::OWaveLanDataPacket( const unsigned char* end, const struct ieee_802_11_data_header* data, OWaveLanPacket* parent )
965 :QObject( parent, "802.11 Data" ), _header( data ) 965 :QObject( parent, "802.11 Data" ), _header( data )
966{ 966{
967 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." ); 967 qDebug( "OWaveLanDataPacket::OWaveLanDataPacket(): decoding frame..." );
968 968
969 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header ); 969 const unsigned char* payload = (const unsigned char*) data + sizeof( struct ieee_802_11_data_header );
970 970
971 #warning The next line works for most cases, but can not be correct generally! 971 #warning The next line works for most cases, but can not be correct generally!
972 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address 972 if (!( ( (OWaveLanPacket*) this->parent())->duration() )) payload -= 6; // compensation for missing last address
973 973
974 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this ); 974 new OLLCPacket( end, (const struct ieee_802_11_802_2_header*) payload, this );
975} 975}
976 976
977 977
978OWaveLanDataPacket::~OWaveLanDataPacket() 978OWaveLanDataPacket::~OWaveLanDataPacket()
979{ 979{
980} 980}
981 981
982 982
983/*====================================================================================== 983/*======================================================================================
984 * OLLCPacket 984 * OLLCPacket
985 *======================================================================================*/ 985 *======================================================================================*/
986 986
987OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent ) 987OLLCPacket::OLLCPacket( const unsigned char* end, const struct ieee_802_11_802_2_header* data, QObject* parent )
988 :QObject( parent, "802.11 LLC" ), _header( data ) 988 :QObject( parent, "802.11 LLC" ), _header( data )
989{ 989{
990 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." ); 990 qDebug( "OLLCPacket::OLLCPacket(): decoding frame..." );
991 991
992 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) ) 992 if ( !(_header->oui[0] || _header->oui[1] || _header->oui[2]) )
993 { 993 {
994 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 994 qDebug( "OLLCPacket::OLLCPacket(): contains an encapsulated Ethernet frame (type=%04X)", EXTRACT_16BITS( &_header->type ) );
995 995
996 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h 996 switch ( EXTRACT_16BITS( &_header->type ) ) // defined in linux/if_ether.h
997 { 997 {
998 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break; 998 case ETH_P_IP: new OIPPacket( end, (const struct iphdr*) (data+1), this ); break;
999 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break; 999 case ETH_P_ARP: new OARPPacket( end, (const struct myarphdr*) (data+1), this ); break;
1000 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) ); 1000 default: qWarning( "OLLCPacket::OLLCPacket(): Unknown Encapsulation (type=%04X)", EXTRACT_16BITS( &_header->type ) );
1001 } 1001 }
1002 1002
1003 } 1003 }
1004} 1004}
1005 1005
1006 1006
1007OLLCPacket::~OLLCPacket() 1007OLLCPacket::~OLLCPacket()
1008{ 1008{
1009} 1009}
1010 1010
1011 1011
1012/*====================================================================================== 1012/*======================================================================================
1013 * OWaveLanControlPacket 1013 * OWaveLanControlPacket
1014 *======================================================================================*/ 1014 *======================================================================================*/
1015 1015
1016OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent ) 1016OWaveLanControlPacket::OWaveLanControlPacket( const unsigned char* end, const struct ieee_802_11_control_header* data, OWaveLanPacket* parent )
1017 :QObject( parent, "802.11 Control" ), _header( data ) 1017 :QObject( parent, "802.11 Control" ), _header( data )
1018{ 1018{
1019 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." ); 1019 qDebug( "OWaveLanControlPacket::OWaveLanDataControl(): decoding frame..." );
1020 //TODO: Implement this 1020 //TODO: Implement this
1021} 1021}
1022 1022
1023 1023
1024OWaveLanControlPacket::~OWaveLanControlPacket() 1024OWaveLanControlPacket::~OWaveLanControlPacket()
1025{ 1025{
1026} 1026}
1027 1027
1028 1028
1029/*====================================================================================== 1029/*======================================================================================
1030 * OPacketCapturer 1030 * OPacketCapturer
1031 *======================================================================================*/ 1031 *======================================================================================*/
1032 1032
1033OPacketCapturer::OPacketCapturer( QObject* parent, const char* name ) 1033OPacketCapturer::OPacketCapturer( QObject* parent, const char* name )
1034 :QObject( parent, name ), _name( QString::null ), _open( false ), 1034 :QObject( parent, name ), _name( QString::null ), _open( false ),
1035 _pch( 0 ), _pcd( 0 ), _sn( 0 ) 1035 _pch( 0 ), _pcd( 0 ), _sn( 0 )
1036{ 1036{
1037} 1037}
1038 1038
1039 1039
1040OPacketCapturer::~OPacketCapturer() 1040OPacketCapturer::~OPacketCapturer()
1041{ 1041{
1042 if ( _open ) 1042 if ( _open )
1043 { 1043 {
1044 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." ); 1044 qDebug( "OPacketCapturer::~OPacketCapturer(): pcap still open, autoclosing." );
1045 close(); 1045 close();
1046 } 1046 }
1047} 1047}
1048 1048
1049 1049
1050void OPacketCapturer::setBlocking( bool b ) 1050void OPacketCapturer::setBlocking( bool b )
1051{ 1051{
1052 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 ) 1052 if ( pcap_setnonblock( _pch, 1-b, _errbuf ) != -1 )
1053 { 1053 {
1054 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." ); 1054 qDebug( "OPacketCapturer::setBlocking(): blocking mode changed successfully." );
1055 } 1055 }
1056 else 1056 else
1057 { 1057 {
1058 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf ); 1058 qDebug( "OPacketCapturer::setBlocking(): can't change blocking mode: %s", _errbuf );
1059 } 1059 }
1060} 1060}
1061 1061
1062 1062
1063bool OPacketCapturer::blocking() const 1063bool OPacketCapturer::blocking() const
1064{ 1064{
1065 int b = pcap_getnonblock( _pch, _errbuf ); 1065 int b = pcap_getnonblock( _pch, _errbuf );
1066 if ( b == -1 ) 1066 if ( b == -1 )
1067 { 1067 {
1068 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf ); 1068 qDebug( "OPacketCapturer::blocking(): can't get blocking mode: %s", _errbuf );
1069 return -1; 1069 return -1;
1070 } 1070 }
1071 return !b; 1071 return !b;
1072} 1072}
1073 1073
1074 1074
1075void OPacketCapturer::closeDumpFile() 1075void OPacketCapturer::closeDumpFile()
1076{ 1076{
1077 if ( _pcd ) 1077 if ( _pcd )
1078 { 1078 {
1079 pcap_dump_close( _pcd ); 1079 pcap_dump_close( _pcd );
1080 _pcd = 0; 1080 _pcd = 0;
1081 } 1081 }
1082 pcap_close( _pch ); 1082 pcap_close( _pch );
1083} 1083}
1084 1084
1085 1085
1086void OPacketCapturer::close() 1086void OPacketCapturer::close()
1087{ 1087{
1088 if ( _open ) 1088 if ( _open )
1089 { 1089 {
1090 if ( _sn ) 1090 if ( _sn )
1091 { 1091 {
1092 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1092 _sn->disconnect( SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1093 delete _sn; 1093 delete _sn;
1094 } 1094 }
1095 closeDumpFile(); 1095 closeDumpFile();
1096 _open = false; 1096 _open = false;
1097 } 1097 }
1098 1098
1099 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." ); 1099 qDebug( "OPacketCapturer::close() --- dumping capturing statistics..." );
1100 qDebug( "--------------------------------------------------" ); 1100 qDebug( "--------------------------------------------------" );
1101 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it ) 1101 for( QMap<QString,int>::Iterator it = _stats.begin(); it != _stats.end(); ++it )
1102 qDebug( "%s : %d", (const char*) it.key(), it.data() ); 1102 qDebug( "%s : %d", (const char*) it.key(), it.data() );
1103 qDebug( "--------------------------------------------------" ); 1103 qDebug( "--------------------------------------------------" );
1104 1104
1105} 1105}
1106 1106
1107 1107
1108int OPacketCapturer::dataLink() const 1108int OPacketCapturer::dataLink() const
1109{ 1109{
1110 return pcap_datalink( _pch ); 1110 return pcap_datalink( _pch );
1111} 1111}
1112 1112
1113 1113
1114void OPacketCapturer::dump( OPacket* p ) 1114void OPacketCapturer::dump( OPacket* p )
1115{ 1115{
1116 if ( !_pcd ) 1116 if ( !_pcd )
1117 { 1117 {
1118 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" ); 1118 qWarning( "OPacketCapturer::dump() - cannot dump without open capture file!" );
1119 return; 1119 return;
1120 } 1120 }
1121 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data ); 1121 pcap_dump( (u_char*) _pcd, &p->_hdr, p->_data );
1122} 1122}
1123 1123
1124 1124
1125int OPacketCapturer::fileno() const 1125int OPacketCapturer::fileno() const
1126{ 1126{
1127 if ( _open ) 1127 if ( _open )
1128 { 1128 {
1129 return pcap_fileno( _pch ); 1129 return pcap_fileno( _pch );
1130 } 1130 }
1131 else 1131 else
1132 { 1132 {
1133 return -1; 1133 return -1;
1134 } 1134 }
1135} 1135}
1136 1136
1137 1137
1138OPacket* OPacketCapturer::next( int time ) 1138OPacket* OPacketCapturer::next( int time )
1139{ 1139{
1140 fd_set fds; 1140 fd_set fds;
1141 struct timeval tv; 1141 struct timeval tv;
1142 FD_ZERO( &fds ); 1142 FD_ZERO( &fds );
1143 FD_SET( pcap_fileno( _pch ), &fds ); 1143 FD_SET( pcap_fileno( _pch ), &fds );
1144 tv.tv_sec = time / 1000; 1144 tv.tv_sec = time / 1000;
1145 tv.tv_usec = time % 1000; 1145 tv.tv_usec = time % 1000;
1146 int retval = select( 1, &fds, NULL, NULL, &tv); 1146 int retval = select( pcap_fileno( _pch )+1, &fds, NULL, NULL, &tv);
1147 if ( retval > 0 ) // clear to read! 1147 if ( retval > 0 ) // clear to read!
1148 return next(); 1148 return next();
1149 else 1149 else
1150 return 0; 1150 return 0;
1151} 1151}
1152 1152
1153 1153
1154OPacket* OPacketCapturer::next() 1154OPacket* OPacketCapturer::next()
1155{ 1155{
1156 packetheaderstruct header; 1156 packetheaderstruct header;
1157 qDebug( "==> OPacketCapturer::next()" ); 1157 qDebug( "==> OPacketCapturer::next()" );
1158 const unsigned char* pdata = pcap_next( _pch, &header ); 1158 const unsigned char* pdata = pcap_next( _pch, &header );
1159 qDebug( "<== OPacketCapturer::next()" ); 1159 qDebug( "<== OPacketCapturer::next()" );
1160 1160
1161 if ( pdata && header.len ) 1161 if ( pdata && header.len )
1162 { 1162 {
1163 OPacket* p = new OPacket( dataLink(), header, pdata, 0 ); 1163 OPacket* p = new OPacket( dataLink(), header, pdata, 0 );
1164 // packets shouldn't be inserted in the QObject child-parent hierarchy, 1164 // packets shouldn't be inserted in the QObject child-parent hierarchy,
1165 // because due to memory constraints they will be deleted as soon 1165 // because due to memory constraints they will be deleted as soon
1166 // as possible - that is right after they have been processed 1166 // as possible - that is right after they have been processed
1167 // by emit() [ see below ] 1167 // by emit() [ see below ]
1168 //TODO: make gathering statistics optional, because it takes time 1168 //TODO: make gathering statistics optional, because it takes time
1169 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) ); 1169 p->updateStats( _stats, const_cast<QObjectList*>( p->children() ) );
1170 #ifndef NODEBUG 1170 #ifndef NODEBUG
1171 p->dumpStructure( const_cast<QObjectList*>( p->children() ) ); 1171 p->dumpStructure( const_cast<QObjectList*>( p->children() ) );
1172 #endif 1172 #endif
1173 return p; 1173 return p;
1174 } 1174 }
1175 else 1175 else
1176 { 1176 {
1177 qWarning( "OPacketCapturer::next() - no packet received!" ); 1177 qWarning( "OPacketCapturer::next() - no packet received!" );
1178 return 0; 1178 return 0;
1179 } 1179 }
1180} 1180}
1181 1181
1182 1182
1183bool OPacketCapturer::open( const QString& name ) 1183bool OPacketCapturer::open( const QString& name )
1184{ 1184{
1185 if ( _open ) 1185 if ( _open )
1186 { 1186 {
1187 if ( name == _name ) // ignore opening an already openend device 1187 if ( name == _name ) // ignore opening an already openend device
1188 { 1188 {
1189 return true; 1189 return true;
1190 } 1190 }
1191 else // close the last opened device 1191 else // close the last opened device
1192 { 1192 {
1193 close(); 1193 close();
1194 } 1194 }
1195 } 1195 }
1196 1196
1197 _name = name; 1197 _name = name;
1198 1198
1199 // open libpcap 1199 // open libpcap
1200 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] ); 1200 pcap_t* handle = pcap_open_live( const_cast<char*>( (const char*) name ), 1024, 0, 0, &_errbuf[0] );
1201 1201
1202 if ( !handle ) 1202 if ( !handle )
1203 { 1203 {
1204 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1204 qWarning( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1205 return false; 1205 return false;
1206 } 1206 }
1207 1207
1208 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name ); 1208 qDebug( "OPacketCapturer::open(): libpcap [%s] opened successfully.", (const char*) name );
1209 _pch = handle; 1209 _pch = handle;
1210 _open = true; 1210 _open = true;
1211 _stats.clear(); 1211 _stats.clear();
1212 1212
1213 // in case we have an application object, create a socket notifier 1213 // in case we have an application object, create a socket notifier
1214 if ( qApp ) //TODO: I don't like this here... 1214 if ( qApp ) //TODO: I don't like this here...
1215 { 1215 {
1216 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1216 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1217 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1217 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1218 } 1218 }
1219 1219
1220 return true; 1220 return true;
1221} 1221}
1222 1222
1223 1223
1224bool OPacketCapturer::openDumpFile( const QString& filename ) 1224bool OPacketCapturer::openDumpFile( const QString& filename )
1225{ 1225{
1226 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) ); 1226 pcap_dumper_t* dump = pcap_dump_open( _pch, const_cast<char*>( (const char*) filename ) );
1227 if ( !dump ) 1227 if ( !dump )
1228 { 1228 {
1229 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf ); 1229 qWarning( "OPacketCapturer::open(): can't open dump with '%s': %s", (const char*) filename, _errbuf );
1230 return false; 1230 return false;
1231 } 1231 }
1232 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename ); 1232 qDebug( "OPacketCapturer::open(): dump [%s] opened successfully.", (const char*) filename );
1233 _pcd = dump; 1233 _pcd = dump;
1234 1234
1235 return true; 1235 return true;
1236} 1236}
1237 1237
1238 1238
1239bool OPacketCapturer::open( const QFile& file ) 1239bool OPacketCapturer::open( const QFile& file )
1240{ 1240{
1241 QString name = file.name(); 1241 QString name = file.name();
1242 1242
1243 if ( _open ) 1243 if ( _open )
1244 { 1244 {
1245 close(); 1245 close();
1246 if ( name == _name ) // ignore opening an already openend device 1246 if ( name == _name ) // ignore opening an already openend device
1247 { 1247 {
1248 return true; 1248 return true;
1249 } 1249 }
1250 else // close the last opened device 1250 else // close the last opened device
1251 { 1251 {
1252 close(); 1252 close();
1253 } 1253 }
1254 } 1254 }
1255 1255
1256 _name = name; 1256 _name = name;
1257 1257
1258 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] ); 1258 pcap_t* handle = pcap_open_offline( const_cast<char*>( (const char*) name ), &_errbuf[0] );
1259 1259
1260 if ( handle ) 1260 if ( handle )
1261 { 1261 {
1262 qDebug( "OPacketCapturer::open(): libpcap opened successfully." ); 1262 qDebug( "OPacketCapturer::open(): libpcap opened successfully." );
1263 _pch = handle; 1263 _pch = handle;
1264 _open = true; 1264 _open = true;
1265 1265
1266 // in case we have an application object, create a socket notifier 1266 // in case we have an application object, create a socket notifier
1267 if ( qApp ) 1267 if ( qApp )
1268 { 1268 {
1269 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read ); 1269 _sn = new QSocketNotifier( fileno(), QSocketNotifier::Read );
1270 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) ); 1270 connect( _sn, SIGNAL( activated(int) ), this, SLOT( readyToReceive() ) );
1271 } 1271 }
1272 1272
1273 return true; 1273 return true;
1274 } 1274 }
1275 else 1275 else
1276 { 1276 {
1277 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf ); 1277 qDebug( "OPacketCapturer::open(): can't open libpcap with '%s': %s", (const char*) name, _errbuf );
1278 return false; 1278 return false;
1279 } 1279 }
1280 1280
1281} 1281}
1282 1282
1283 1283
1284bool OPacketCapturer::isOpen() const 1284bool OPacketCapturer::isOpen() const
1285{ 1285{
1286 return _open; 1286 return _open;
1287} 1287}
1288 1288
1289 1289
1290void OPacketCapturer::readyToReceive() 1290void OPacketCapturer::readyToReceive()
1291{ 1291{
1292 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" ); 1292 qDebug( "OPacketCapturer::readyToReceive(): about to emit 'receivePacket(p)'" );
1293 OPacket* p = next(); 1293 OPacket* p = next();
1294 emit receivedPacket( p ); 1294 emit receivedPacket( p );
1295 // emit is synchronous - packet has been dealt with, now it's safe to delete 1295 // emit is synchronous - packet has been dealt with, now it's safe to delete
1296 delete p; 1296 delete p;
1297} 1297}
1298 1298
1299 1299
1300const QMap<QString,int>& OPacketCapturer::statistics() const 1300const QMap<QString,int>& OPacketCapturer::statistics() const
1301{ 1301{
1302 return _stats; 1302 return _stats;
1303} 1303}
1304 1304
1305 1305
1306int OPacketCapturer::snapShot() const 1306int OPacketCapturer::snapShot() const
1307{ 1307{
1308 return pcap_snapshot( _pch ); 1308 return pcap_snapshot( _pch );
1309} 1309}
1310 1310
1311 1311
1312bool OPacketCapturer::swapped() const 1312bool OPacketCapturer::swapped() const
1313{ 1313{
1314 return pcap_is_swapped( _pch ); 1314 return pcap_is_swapped( _pch );
1315} 1315}
1316 1316
1317 1317
1318QString OPacketCapturer::version() const 1318QString OPacketCapturer::version() const
1319{ 1319{
1320 return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) ); 1320 return QString().sprintf( "%s.%s", pcap_major_version( _pch ), pcap_minor_version( _pch ) );
1321} 1321}
1322 1322
1323 1323