Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 66fa215..789e8ca 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -130,4 +130,4 @@ bool ONetwork::isWirelessInterface( const char* name ) const | |||
130 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 130 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
131 | iwreqstruct iwr; | 131 | struct iwreq iwr; |
132 | memset( &iwr, 0, sizeof( iwreqstruct ) ); | 132 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
133 | strcpy( (char*) &iwr.ifr_name, name ); | 133 | strcpy( (char*) &iwr.ifr_name, name ); |
@@ -154,3 +154,3 @@ ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | |||
154 | 154 | ||
155 | ifreqstruct& ONetworkInterface::ifr() const | 155 | struct ifreq& ONetworkInterface::ifr() const |
156 | { | 156 | { |
@@ -174,3 +174,3 @@ void ONetworkInterface::init() | |||
174 | 174 | ||
175 | bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const | 175 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
176 | { | 176 | { |
@@ -379,3 +379,3 @@ OWirelessNetworkInterface::~OWirelessNetworkInterface() | |||
379 | 379 | ||
380 | iwreqstruct& OWirelessNetworkInterface::iwr() const | 380 | struct iwreq& OWirelessNetworkInterface::iwr() const |
381 | { | 381 | { |
@@ -419,5 +419,2 @@ void OWirelessNetworkInterface::buildChannelList() | |||
419 | { | 419 | { |
420 | // IEEE802.11(b) radio frequency channels | ||
421 | struct iw_range range; | ||
422 | |||
423 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 420 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
@@ -427,8 +424,17 @@ void OWirelessNetworkInterface::buildChannelList() | |||
427 | //ML: _too much_ space. This is damn shitty crap *sigh* | 424 | //ML: _too much_ space. This is damn shitty crap *sigh* |
428 | 425 | //ML: We allocate a large memory region in RAM and check whether the | |
429 | _iwr.u.data.pointer = (char*) ⦥ | 426 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
430 | _iwr.u.data.length = IW_MAX_FREQUENCIES; //sizeof range; | 427 | //ML: so please forward this... |
431 | _iwr.u.data.flags = 0; | 428 | |
432 | 429 | struct iwreq wrq; | |
433 | if ( !wioctl( SIOCGIWRANGE ) ) | 430 | int len = sizeof( struct iw_range )*2; |
431 | char *buffer = (char*) malloc( len ); | ||
432 | //FIXME: Validate if we actually got the memory block | ||
433 | memset( buffer, 0, len ); | ||
434 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | ||
435 | wrq.u.data.pointer = (caddr_t) buffer; | ||
436 | wrq.u.data.length = sizeof( struct iw_range ); | ||
437 | wrq.u.data.flags = 0; | ||
438 | |||
439 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | ||
434 | { | 440 | { |
@@ -449,2 +455,17 @@ void OWirelessNetworkInterface::buildChannelList() | |||
449 | { | 455 | { |
456 | // <check if the driver overwrites stuff> | ||
457 | int max = 0; | ||
458 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | ||
459 | if (buffer[r] != 0) | ||
460 | max = r; | ||
461 | if (max > 0) | ||
462 | { | ||
463 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" | ||
464 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | ||
465 | } | ||
466 | // </check if the driver overwrites stuff> | ||
467 | |||
468 | struct iw_range range; | ||
469 | memcpy( &range, buffer, sizeof range ); | ||
470 | |||
450 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 471 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); |
@@ -456,3 +477,5 @@ void OWirelessNetworkInterface::buildChannelList() | |||
456 | } | 477 | } |
478 | |||
457 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | 479 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); |
480 | free(buffer); | ||
458 | } | 481 | } |
@@ -507,3 +530,3 @@ void OWirelessNetworkInterface::setChannel( int c ) const | |||
507 | { | 530 | { |
508 | memset( &_iwr, 0, sizeof( iwreqstruct ) ); | 531 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
509 | _iwr.u.freq.m = c; | 532 | _iwr.u.freq.m = c; |
@@ -641,3 +664,3 @@ void OWirelessNetworkInterface::setSSID( const QString& ssid ) | |||
641 | 664 | ||
642 | bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const | 665 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
643 | { | 666 | { |
@@ -677,3 +700,3 @@ void OMonitoringInterface::setChannel( int c ) | |||
677 | // use standard WE channel switching protocol | 700 | // use standard WE channel switching protocol |
678 | memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); | 701 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
679 | _if->_iwr.u.freq.m = c; | 702 | _if->_iwr.u.freq.m = c; |