author | mickeyl <mickeyl> | 2003-04-04 13:45:49 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-04 13:45:49 (UTC) |
commit | b2153d44e64c1ade3ee141ea24075add1fd33777 (patch) (unidiff) | |
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 | 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 | |||
@@ -52,6 +52,7 @@ | |||
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 | #include <net/if_arp.h> | ||
55 | #include <stdarg.h> | 56 | #include <stdarg.h> |
56 | 57 | ||
57 | using namespace std; | 58 | using namespace std; |
@@ -71,7 +72,8 @@ ONetwork::ONetwork() | |||
71 | void ONetwork::synchronize() | 72 | void ONetwork::synchronize() |
72 | { | 73 | { |
73 | // gather available interfaces by inspecting /proc/net/dev | 74 | // gather available interfaces by inspecting /proc/net/dev |
74 | // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 75 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
76 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | ||
75 | 77 | ||
76 | _interfaces.clear(); | 78 | _interfaces.clear(); |
77 | QString str; | 79 | QString str; |
@@ -132,11 +134,7 @@ bool ONetwork::isWirelessInterface( const char* name ) const | |||
132 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 134 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
133 | strcpy( (char*) &iwr.ifr_name, name ); | 135 | strcpy( (char*) &iwr.ifr_name, name ); |
134 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 136 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
135 | if ( result == -1 ) | 137 | return result != -1; |
136 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); | ||
137 | else | ||
138 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); | ||
139 | return ( result != -1 ); | ||
140 | } | 138 | } |
141 | 139 | ||
142 | /*====================================================================================== | 140 | /*====================================================================================== |
@@ -239,6 +237,19 @@ OMacAddress ONetworkInterface::macAddress() const | |||
239 | } | 237 | } |
240 | 238 | ||
241 | 239 | ||
240 | int ONetworkInterface::dataLinkType() const | ||
241 | { | ||
242 | if ( ioctl( SIOCGIFHWADDR ) ) | ||
243 | { | ||
244 | return _ifr.ifr_hwaddr.sa_family; | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | return -1; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | |||
242 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 253 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
243 | { | 254 | { |
244 | _mon = m; | 255 | _mon = m; |
@@ -585,7 +596,8 @@ void OWirelessNetworkInterface::setMonitorMode( bool b ) | |||
585 | 596 | ||
586 | bool OWirelessNetworkInterface::monitorMode() const | 597 | bool OWirelessNetworkInterface::monitorMode() const |
587 | { | 598 | { |
588 | return _mon ? _mon->enabled() : false; | 599 | qDebug( "dataLinkType = %d", dataLinkType() ); |
600 | return dataLinkType() == ARPHRD_IEEE80211; | ||
589 | } | 601 | } |
590 | 602 | ||
591 | 603 | ||
@@ -685,7 +697,7 @@ bool OWirelessNetworkInterface::wioctl( int call ) const | |||
685 | *======================================================================================*/ | 697 | *======================================================================================*/ |
686 | 698 | ||
687 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) | 699 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) |
688 | :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) | 700 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) |
689 | { | 701 | { |
690 | } | 702 | } |
691 | 703 | ||
@@ -707,27 +719,15 @@ void OMonitoringInterface::setChannel( int c ) | |||
707 | 719 | ||
708 | bool OMonitoringInterface::enabled() const | 720 | bool OMonitoringInterface::enabled() const |
709 | { | 721 | { |
710 | return _enabled; | 722 | return _if->monitorMode(); |
711 | } | 723 | } |
712 | 724 | ||
725 | |||
713 | void OMonitoringInterface::setEnabled( bool b ) | 726 | void OMonitoringInterface::setEnabled( bool b ) |
714 | { | 727 | { |
715 | // open a packet capturer here or leave this to | ||
716 | // the client code? | ||
717 | |||
718 | /* | ||
719 | |||
720 | if ( b ) | ||
721 | { | ||
722 | OPacketCapturer* opcap = new OPacketCapturer(); | ||
723 | opcap->open( _if->name() ); | ||
724 | } | ||
725 | */ | ||
726 | |||
727 | _enabled = b; | ||
728 | |||
729 | } | 728 | } |
730 | 729 | ||
730 | |||
731 | /*====================================================================================== | 731 | /*====================================================================================== |
732 | * OCiscoMonitoringInterface | 732 | * OCiscoMonitoringInterface |
733 | *======================================================================================*/ | 733 | *======================================================================================*/ |
@@ -757,9 +757,6 @@ void OCiscoMonitoringInterface::setEnabled( bool b ) | |||
757 | s << "Mode: r"; | 757 | s << "Mode: r"; |
758 | s << "Mode: y"; | 758 | s << "Mode: y"; |
759 | s << "XmitPower: 1"; | 759 | s << "XmitPower: 1"; |
760 | |||
761 | OMonitoringInterface::setEnabled( b ); | ||
762 | |||
763 | } | 760 | } |
764 | 761 | ||
765 | // flushing and closing will be done automatically when f goes out of scope | 762 | // flushing and closing will be done automatically when f goes out of scope |
@@ -803,8 +800,6 @@ void OWlanNGMonitoringInterface::setEnabled( bool b ) | |||
803 | QString cmd; | 800 | QString cmd; |
804 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); | 801 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); |
805 | system( cmd ); | 802 | system( cmd ); |
806 | |||
807 | OMonitoringInterface::setEnabled( b ); | ||
808 | } | 803 | } |
809 | 804 | ||
810 | 805 | ||
@@ -863,8 +858,6 @@ void OHostAPMonitoringInterface::setEnabled( bool b ) | |||
863 | _if->wioctl( SIOCDEVPRIVATE ); | 858 | _if->wioctl( SIOCDEVPRIVATE ); |
864 | #endif | 859 | #endif |
865 | } | 860 | } |
866 | |||
867 | OMonitoringInterface::setEnabled( b ); | ||
868 | } | 861 | } |
869 | 862 | ||
870 | 863 | ||
@@ -914,8 +907,6 @@ void OOrinocoMonitoringInterface::setEnabled( bool b ) | |||
914 | args[1] = 0; | 907 | args[1] = 0; |
915 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); | 908 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); |
916 | } | 909 | } |
917 | |||
918 | OMonitoringInterface::setEnabled( b ); | ||
919 | } | 910 | } |
920 | 911 | ||
921 | 912 | ||
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 | |||
126 | bool isWireless() const; | 126 | bool isWireless() const; |
127 | QString ipV4Address() const; | 127 | QString ipV4Address() const; |
128 | OMacAddress macAddress() const; | 128 | OMacAddress macAddress() const; |
129 | int dataLinkType() const; | ||
129 | 130 | ||
130 | protected: | 131 | protected: |
131 | const int _sfd; | 132 | const int _sfd; |
@@ -248,7 +249,6 @@ class OMonitoringInterface | |||
248 | virtual QString name() const = 0; | 249 | virtual QString name() const = 0; |
249 | 250 | ||
250 | protected: | 251 | protected: |
251 | bool _enabled; | ||
252 | const OWirelessNetworkInterface* _if; | 252 | const OWirelessNetworkInterface* _if; |
253 | 253 | ||
254 | }; | 254 | }; |