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 | |
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 @@ -51,8 +51,9 @@ #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> #include <linux/sockios.h> +#include <net/if_arp.h> #include <stdarg.h> using namespace std; @@ -70,9 +71,10 @@ 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; QFile f( "/proc/net/dev" ); @@ -131,13 +133,9 @@ bool ONetwork::isWirelessInterface( const char* name ) const struct iwreq iwr; 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; } /*====================================================================================== * ONetworkInterface @@ -238,8 +236,21 @@ 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; qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); @@ -584,9 +595,10 @@ void OWirelessNetworkInterface::setMonitorMode( bool b ) bool OWirelessNetworkInterface::monitorMode() const { - return _mon ? _mon->enabled() : false; + qDebug( "dataLinkType = %d", dataLinkType() ); + return dataLinkType() == ARPHRD_IEEE80211; } QString OWirelessNetworkInterface::nickName() const @@ -684,9 +696,9 @@ bool OWirelessNetworkInterface::wioctl( int call ) const * OMonitoringInterface *======================================================================================*/ OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) - :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) + :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) { } @@ -706,28 +718,16 @@ 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 *======================================================================================*/ @@ -756,11 +756,8 @@ void OCiscoMonitoringInterface::setEnabled( bool b ) QTextStream s( &f ); 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 } @@ -802,10 +799,8 @@ void OWlanNGMonitoringInterface::setEnabled( bool b ) QString enable = b ? "true" : "false"; 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 ); } QString OWlanNGMonitoringInterface::name() const @@ -862,10 +857,8 @@ void OHostAPMonitoringInterface::setEnabled( bool b ) args[1] = 0; _if->wioctl( SIOCDEVPRIVATE ); #endif } - - OMonitoringInterface::setEnabled( b ); } QString OHostAPMonitoringInterface::name() const @@ -913,10 +906,8 @@ void OOrinocoMonitoringInterface::setEnabled( bool b ) args[0] = 0; args[1] = 0; _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); } - - OMonitoringInterface::setEnabled( b ); } QString OOrinocoMonitoringInterface::name() const 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 @@ -125,8 +125,9 @@ class ONetworkInterface : public QObject bool isLoopback() const; bool isWireless() const; QString ipV4Address() const; OMacAddress macAddress() const; + int dataLinkType() const; protected: const int _sfd; mutable ifreq _ifr; @@ -247,9 +248,8 @@ class OMonitoringInterface virtual QString name() const = 0; protected: - bool _enabled; const OWirelessNetworkInterface* _if; }; |