-rw-r--r-- | libopie2/opienet/onetwork.cpp | 55 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 2 |
2 files changed, 24 insertions, 33 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 @@ -49,12 +49,13 @@ #include <math.h> #include <sys/ioctl.h> #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; /*====================================================================================== * ONetwork @@ -68,13 +69,14 @@ ONetwork::ONetwork() synchronize(); } 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" ); bool hasFile = f.open( IO_ReadOnly ); if ( !hasFile ) @@ -129,17 +131,13 @@ bool ONetwork::isWirelessInterface( const char* name ) const { int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 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 *======================================================================================*/ @@ -236,12 +234,25 @@ OMacAddress ONetworkInterface::macAddress() const { return OMacAddress::unknown; } } +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() ); } @@ -582,13 +593,14 @@ void OWirelessNetworkInterface::setMonitorMode( bool b ) qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); } bool OWirelessNetworkInterface::monitorMode() const { - return _mon ? _mon->enabled() : false; + qDebug( "dataLinkType = %d", dataLinkType() ); + return dataLinkType() == ARPHRD_IEEE80211; } QString OWirelessNetworkInterface::nickName() const { char str[IW_ESSID_MAX_SIZE]; @@ -682,13 +694,13 @@ bool OWirelessNetworkInterface::wioctl( int call ) const /*====================================================================================== * OMonitoringInterface *======================================================================================*/ OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) - :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) + :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) { } OMonitoringInterface::~OMonitoringInterface() { @@ -704,33 +716,21 @@ void OMonitoringInterface::setChannel( int c ) _if->wioctl( SIOCSIWFREQ ); } 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 ) - { - OPacketCapturer* opcap = new OPacketCapturer(); - opcap->open( _if->name() ); - } - */ - - _enabled = b; - } + /*====================================================================================== * OCiscoMonitoringInterface *======================================================================================*/ OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) :OMonitoringInterface( iface ) @@ -754,15 +754,12 @@ void OCiscoMonitoringInterface::setEnabled( bool b ) if ( f.open( IO_WriteOnly ) ) { 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 } @@ -800,14 +797,12 @@ void OWlanNGMonitoringInterface::setEnabled( bool b ) //FIXME: do nothing if its already in the same mode 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 { return "wlan-ng"; @@ -860,14 +855,12 @@ void OHostAPMonitoringInterface::setEnabled( bool b ) int* args = (int*) &_if->_iwr.u.name; args[0] = 0; args[1] = 0; _if->wioctl( SIOCDEVPRIVATE ); #endif } - - OMonitoringInterface::setEnabled( b ); } QString OHostAPMonitoringInterface::name() const { return "hostap"; @@ -911,14 +904,12 @@ void OOrinocoMonitoringInterface::setEnabled( bool b ) // call iwpriv <device> monitor 0 0 int* args = (int*) &_if->_iwr.u.name; args[0] = 0; args[1] = 0; _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); } - - OMonitoringInterface::setEnabled( b ); } QString OOrinocoMonitoringInterface::name() const { return "orinoco"; 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 @@ -123,12 +123,13 @@ class ONetworkInterface : public QObject bool setUp( bool ); bool isUp() const; bool isLoopback() const; bool isWireless() const; QString ipV4Address() const; OMacAddress macAddress() const; + int dataLinkType() const; protected: const int _sfd; mutable ifreq _ifr; OMonitoringInterface* _mon; @@ -245,13 +246,12 @@ class OMonitoringInterface virtual bool enabled() const; virtual void setChannel( int ); virtual QString name() const = 0; protected: - bool _enabled; const OWirelessNetworkInterface* _if; }; /*====================================================================================== |