author | mickeyl <mickeyl> | 2003-04-04 13:45:49 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-04 13:45:49 (UTC) |
commit | b2153d44e64c1ade3ee141ea24075add1fd33777 (patch) (side-by-side diff) | |
tree | 6164d2eeef1c0ee79fcf4da85f2c8ed88aa0ecb3 /libopie2/opienet | |
parent | 089385bb8ab768fbf6f394f326e565e3589163fc (diff) | |
download | opie-b2153d44e64c1ade3ee141ea24075add1fd33777.zip opie-b2153d44e64c1ade3ee141ea24075add1fd33777.tar.gz opie-b2153d44e64c1ade3ee141ea24075add1fd33777.tar.bz2 |
reliable strategy to see if we're in monitor mode by looking at the MAC address family
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 53 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 2 |
2 files changed, 23 insertions, 32 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 789e8ca..6a363d7 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp @@ -52,6 +52,7 @@ #include <sys/types.h> #include <unistd.h> #include <linux/sockios.h> +#include <net/if_arp.h> #include <stdarg.h> using namespace std; @@ -71,7 +72,8 @@ ONetwork::ONetwork() void ONetwork::synchronize() { // gather available interfaces by inspecting /proc/net/dev - // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices + //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices + //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices _interfaces.clear(); QString str; @@ -132,11 +134,7 @@ bool ONetwork::isWirelessInterface( const char* name ) const memset( &iwr, 0, sizeof( struct iwreq ) ); strcpy( (char*) &iwr.ifr_name, name ); int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); - if ( result == -1 ) - qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); - else - qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); - return ( result != -1 ); + return result != -1; } /*====================================================================================== @@ -239,6 +237,19 @@ OMacAddress ONetworkInterface::macAddress() const } +int ONetworkInterface::dataLinkType() const +{ + if ( ioctl( SIOCGIFHWADDR ) ) + { + return _ifr.ifr_hwaddr.sa_family; + } + else + { + return -1; + } +} + + void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) { _mon = m; @@ -585,7 +596,8 @@ void OWirelessNetworkInterface::setMonitorMode( bool b ) bool OWirelessNetworkInterface::monitorMode() const { - return _mon ? _mon->enabled() : false; + qDebug( "dataLinkType = %d", dataLinkType() ); + return dataLinkType() == ARPHRD_IEEE80211; } @@ -685,7 +697,7 @@ bool OWirelessNetworkInterface::wioctl( int call ) const *======================================================================================*/ OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) - :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) + :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) { } @@ -707,26 +719,14 @@ void OMonitoringInterface::setChannel( int c ) bool OMonitoringInterface::enabled() const { - return _enabled; + return _if->monitorMode(); } -void OMonitoringInterface::setEnabled( bool b ) -{ - // open a packet capturer here or leave this to - // the client code? - - /* - if ( b ) +void OMonitoringInterface::setEnabled( bool b ) { - OPacketCapturer* opcap = new OPacketCapturer(); - opcap->open( _if->name() ); } - */ - _enabled = b; - -} /*====================================================================================== * OCiscoMonitoringInterface @@ -757,9 +757,6 @@ void OCiscoMonitoringInterface::setEnabled( bool b ) s << "Mode: r"; s << "Mode: y"; s << "XmitPower: 1"; - - OMonitoringInterface::setEnabled( b ); - } // flushing and closing will be done automatically when f goes out of scope @@ -803,8 +800,6 @@ void OWlanNGMonitoringInterface::setEnabled( bool b ) QString cmd; cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); system( cmd ); - - OMonitoringInterface::setEnabled( b ); } @@ -863,8 +858,6 @@ void OHostAPMonitoringInterface::setEnabled( bool b ) _if->wioctl( SIOCDEVPRIVATE ); #endif } - - OMonitoringInterface::setEnabled( b ); } @@ -914,8 +907,6 @@ void OOrinocoMonitoringInterface::setEnabled( bool b ) args[1] = 0; _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); } - - OMonitoringInterface::setEnabled( b ); } diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 509c3db..4cadbeb 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h @@ -126,6 +126,7 @@ class ONetworkInterface : public QObject bool isWireless() const; QString ipV4Address() const; OMacAddress macAddress() const; + int dataLinkType() const; protected: const int _sfd; @@ -248,7 +249,6 @@ class OMonitoringInterface virtual QString name() const = 0; protected: - bool _enabled; const OWirelessNetworkInterface* _if; }; |