summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-03-31 10:21:22 (UTC)
committer mickeyl <mickeyl>2003-03-31 10:21:22 (UTC)
commit636449b2246963c2c9e48163332a0227036e4364 (patch) (unidiff)
treec7383136a93938584b80b8f59c756733772d314d
parent2318b309ef4c5147fa1a975b7b261ceec5dd13a7 (diff)
downloadopie-636449b2246963c2c9e48163332a0227036e4364.zip
opie-636449b2246963c2c9e48163332a0227036e4364.tar.gz
opie-636449b2246963c2c9e48163332a0227036e4364.tar.bz2
resolve potential ambiguities in pow()
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index cd36f16..50d67bb 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,809 +1,809 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/onetwork.h> 36#include <opie2/onetwork.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qfile.h> 40#include <qfile.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42 42
43/* UNIX */ 43/* UNIX */
44 44
45#include <arpa/inet.h> 45#include <arpa/inet.h>
46#include <cerrno> 46#include <cerrno>
47#include <cstring> 47#include <cstring>
48#include <cstdlib> 48#include <cstdlib>
49#include <math.h> 49#include <math.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/socket.h> 51#include <sys/socket.h>
52#include <sys/types.h> 52#include <sys/types.h>
53#include <unistd.h> 53#include <unistd.h>
54#include <linux/sockios.h> 54#include <linux/sockios.h>
55 55
56using namespace std; 56using namespace std;
57 57
58/*====================================================================================== 58/*======================================================================================
59 * ONetwork 59 * ONetwork
60 *======================================================================================*/ 60 *======================================================================================*/
61 61
62ONetwork* ONetwork::_instance = 0; 62ONetwork* ONetwork::_instance = 0;
63 63
64ONetwork::ONetwork() 64ONetwork::ONetwork()
65{ 65{
66 qDebug( "ONetwork::ONetwork()" ); 66 qDebug( "ONetwork::ONetwork()" );
67 synchronize(); 67 synchronize();
68} 68}
69 69
70void ONetwork::synchronize() 70void ONetwork::synchronize()
71{ 71{
72 // gather available interfaces by inspecting /proc/net/dev 72 // gather available interfaces by inspecting /proc/net/dev
73 // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 73 // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
74 74
75 _interfaces.clear(); 75 _interfaces.clear();
76 QString str; 76 QString str;
77 QFile f( "/proc/net/dev" ); 77 QFile f( "/proc/net/dev" );
78 bool hasFile = f.open( IO_ReadOnly ); 78 bool hasFile = f.open( IO_ReadOnly );
79 if ( !hasFile ) 79 if ( !hasFile )
80 { 80 {
81 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 81 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
82 return; 82 return;
83 } 83 }
84 QTextStream s( &f ); 84 QTextStream s( &f );
85 s.readLine(); 85 s.readLine();
86 s.readLine(); 86 s.readLine();
87 while ( !s.atEnd() ) 87 while ( !s.atEnd() )
88 { 88 {
89 s >> str; 89 s >> str;
90 str.truncate( str.find( ':' ) ); 90 str.truncate( str.find( ':' ) );
91 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 91 qDebug( "ONetwork: found interface '%s'", (const char*) str );
92 ONetworkInterface* iface; 92 ONetworkInterface* iface;
93 if ( isWirelessInterface( str ) ) 93 if ( isWirelessInterface( str ) )
94 { 94 {
95 iface = new OWirelessNetworkInterface( str ); 95 iface = new OWirelessNetworkInterface( str );
96 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 96 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
97 } 97 }
98 else 98 else
99 { 99 {
100 iface = new ONetworkInterface( str ); 100 iface = new ONetworkInterface( str );
101 } 101 }
102 _interfaces.insert( str, iface ); 102 _interfaces.insert( str, iface );
103 s.readLine(); 103 s.readLine();
104 } 104 }
105} 105}
106 106
107 107
108ONetworkInterface* ONetwork::interface( QString iface ) const 108ONetworkInterface* ONetwork::interface( QString iface ) const
109{ 109{
110 return _interfaces[iface]; 110 return _interfaces[iface];
111} 111}
112 112
113 113
114ONetwork* ONetwork::instance() 114ONetwork* ONetwork::instance()
115{ 115{
116 if ( !_instance ) _instance = new ONetwork(); 116 if ( !_instance ) _instance = new ONetwork();
117 return _instance; 117 return _instance;
118} 118}
119 119
120 120
121ONetwork::InterfaceIterator ONetwork::iterator() const 121ONetwork::InterfaceIterator ONetwork::iterator() const
122{ 122{
123 return ONetwork::InterfaceIterator( _interfaces ); 123 return ONetwork::InterfaceIterator( _interfaces );
124} 124}
125 125
126 126
127bool ONetwork::isWirelessInterface( const char* name ) const 127bool ONetwork::isWirelessInterface( const char* name ) const
128{ 128{
129 int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); 129 int sfd = socket( AF_INET, SOCK_DGRAM, 0 );
130 iwreqstruct iwr; 130 iwreqstruct iwr;
131 memset( &iwr, 0, sizeof( iwreqstruct ) ); 131 memset( &iwr, 0, sizeof( iwreqstruct ) );
132 strcpy( (char*) &iwr.ifr_name, name ); 132 strcpy( (char*) &iwr.ifr_name, name );
133 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 133 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
134 if ( result == -1 ) 134 if ( result == -1 )
135 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); 135 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) );
136 else 136 else
137 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); 137 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." );
138 return ( result != -1 ); 138 return ( result != -1 );
139} 139}
140 140
141/*====================================================================================== 141/*======================================================================================
142 * ONetworkInterface 142 * ONetworkInterface
143 *======================================================================================*/ 143 *======================================================================================*/
144 144
145ONetworkInterface::ONetworkInterface( const QString& name ) 145ONetworkInterface::ONetworkInterface( const QString& name )
146 :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 146 :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
147{ 147{
148 qDebug( "ONetworkInterface::ONetworkInterface()" ); 148 qDebug( "ONetworkInterface::ONetworkInterface()" );
149 init(); 149 init();
150} 150}
151 151
152 152
153ifreqstruct& ONetworkInterface::ifr() const 153ifreqstruct& ONetworkInterface::ifr() const
154{ 154{
155 return _ifr; 155 return _ifr;
156} 156}
157 157
158 158
159void ONetworkInterface::init() 159void ONetworkInterface::init()
160{ 160{
161 qDebug( "ONetworkInterface::init()" ); 161 qDebug( "ONetworkInterface::init()" );
162 162
163 memset( &_ifr, 0, sizeof( struct ifreq ) ); 163 memset( &_ifr, 0, sizeof( struct ifreq ) );
164 164
165 if ( _sfd == -1 ) 165 if ( _sfd == -1 )
166 { 166 {
167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); 167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name );
168 return; 168 return;
169 } 169 }
170} 170}
171 171
172 172
173bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const 173bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const
174{ 174{
175 int result = ::ioctl( _sfd, call, &ifreq ); 175 int result = ::ioctl( _sfd, call, &ifreq );
176 if ( result == -1 ) 176 if ( result == -1 )
177 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 177 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
178 else 178 else
179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); 179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call );
180 return ( result != -1 ); 180 return ( result != -1 );
181} 181}
182 182
183 183
184bool ONetworkInterface::ioctl( int call ) const 184bool ONetworkInterface::ioctl( int call ) const
185{ 185{
186 strcpy( _ifr.ifr_name, (const char*) _name ); 186 strcpy( _ifr.ifr_name, (const char*) _name );
187 return ioctl( call, _ifr ); 187 return ioctl( call, _ifr );
188} 188}
189 189
190 190
191bool ONetworkInterface::isLoopback() const 191bool ONetworkInterface::isLoopback() const
192{ 192{
193 ioctl( SIOCGIFFLAGS ); 193 ioctl( SIOCGIFFLAGS );
194 return _ifr.ifr_flags & IFF_LOOPBACK; 194 return _ifr.ifr_flags & IFF_LOOPBACK;
195} 195}
196 196
197 197
198bool ONetworkInterface::setUp( bool b ) 198bool ONetworkInterface::setUp( bool b )
199{ 199{
200 ioctl( SIOCGIFFLAGS ); 200 ioctl( SIOCGIFFLAGS );
201 if ( b ) _ifr.ifr_flags |= IFF_UP; 201 if ( b ) _ifr.ifr_flags |= IFF_UP;
202 else _ifr.ifr_flags &= (~IFF_UP); 202 else _ifr.ifr_flags &= (~IFF_UP);
203 return ioctl( SIOCSIFFLAGS ); 203 return ioctl( SIOCSIFFLAGS );
204} 204}
205 205
206 206
207bool ONetworkInterface::isUp() const 207bool ONetworkInterface::isUp() const
208{ 208{
209 ioctl( SIOCGIFFLAGS ); 209 ioctl( SIOCGIFFLAGS );
210 return _ifr.ifr_flags & IFF_UP; 210 return _ifr.ifr_flags & IFF_UP;
211} 211}
212 212
213 213
214QString ONetworkInterface::ipV4Address() const 214QString ONetworkInterface::ipV4Address() const
215{ 215{
216 if ( ioctl( SIOCGIFADDR ) ) 216 if ( ioctl( SIOCGIFADDR ) )
217 { 217 {
218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
219 //FIXME: Use QHostAddress here 219 //FIXME: Use QHostAddress here
220 return QString( inet_ntoa( sa->sin_addr ) ); 220 return QString( inet_ntoa( sa->sin_addr ) );
221 } 221 }
222 else 222 else
223 return "<unknown>"; 223 return "<unknown>";
224} 224}
225 225
226 226
227OMacAddress ONetworkInterface::macAddress() const 227OMacAddress ONetworkInterface::macAddress() const
228{ 228{
229 if ( ioctl( SIOCGIFHWADDR ) ) 229 if ( ioctl( SIOCGIFHWADDR ) )
230 { 230 {
231 return OMacAddress( _ifr ); 231 return OMacAddress( _ifr );
232 } 232 }
233 else 233 else
234 { 234 {
235 return OMacAddress::unknown; 235 return OMacAddress::unknown;
236 } 236 }
237} 237}
238 238
239 239
240void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 240void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
241{ 241{
242 _mon = m; 242 _mon = m;
243 qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() ); 243 qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() );
244} 244}
245 245
246 246
247OMonitoringInterface* ONetworkInterface::monitoring() const 247OMonitoringInterface* ONetworkInterface::monitoring() const
248{ 248{
249 return _mon; 249 return _mon;
250} 250}
251 251
252 252
253const QString& ONetworkInterface::name() const 253const QString& ONetworkInterface::name() const
254{ 254{
255 return _name; 255 return _name;
256} 256}
257 257
258 258
259ONetworkInterface::~ONetworkInterface() 259ONetworkInterface::~ONetworkInterface()
260{ 260{
261 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 261 qDebug( "ONetworkInterface::~ONetworkInterface()" );
262 if ( _sfd != -1 ) ::close( _sfd ); 262 if ( _sfd != -1 ) ::close( _sfd );
263} 263}
264 264
265 265
266bool ONetworkInterface::setPromiscuousMode( bool b ) 266bool ONetworkInterface::setPromiscuousMode( bool b )
267{ 267{
268 ioctl( SIOCGIFFLAGS ); 268 ioctl( SIOCGIFFLAGS );
269 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 269 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
270 else _ifr.ifr_flags &= (~IFF_PROMISC); 270 else _ifr.ifr_flags &= (~IFF_PROMISC);
271 return ioctl( SIOCSIFFLAGS ); 271 return ioctl( SIOCSIFFLAGS );
272} 272}
273 273
274 274
275bool ONetworkInterface::promiscuousMode() const 275bool ONetworkInterface::promiscuousMode() const
276{ 276{
277 ioctl( SIOCGIFFLAGS ); 277 ioctl( SIOCGIFFLAGS );
278 return _ifr.ifr_flags & IFF_PROMISC; 278 return _ifr.ifr_flags & IFF_PROMISC;
279} 279}
280 280
281 281
282bool ONetworkInterface::isWireless() const 282bool ONetworkInterface::isWireless() const
283{ 283{
284 return ioctl( SIOCGIWNAME ); 284 return ioctl( SIOCGIWNAME );
285} 285}
286 286
287 287
288/*====================================================================================== 288/*======================================================================================
289 * OChannelHopper 289 * OChannelHopper
290 *======================================================================================*/ 290 *======================================================================================*/
291 291
292OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 292OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
293 :QObject( 0, "Mickey's funky hopper" ), 293 :QObject( 0, "Mickey's funky hopper" ),
294 _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ), 294 _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ),
295 _maxChannel( iface->channels()+1 ) 295 _maxChannel( iface->channels()+1 )
296{ 296{
297} 297}
298 298
299 299
300OChannelHopper::~OChannelHopper() 300OChannelHopper::~OChannelHopper()
301{ 301{
302} 302}
303 303
304 304
305bool OChannelHopper::isActive() const 305bool OChannelHopper::isActive() const
306{ 306{
307 return _tid; 307 return _tid;
308} 308}
309 309
310 310
311int OChannelHopper::channel() const 311int OChannelHopper::channel() const
312{ 312{
313 return _channel; 313 return _channel;
314} 314}
315 315
316 316
317void OChannelHopper::timerEvent( QTimerEvent* ) 317void OChannelHopper::timerEvent( QTimerEvent* )
318{ 318{
319 if ( !--_channel ) _channel = _maxChannel; 319 if ( !--_channel ) _channel = _maxChannel;
320 _iface->setChannel( _channel ); 320 _iface->setChannel( _channel );
321 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 321 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
322 _channel, (const char*) _iface->name() ); 322 _channel, (const char*) _iface->name() );
323} 323}
324 324
325 325
326void OChannelHopper::setInterval( int interval ) 326void OChannelHopper::setInterval( int interval )
327{ 327{
328 if ( interval == _interval ) 328 if ( interval == _interval )
329 return; 329 return;
330 330
331 if ( _interval ) 331 if ( _interval )
332 killTimer( _tid ); 332 killTimer( _tid );
333 333
334 _tid = 0; 334 _tid = 0;
335 _interval = interval; 335 _interval = interval;
336 336
337 if ( _interval ) 337 if ( _interval )
338 { 338 {
339 _tid = startTimer( interval ); 339 _tid = startTimer( interval );
340 } 340 }
341} 341}
342 342
343 343
344int OChannelHopper::interval() const 344int OChannelHopper::interval() const
345{ 345{
346 return _interval; 346 return _interval;
347} 347}
348 348
349 349
350/*====================================================================================== 350/*======================================================================================
351 * OWirelessNetworkInterface 351 * OWirelessNetworkInterface
352 *======================================================================================*/ 352 *======================================================================================*/
353 353
354OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) 354OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name )
355 :ONetworkInterface( name ), _hopper( 0 ) 355 :ONetworkInterface( name ), _hopper( 0 )
356{ 356{
357 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 357 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
358 init(); 358 init();
359} 359}
360 360
361 361
362OWirelessNetworkInterface::~OWirelessNetworkInterface() 362OWirelessNetworkInterface::~OWirelessNetworkInterface()
363{ 363{
364} 364}
365 365
366 366
367iwreqstruct& OWirelessNetworkInterface::iwr() const 367iwreqstruct& OWirelessNetworkInterface::iwr() const
368{ 368{
369 return _iwr; 369 return _iwr;
370} 370}
371 371
372 372
373void OWirelessNetworkInterface::init() 373void OWirelessNetworkInterface::init()
374{ 374{
375 qDebug( "OWirelessNetworkInterface::init()" ); 375 qDebug( "OWirelessNetworkInterface::init()" );
376 376
377 memset( &_iwr, 0, sizeof( struct iwreq ) ); 377 memset( &_iwr, 0, sizeof( struct iwreq ) );
378 378
379 // IEEE802.11(b) radio frequency channels 379 // IEEE802.11(b) radio frequency channels
380 380
381 iwrangestruct range; 381 iwrangestruct range;
382 //ML: work around an ugly HostAP bug, which needs 382 //ML: work around an ugly HostAP bug, which needs
383 //ML: extra space or will complain with "invalid argument length"... :-( 383 //ML: extra space or will complain with "invalid argument length"... :-(
384 char __extraBufferForBuggyDrivers[sizeof range]; 384 char __extraBufferForBuggyDrivers[sizeof range];
385 _iwr.u.data.pointer = (char*) &range; 385 _iwr.u.data.pointer = (char*) &range;
386 _iwr.u.data.length = (sizeof range) * 2; 386 _iwr.u.data.length = (sizeof range) * 2;
387 _iwr.u.data.flags = 0; 387 _iwr.u.data.flags = 0;
388 if ( !wioctl( SIOCGIWRANGE ) ) 388 if ( !wioctl( SIOCGIWRANGE ) )
389 { 389 {
390 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); 390 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) );
391 return; 391 return;
392 } 392 }
393 393
394 for ( int i = 0; i < range.num_frequency; ++i ) 394 for ( int i = 0; i < range.num_frequency; ++i )
395 { 395 {
396 int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); 396 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
397 _channels.insert( freq, i+1 ); 397 _channels.insert( freq, i+1 );
398 } 398 }
399} 399}
400 400
401 401
402QString OWirelessNetworkInterface::associatedAP() const 402QString OWirelessNetworkInterface::associatedAP() const
403{ 403{
404 //FIXME: use OMacAddress 404 //FIXME: use OMacAddress
405 QString mac; 405 QString mac;
406 406
407 if ( ioctl( SIOCGIWAP ) ) 407 if ( ioctl( SIOCGIWAP ) )
408 { 408 {
409 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 409 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
410 _ifr.ifr_hwaddr.sa_data[0]&0xff, 410 _ifr.ifr_hwaddr.sa_data[0]&0xff,
411 _ifr.ifr_hwaddr.sa_data[1]&0xff, 411 _ifr.ifr_hwaddr.sa_data[1]&0xff,
412 _ifr.ifr_hwaddr.sa_data[2]&0xff, 412 _ifr.ifr_hwaddr.sa_data[2]&0xff,
413 _ifr.ifr_hwaddr.sa_data[3]&0xff, 413 _ifr.ifr_hwaddr.sa_data[3]&0xff,
414 _ifr.ifr_hwaddr.sa_data[4]&0xff, 414 _ifr.ifr_hwaddr.sa_data[4]&0xff,
415 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 415 _ifr.ifr_hwaddr.sa_data[5]&0xff );
416 } 416 }
417 else 417 else
418 { 418 {
419 mac = "<Unknown>"; 419 mac = "<Unknown>";
420 } 420 }
421 return mac; 421 return mac;
422} 422}
423 423
424 424
425int OWirelessNetworkInterface::channel() const 425int OWirelessNetworkInterface::channel() const
426{ 426{
427 //FIXME: When monitoring enabled, then use it 427 //FIXME: When monitoring enabled, then use it
428 //FIXME: to gather the current RF channel 428 //FIXME: to gather the current RF channel
429 //FIXME: Until then, get active channel from hopper. 429 //FIXME: Until then, get active channel from hopper.
430 if ( _hopper && _hopper->isActive() ) 430 if ( _hopper && _hopper->isActive() )
431 return _hopper->channel(); 431 return _hopper->channel();
432 432
433 if ( !wioctl( SIOCGIWFREQ ) ) 433 if ( !wioctl( SIOCGIWFREQ ) )
434 { 434 {
435 return -1; 435 return -1;
436 } 436 }
437 else 437 else
438 { 438 {
439 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; 439 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
440 } 440 }
441} 441}
442 442
443 443
444void OWirelessNetworkInterface::setChannel( int c ) const 444void OWirelessNetworkInterface::setChannel( int c ) const
445{ 445{
446 if ( !_mon ) 446 if ( !_mon )
447 { 447 {
448 memset( &_iwr, 0, sizeof( iwreqstruct ) ); 448 memset( &_iwr, 0, sizeof( iwreqstruct ) );
449 _iwr.u.freq.m = c; 449 _iwr.u.freq.m = c;
450 _iwr.u.freq.e = 0; 450 _iwr.u.freq.e = 0;
451 wioctl( SIOCSIWFREQ ); 451 wioctl( SIOCSIWFREQ );
452 } 452 }
453 else 453 else
454 { 454 {
455 _mon->setChannel( c ); 455 _mon->setChannel( c );
456 } 456 }
457} 457}
458 458
459 459
460double OWirelessNetworkInterface::frequency() const 460double OWirelessNetworkInterface::frequency() const
461{ 461{
462 if ( !wioctl( SIOCGIWFREQ ) ) 462 if ( !wioctl( SIOCGIWFREQ ) )
463 { 463 {
464 return -1.0; 464 return -1.0;
465 } 465 }
466 else 466 else
467 { 467 {
468 return double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000000.0; 468 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
469 } 469 }
470} 470}
471 471
472 472
473int OWirelessNetworkInterface::channels() const 473int OWirelessNetworkInterface::channels() const
474{ 474{
475 return _channels.count(); 475 return _channels.count();
476} 476}
477 477
478 478
479void OWirelessNetworkInterface::setChannelHopping( int interval ) 479void OWirelessNetworkInterface::setChannelHopping( int interval )
480{ 480{
481 if ( !_hopper ) _hopper = new OChannelHopper( this ); 481 if ( !_hopper ) _hopper = new OChannelHopper( this );
482 _hopper->setInterval( interval ); 482 _hopper->setInterval( interval );
483 //FIXME: When and by whom will the channel hopper be deleted? 483 //FIXME: When and by whom will the channel hopper be deleted?
484} 484}
485 485
486 486
487int OWirelessNetworkInterface::channelHopping() const 487int OWirelessNetworkInterface::channelHopping() const
488{ 488{
489 return _hopper->interval(); 489 return _hopper->interval();
490} 490}
491 491
492 492
493void OWirelessNetworkInterface::setMonitorMode( bool b ) 493void OWirelessNetworkInterface::setMonitorMode( bool b )
494{ 494{
495 if ( _mon ) 495 if ( _mon )
496 _mon->setEnabled( b ); 496 _mon->setEnabled( b );
497 else 497 else
498 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 498 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
499} 499}
500 500
501 501
502bool OWirelessNetworkInterface::monitorMode() const 502bool OWirelessNetworkInterface::monitorMode() const
503{ 503{
504 return _mon ? _mon->enabled() : false; 504 return _mon ? _mon->enabled() : false;
505} 505}
506 506
507 507
508QString OWirelessNetworkInterface::nickName() const 508QString OWirelessNetworkInterface::nickName() const
509{ 509{
510 char str[IW_ESSID_MAX_SIZE]; 510 char str[IW_ESSID_MAX_SIZE];
511 _iwr.u.data.pointer = &str[0]; 511 _iwr.u.data.pointer = &str[0];
512 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 512 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
513 if ( !wioctl( SIOCGIWNICKN ) ) 513 if ( !wioctl( SIOCGIWNICKN ) )
514 { 514 {
515 return "<unknown>"; 515 return "<unknown>";
516 } 516 }
517 else 517 else
518 { 518 {
519 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 519 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
520 return str; 520 return str;
521 } 521 }
522} 522}
523 523
524 524
525QString OWirelessNetworkInterface::SSID() const 525QString OWirelessNetworkInterface::SSID() const
526{ 526{
527 char str[IW_ESSID_MAX_SIZE]; 527 char str[IW_ESSID_MAX_SIZE];
528 _iwr.u.essid.pointer = &str[0]; 528 _iwr.u.essid.pointer = &str[0];
529 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 529 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
530 if ( !wioctl( SIOCGIWESSID ) ) 530 if ( !wioctl( SIOCGIWESSID ) )
531 { 531 {
532 return "<unknown>"; 532 return "<unknown>";
533 } 533 }
534 else 534 else
535 { 535 {
536 return str; 536 return str;
537 } 537 }
538} 538}
539 539
540 540
541void OWirelessNetworkInterface::setSSID( const QString& ssid ) 541void OWirelessNetworkInterface::setSSID( const QString& ssid )
542{ 542{
543 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 543 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
544 _iwr.u.essid.length = ssid.length(); 544 _iwr.u.essid.length = ssid.length();
545 wioctl( SIOCSIWESSID ); 545 wioctl( SIOCSIWESSID );
546} 546}
547 547
548 548
549bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const 549bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const
550{ 550{
551 int result = ::ioctl( _sfd, call, &iwreq ); 551 int result = ::ioctl( _sfd, call, &iwreq );
552 if ( result == -1 ) 552 if ( result == -1 )
553 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 553 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
554 else 554 else
555 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); 555 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call );
556 return ( result != -1 ); 556 return ( result != -1 );
557} 557}
558 558
559 559
560bool OWirelessNetworkInterface::wioctl( int call ) const 560bool OWirelessNetworkInterface::wioctl( int call ) const
561{ 561{
562 strcpy( _iwr.ifr_name, (const char*) _name ); 562 strcpy( _iwr.ifr_name, (const char*) _name );
563 return wioctl( call, _iwr ); 563 return wioctl( call, _iwr );
564} 564}
565 565
566 566
567/*====================================================================================== 567/*======================================================================================
568 * OMonitoringInterface 568 * OMonitoringInterface
569 *======================================================================================*/ 569 *======================================================================================*/
570 570
571OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) 571OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface )
572 :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) 572 :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) )
573{ 573{
574} 574}
575 575
576 576
577OMonitoringInterface::~OMonitoringInterface() 577OMonitoringInterface::~OMonitoringInterface()
578{ 578{
579} 579}
580 580
581 581
582void OMonitoringInterface::setChannel( int c ) 582void OMonitoringInterface::setChannel( int c )
583{ 583{
584 // use standard WE channel switching protocol 584 // use standard WE channel switching protocol
585 memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); 585 memset( &_if->_iwr, 0, sizeof( iwreqstruct ) );
586 _if->_iwr.u.freq.m = c; 586 _if->_iwr.u.freq.m = c;
587 _if->_iwr.u.freq.e = 0; 587 _if->_iwr.u.freq.e = 0;
588 _if->wioctl( SIOCSIWFREQ ); 588 _if->wioctl( SIOCSIWFREQ );
589} 589}
590 590
591 591
592bool OMonitoringInterface::enabled() const 592bool OMonitoringInterface::enabled() const
593{ 593{
594 return _enabled; 594 return _enabled;
595} 595}
596 596
597void OMonitoringInterface::setEnabled( bool b ) 597void OMonitoringInterface::setEnabled( bool b )
598{ 598{
599 // open a packet capturer here or leave this to 599 // open a packet capturer here or leave this to
600 // the client code? 600 // the client code?
601 601
602 /* 602 /*
603 603
604 if ( b ) 604 if ( b )
605 { 605 {
606 OPacketCapturer* opcap = new OPacketCapturer(); 606 OPacketCapturer* opcap = new OPacketCapturer();
607 opcap->open( _if->name() ); 607 opcap->open( _if->name() );
608 } 608 }
609 */ 609 */
610 610
611 _enabled = b; 611 _enabled = b;
612 612
613} 613}
614 614
615/*====================================================================================== 615/*======================================================================================
616 * OCiscoMonitoringInterface 616 * OCiscoMonitoringInterface
617 *======================================================================================*/ 617 *======================================================================================*/
618 618
619OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) 619OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface )
620 :OMonitoringInterface( iface ) 620 :OMonitoringInterface( iface )
621{ 621{
622 iface->setMonitoring( this ); 622 iface->setMonitoring( this );
623} 623}
624 624
625 625
626OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 626OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
627{ 627{
628} 628}
629 629
630 630
631void OCiscoMonitoringInterface::setEnabled( bool b ) 631void OCiscoMonitoringInterface::setEnabled( bool b )
632{ 632{
633 QString fname; 633 QString fname;
634 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 634 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
635 QFile f( fname ); 635 QFile f( fname );
636 if ( !f.exists() ) return; 636 if ( !f.exists() ) return;
637 637
638 if ( f.open( IO_WriteOnly ) ) 638 if ( f.open( IO_WriteOnly ) )
639 { 639 {
640 QTextStream s( &f ); 640 QTextStream s( &f );
641 s << "Mode: r"; 641 s << "Mode: r";
642 s << "Mode: y"; 642 s << "Mode: y";
643 s << "XmitPower: 1"; 643 s << "XmitPower: 1";
644 644
645 OMonitoringInterface::setEnabled( b ); 645 OMonitoringInterface::setEnabled( b );
646 646
647 } 647 }
648 648
649 // flushing and closing will be done automatically when f goes out of scope 649 // flushing and closing will be done automatically when f goes out of scope
650} 650}
651 651
652 652
653QString OCiscoMonitoringInterface::name() const 653QString OCiscoMonitoringInterface::name() const
654{ 654{
655 return "cisco"; 655 return "cisco";
656} 656}
657 657
658 658
659void OCiscoMonitoringInterface::setChannel( int ) 659void OCiscoMonitoringInterface::setChannel( int )
660{ 660{
661 // cisco devices automatically switch channels when in monitor mode 661 // cisco devices automatically switch channels when in monitor mode
662} 662}
663 663
664 664
665/*====================================================================================== 665/*======================================================================================
666 * OWlanNGMonitoringInterface 666 * OWlanNGMonitoringInterface
667 *======================================================================================*/ 667 *======================================================================================*/
668 668
669 669
670OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) 670OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface )
671 :OMonitoringInterface( iface ) 671 :OMonitoringInterface( iface )
672{ 672{
673 iface->setMonitoring( this ); 673 iface->setMonitoring( this );
674} 674}
675 675
676 676
677OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 677OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
678{ 678{
679} 679}
680 680
681 681
682void OWlanNGMonitoringInterface::setEnabled( bool b ) 682void OWlanNGMonitoringInterface::setEnabled( bool b )
683{ 683{
684 //FIXME: do nothing if its already in the same mode 684 //FIXME: do nothing if its already in the same mode
685 685
686 QString enable = b ? "true" : "false"; 686 QString enable = b ? "true" : "false";
687 QString cmd; 687 QString cmd;
688 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); 688 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable );
689 system( cmd ); 689 system( cmd );
690 690
691 OMonitoringInterface::setEnabled( b ); 691 OMonitoringInterface::setEnabled( b );
692} 692}
693 693
694 694
695QString OWlanNGMonitoringInterface::name() const 695QString OWlanNGMonitoringInterface::name() const
696{ 696{
697 return "wlan-ng"; 697 return "wlan-ng";
698} 698}
699 699
700 700
701void OWlanNGMonitoringInterface::setChannel( int ) 701void OWlanNGMonitoringInterface::setChannel( int )
702{ 702{
703 // wlan-ng devices automatically switch channels when in monitor mode 703 // wlan-ng devices automatically switch channels when in monitor mode
704} 704}
705 705
706 706
707/*====================================================================================== 707/*======================================================================================
708 * OHostAPMonitoringInterface 708 * OHostAPMonitoringInterface
709 *======================================================================================*/ 709 *======================================================================================*/
710 710
711OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) 711OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface )
712 :OMonitoringInterface( iface ) 712 :OMonitoringInterface( iface )
713{ 713{
714 iface->setMonitoring( this ); 714 iface->setMonitoring( this );
715} 715}
716 716
717OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 717OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
718{ 718{
719} 719}
720 720
721void OHostAPMonitoringInterface::setEnabled( bool b ) 721void OHostAPMonitoringInterface::setEnabled( bool b )
722{ 722{
723 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 723 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
724 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 724 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
725 725
726 if ( b ) 726 if ( b )
727 { 727 {
728 #if WIRELESS_EXT > 14 728 #if WIRELESS_EXT > 14
729 _if->_iwr.u.mode = IW_MODE_MONITOR; 729 _if->_iwr.u.mode = IW_MODE_MONITOR;
730 _if->wioctl( SIOCSIWMODE ); 730 _if->wioctl( SIOCSIWMODE );
731 #else 731 #else
732 int* args = (int*) &_if->_iwr.u.name; 732 int* args = (int*) &_if->_iwr.u.name;
733 args[0] = 2; 733 args[0] = 2;
734 args[1] = 0; 734 args[1] = 0;
735 _if->wioctl( SIOCDEVPRIVATE ); 735 _if->wioctl( SIOCDEVPRIVATE );
736 #endif 736 #endif
737 } 737 }
738 else 738 else
739 { 739 {
740 #if WIRELESS_EXT > 14 740 #if WIRELESS_EXT > 14
741 _if->_iwr.u.mode = IW_MODE_INFRA; 741 _if->_iwr.u.mode = IW_MODE_INFRA;
742 _if->wioctl( SIOCSIWMODE ); 742 _if->wioctl( SIOCSIWMODE );
743 #else 743 #else
744 int* args = (int*) &_if->_iwr.u.name; 744 int* args = (int*) &_if->_iwr.u.name;
745 args[0] = 0; 745 args[0] = 0;
746 args[1] = 0; 746 args[1] = 0;
747 _if->wioctl( SIOCDEVPRIVATE ); 747 _if->wioctl( SIOCDEVPRIVATE );
748 #endif 748 #endif
749 } 749 }
750 750
751 OMonitoringInterface::setEnabled( b ); 751 OMonitoringInterface::setEnabled( b );
752} 752}
753 753
754 754
755QString OHostAPMonitoringInterface::name() const 755QString OHostAPMonitoringInterface::name() const
756{ 756{
757 return "hostap"; 757 return "hostap";
758} 758}
759 759
760 760
761/*====================================================================================== 761/*======================================================================================
762 * OOrinocoNetworkInterface 762 * OOrinocoNetworkInterface
763 *======================================================================================*/ 763 *======================================================================================*/
764 764
765OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) 765OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface )
766 :OMonitoringInterface( iface ) 766 :OMonitoringInterface( iface )
767{ 767{
768 iface->setMonitoring( this ); 768 iface->setMonitoring( this );
769} 769}
770 770
771 771
772OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 772OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
773{ 773{
774} 774}
775 775
776 776
777void OOrinocoMonitoringInterface::setChannel( int c ) 777void OOrinocoMonitoringInterface::setChannel( int c )
778{ 778{
779 // call iwpriv <device> monitor 2 <channel> 779 // call iwpriv <device> monitor 2 <channel>
780 int* args = (int*) &_if->_iwr.u.name; 780 int* args = (int*) &_if->_iwr.u.name;
781 args[0] = 2; 781 args[0] = 2;
782 args[1] = c; 782 args[1] = c;
783 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); 783 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
784} 784}
785 785
786 786
787void OOrinocoMonitoringInterface::setEnabled( bool b ) 787void OOrinocoMonitoringInterface::setEnabled( bool b )
788{ 788{
789 if ( b ) 789 if ( b )
790 { 790 {
791 setChannel( 1 ); 791 setChannel( 1 );
792 } 792 }
793 else 793 else
794 { 794 {
795 // call iwpriv <device> monitor 0 0 795 // call iwpriv <device> monitor 0 0
796 int* args = (int*) &_if->_iwr.u.name; 796 int* args = (int*) &_if->_iwr.u.name;
797 args[0] = 0; 797 args[0] = 0;
798 args[1] = 0; 798 args[1] = 0;
799 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); 799 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
800 } 800 }
801 801
802 OMonitoringInterface::setEnabled( b ); 802 OMonitoringInterface::setEnabled( b );
803} 803}
804 804
805 805
806QString OOrinocoMonitoringInterface::name() const 806QString OOrinocoMonitoringInterface::name() const
807{ 807{
808 return "orinoco"; 808 return "orinoco";
809} 809}