summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-04 13:45:49 (UTC)
committer mickeyl <mickeyl>2003-04-04 13:45:49 (UTC)
commitb2153d44e64c1ade3ee141ea24075add1fd33777 (patch) (side-by-side diff)
tree6164d2eeef1c0ee79fcf4da85f2c8ed88aa0ecb3
parent089385bb8ab768fbf6f394f326e565e3589163fc (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp55
-rw-r--r--libopie2/opienet/onetwork.h2
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
@@ -47,16 +47,17 @@
#include <cstring>
#include <cstdlib>
#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
*======================================================================================*/
@@ -66,17 +67,18 @@ ONetwork::ONetwork()
{
qDebug( "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 )
{
qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
@@ -127,21 +129,17 @@ ONetwork::InterfaceIterator ONetwork::iterator() const
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
*======================================================================================*/
ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
:QObject( parent, name ),
@@ -234,16 +232,29 @@ OMacAddress ONetworkInterface::macAddress() const
}
else
{
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() );
}
OMonitoringInterface* ONetworkInterface::monitoring() const
@@ -580,17 +591,18 @@ void OWirelessNetworkInterface::setMonitorMode( bool b )
_mon->setEnabled( b );
else
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];
_iwr.u.data.pointer = &str[0];
_iwr.u.data.length = IW_ESSID_MAX_SIZE;
@@ -680,17 +692,17 @@ 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()
{
}
@@ -702,37 +714,25 @@ void OMonitoringInterface::setChannel( int c )
_if->_iwr.u.freq.m = c;
_if->_iwr.u.freq.e = 0;
_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 )
{
iface->setMonitoring( this );
@@ -752,19 +752,16 @@ void OCiscoMonitoringInterface::setEnabled( bool b )
if ( !f.exists() ) return;
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
}
QString OCiscoMonitoringInterface::name() const
{
@@ -798,18 +795,16 @@ OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
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";
}
@@ -858,18 +853,16 @@ void OHostAPMonitoringInterface::setEnabled( bool b )
_if->wioctl( SIOCSIWMODE );
#else
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";
}
@@ -909,17 +902,15 @@ void OOrinocoMonitoringInterface::setEnabled( bool b )
else
{
// 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
@@ -121,16 +121,17 @@ class ONetworkInterface : public QObject
bool setPromiscuousMode( bool );
bool promiscuousMode() const;
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;
protected:
struct ifreq& ifr() const;
@@ -243,17 +244,16 @@ class OMonitoringInterface
public:
virtual void setEnabled( bool );
virtual bool enabled() const;
virtual void setChannel( int );
virtual QString name() const = 0;
protected:
- bool _enabled;
const OWirelessNetworkInterface* _if;
};
/*======================================================================================
* OCiscoMonitoring
*======================================================================================*/