summaryrefslogtreecommitdiff
path: root/libopie2/opienet
Side-by-side diff
Diffstat (limited to 'libopie2/opienet') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetutils.cpp19
-rw-r--r--libopie2/opienet/onetutils.h8
-rw-r--r--libopie2/opienet/onetwork.cpp43
-rw-r--r--libopie2/opienet/onetwork.h7
4 files changed, 39 insertions, 38 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index c8c494a..9c3e650 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -1,53 +1,51 @@
/*
                This file is part of the Opie Project
-
-              (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
- =.
+ =. (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/onetutils.h>
#include <opie2/onetwork.h>
#include <opie2/omanufacturerdb.h>
#include <net/if.h>
#include <assert.h>
#include <stdio.h>
namespace Opie {
namespace Net {
/*======================================================================================
* OMacAddress
*======================================================================================*/
// static initializer for broadcast and unknown MAC Adresses
const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast );
const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 };
const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown );
//TODO: Incorporate Ethernet Manufacturer database here! (inline or so)
@@ -91,96 +89,111 @@ const unsigned char* OMacAddress::native() const
OMacAddress OMacAddress::fromString( const QString& str )
{
QString addr( str );
unsigned char buf[6];
bool ok = true;
int index = 14;
for ( int i = 5; i >= 0; --i )
{
buf[i] = addr.right( 2 ).toUShort( &ok, 16 );
if ( !ok ) return OMacAddress::unknown;
addr.truncate( index );
index -= 3;
}
return (const unsigned char*) &buf;
}
QString OMacAddress::toString( bool substitute ) const
{
QString manu;
manu.sprintf( "%.2X:%.2X:%.2X", _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff );
QString serial;
serial.sprintf( ":%.2X:%.2X:%.2X", _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff );
if ( !substitute ) return manu+serial;
// fallback - if no vendor is found, just use the number
QString textmanu = OManufacturerDB::instance()->lookup( manu );
return textmanu.isNull() ? manu+serial : textmanu+serial;
}
QString OMacAddress::manufacturer() const
{
return OManufacturerDB::instance()->lookupExt( toString() );
}
bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
{
return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0;
}
/*======================================================================================
* OHostAddress
*======================================================================================*/
+OHostAddress::OHostAddress()
+ :QHostAddress()
+{
+}
+
+
+OHostAddress::OHostAddress( Q_UINT32 ip4Addr )
+ :QHostAddress( ip4Addr )
+{
+}
+
+
+OHostAddress::~OHostAddress()
+{
+}
/*======================================================================================
* OPrivateIOCTL
*======================================================================================*/
OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs )
:QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs )
{
}
OPrivateIOCTL::~OPrivateIOCTL()
{
}
int OPrivateIOCTL::numberGetArgs() const
{
return _getargs & IW_PRIV_SIZE_MASK;
}
int OPrivateIOCTL::typeGetArgs() const
{
return _getargs & IW_PRIV_TYPE_MASK >> 12;
}
int OPrivateIOCTL::numberSetArgs() const
{
return _setargs & IW_PRIV_SIZE_MASK;
}
int OPrivateIOCTL::typeSetArgs() const
{
return _setargs & IW_PRIV_TYPE_MASK >> 12;
}
void OPrivateIOCTL::invoke() const
{
( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl );
}
void OPrivateIOCTL::setParameter( int num, u_int32_t value )
{
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 25c9238..f08738c 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -1,143 +1,143 @@
/*
                This file is part of the Opie Project
-              (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
- =.
+ =. (C) 2003-2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef ONETUTILS_H
#define ONETUTILS_H
#include <qdict.h>
#include <qmap.h>
#include <qstring.h>
#include <qhostaddress.h>
#include <qobject.h>
#include <sys/types.h>
struct ifreq;
namespace Opie {
namespace Net {
class OWirelessNetworkInterface;
/*======================================================================================
* OMacAddress
*======================================================================================*/
class OMacAddress
{
public:
// QString c'tor? -zecke
OMacAddress();
OMacAddress( unsigned char* );
OMacAddress( const unsigned char* );
OMacAddress( struct ifreq& );
~OMacAddress();
QString manufacturer() const;
QString toString( bool substitute = false ) const;
const unsigned char* native() const;
// no c'tor but this one why not make it a c'tor. it could also replace the others or is this the problem?
static OMacAddress fromString( const QString& );
public:
static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff
static const OMacAddress& unknown; // 44:44:44:44:44:44
private:
unsigned char _bytes[6];
friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
class Private;
Private *d;
};
bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
/*======================================================================================
* OHostAddress
*======================================================================================*/
class OHostAddress : public QHostAddress
{
- /*public:
+ public:
OHostAddress();
+ OHostAddress( Q_UINT32 ip4Addr );
~OHostAddress();
- */
+
private:
class Private;
Private *d;
};
/*======================================================================================
* ONetworkInterfaceDriverInfo
*======================================================================================*/
class ONetworkInterfaceDriverInfo
{
public:
ONetworkInterfaceDriverInfo( const QString& name = "<unknown>",
const QString& version = "<unknown>",
const QString& firmware = "<unknown>",
const QString& bus = "<unknown>" ) :
_name( name ), _version( version ), _firmware( firmware ), _bus( bus ) { };
~ONetworkInterfaceDriverInfo() { };
QString name() const { return _name; };
QString version() const { return _version; };
QString firmware() const { return _firmware; };
QString bus() const { return _bus; };
private:
const QString _name;
const QString _version;
const QString _firmware;
const QString _bus;
};
/*======================================================================================
* OPrivateIOCTL
*======================================================================================*/
class OPrivateIOCTL : public QObject
{
public:
OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs );
~OPrivateIOCTL();
int numberGetArgs() const;
int typeGetArgs() const;
int numberSetArgs() const;
int typeSetArgs() const;
// FIXME return int? as ::ioctl does? -zecke
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 1deb051..0649ca2 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,139 +1,134 @@
/*
                This file is part of the Opie Project
-              Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
- =.
+ =. Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* OPIE */
#include <opie2/onetwork.h>
#include <opie2/ostation.h>
#include <opie2/odebug.h>
using namespace Opie::Core;
/* QT */
#include <qfile.h>
#include <qtextstream.h>
#include <qapplication.h>
/* STD */
#include <assert.h>
#include <arpa/inet.h>
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <net/if_arp.h>
#include <net/ethernet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/types.h>
#include <linux/sockios.h>
#define u64 __u64
#define u32 __u32
#define u16 __u16
#define u8 __u8
#include <linux/ethtool.h>
#ifndef NODEBUG
#include <opie2/odebugmapper.h>
using namespace Opie::Net::Internal;
DebugMapper* debugmapper = new DebugMapper();
#endif
/*======================================================================================
* ONetwork
*======================================================================================*/
namespace Opie {
namespace Net {
ONetwork* ONetwork::_instance = 0;
ONetwork::ONetwork()
{
odebug << "ONetwork::ONetwork()" << oendl;
odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl;
synchronize();
}
void ONetwork::synchronize()
{
// gather available interfaces by inspecting /proc/net/dev
- //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
- //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
-
_interfaces.clear();
QString str;
QFile f( "/proc/net/dev" );
bool hasFile = f.open( IO_ReadOnly );
if ( !hasFile )
{
odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl;
return;
}
QTextStream s( &f );
s.readLine();
s.readLine();
while ( !s.atEnd() )
{
s >> str;
str.truncate( str.find( ':' ) );
odebug << "ONetwork: found interface '" << str << "'" << oendl;
if ( str.startsWith( "wifi" ) )
{
odebug << "ONetwork: ignoring hostap control interface" << oendl;
s.readLine();
continue;
}
ONetworkInterface* iface = 0;
if ( isWirelessInterface( str ) )
{
iface = new OWirelessNetworkInterface( this, (const char*) str );
odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl;
}
else
{
iface = new ONetworkInterface( this, (const char*) str );
}
_interfaces.insert( str, iface );
s.readLine();
}
}
short ONetwork::wirelessExtensionCompileVersion()
{
return WIRELESS_EXT;
}
int ONetwork::count() const
{
return _interfaces.count();
@@ -157,219 +152,205 @@ ONetwork::InterfaceIterator ONetwork::iterator() const
{
return ONetwork::InterfaceIterator( _interfaces );
}
bool ONetwork::isPresent( const char* name ) const
{
int sfd = socket( AF_INET, SOCK_STREAM, 0 );
struct ifreq ifr;
memset( &ifr, 0, sizeof( struct ifreq ) );
strcpy( (char*) &ifr.ifr_name, name );
int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr );
return result != -1;
}
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 );
return result != -1;
}
/*======================================================================================
* ONetworkInterface
*======================================================================================*/
ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
:QObject( parent, name ),
_sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
{
odebug << "ONetworkInterface::ONetworkInterface()" << oendl;
init();
}
struct ifreq& ONetworkInterface::ifr() const
{
return _ifr;
}
void ONetworkInterface::init()
{
odebug << "ONetworkInterface::init()" << oendl;
-
memset( &_ifr, 0, sizeof( struct ifreq ) );
if ( _sfd == -1 )
{
odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl;
return;
}
}
bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
{
#ifndef NODEBUG
int result = ::ioctl( _sfd, call, &ifreq );
if ( result == -1 )
odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call )
<< "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl;
else
odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call )
<< "' - Status: Ok." << oendl;
return ( result != -1 );
#else
return ::ioctl( _sfd, call, &ifreq ) != -1;
#endif
}
bool ONetworkInterface::ioctl( int call ) const
{
strcpy( _ifr.ifr_name, name() );
return ioctl( call, _ifr );
}
bool ONetworkInterface::isLoopback() const
{
ioctl( SIOCGIFFLAGS );
return _ifr.ifr_flags & IFF_LOOPBACK;
}
bool ONetworkInterface::setUp( bool b )
{
ioctl( SIOCGIFFLAGS );
if ( b ) _ifr.ifr_flags |= IFF_UP;
else _ifr.ifr_flags &= (~IFF_UP);
return ioctl( SIOCSIFFLAGS );
}
bool ONetworkInterface::isUp() const
{
ioctl( SIOCGIFFLAGS );
return _ifr.ifr_flags & IFF_UP;
}
void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
{
struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
sa->sin_family = AF_INET;
sa->sin_port = 0;
sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
ioctl( SIOCSIFADDR );
}
-QString ONetworkInterface::ipV4Address() const
+OHostAddress ONetworkInterface::ipV4Address() const
{
- if ( ioctl( SIOCGIFADDR ) )
- {
- struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
- //FIXME: Use QHostAddress here
- return QString( inet_ntoa( sa->sin_addr ) );
- }
- else
- return "<unknown>";
-
+ struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
+ return ioctl( SIOCGIFADDR ) ? OHostAddress( ntohl( sa->sin_addr.s_addr ) ) : OHostAddress();
}
void ONetworkInterface::setMacAddress( const OMacAddress& addr )
{
_ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
ioctl( SIOCSIFHWADDR );
}
OMacAddress ONetworkInterface::macAddress() const
{
if ( ioctl( SIOCGIFHWADDR ) )
{
return OMacAddress( _ifr );
}
else
{
return OMacAddress::unknown;
}
}
void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
{
struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
sa->sin_family = AF_INET;
sa->sin_port = 0;
sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
ioctl( SIOCSIFNETMASK );
}
-QString ONetworkInterface::ipV4Netmask() const
+OHostAddress ONetworkInterface::ipV4Netmask() const
{
- if ( ioctl( SIOCGIFNETMASK ) )
- {
- struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
- //FIXME: Use QHostAddress here
- return QString( inet_ntoa( sa->sin_addr ) );
- }
- else
- return "<unknown>";
+ struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
+ return ioctl( SIOCGIFNETMASK ) ? OHostAddress( ntohl( sa->sin_addr.s_addr ) ) : OHostAddress();
}
int ONetworkInterface::dataLinkType() const
{
if ( ioctl( SIOCGIFHWADDR ) )
{
return _ifr.ifr_hwaddr.sa_family;
}
else
{
return -1;
}
}
void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
{
_mon = m;
odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl;
}
OMonitoringInterface* ONetworkInterface::monitoring() const
{
return _mon;
}
ONetworkInterface::~ONetworkInterface()
{
odebug << "ONetworkInterface::~ONetworkInterface()" << oendl;
if ( _sfd != -1 ) ::close( _sfd );
}
bool ONetworkInterface::setPromiscuousMode( bool b )
{
ioctl( SIOCGIFFLAGS );
if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
else _ifr.ifr_flags &= (~IFF_PROMISC);
return ioctl( SIOCSIFFLAGS );
}
bool ONetworkInterface::promiscuousMode() const
{
ioctl( SIOCGIFFLAGS );
@@ -502,97 +483,105 @@ void OWirelessNetworkInterface::init()
dumpInformation();
}
bool OWirelessNetworkInterface::isAssociated() const
{
//FIXME: handle different modes
return !(associatedAP() == OMacAddress::unknown);
}
void OWirelessNetworkInterface::setAssociatedAP( const OMacAddress& mac ) const
{
_iwr.u.ap_addr.sa_family = ARPHRD_ETHER;
::memcpy(_iwr.u.ap_addr.sa_data, mac.native(), ETH_ALEN);
wioctl( SIOCSIWAP );
}
OMacAddress OWirelessNetworkInterface::associatedAP() const
{
if ( ioctl( SIOCGIWAP ) )
return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0];
else
return OMacAddress::unknown;
}
void OWirelessNetworkInterface::buildInformation()
{
//ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
//ML: The HostAP drivers need more than sizeof struct_iw range to complete
//ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
//ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
//ML: _too much_ space. This is damn shitty crap *sigh*
//ML: We allocate a large memory region in RAM and check whether the
//ML: driver pollutes this extra space. The complaint will be made on stdout,
//ML: so please forward this...
struct iwreq wrq;
int len = sizeof( struct iw_range )*2;
char buffer[len];
memset( buffer, 0, len );
memcpy( wrq.ifr_name, name(), IFNAMSIZ);
wrq.u.data.pointer = (caddr_t) buffer;
wrq.u.data.length = sizeof buffer;
wrq.u.data.flags = 0;
- if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
+ int result = ::ioctl( _sfd, SIOCGIWRANGE, &wrq );
+ if ( result == -1 )
+ {
+ owarn << "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (" << strerror( errno ) << ") - retrying with smaller buffer..." << oendl;
+ wrq.u.data.length = sizeof( struct iw_range );
+ result = ::ioctl( _sfd, SIOCGIWRANGE, &wrq );
+ }
+
+ if ( result == -1 )
{
owarn << "OWirelessNetworkInterface::buildInformation(): Can't get driver information (" << strerror( errno ) << ") - using default values." << oendl;
_channels.insert( 2412, 1 ); // 2.412 GHz
_channels.insert( 2417, 2 ); // 2.417 GHz
_channels.insert( 2422, 3 ); // 2.422 GHz
_channels.insert( 2427, 4 ); // 2.427 GHz
_channels.insert( 2432, 5 ); // 2.432 GHz
_channels.insert( 2437, 6 ); // 2.437 GHz
_channels.insert( 2442, 7 ); // 2.442 GHz
_channels.insert( 2447, 8 ); // 2.447 GHz
_channels.insert( 2452, 9 ); // 2.452 GHz
_channels.insert( 2457, 10 ); // 2.457 GHz
_channels.insert( 2462, 11 ); // 2.462 GHz
memset( &_range, 0, sizeof( struct iw_range ) );
}
else
{
// <check if the driver overwrites stuff>
int max = 0;
for ( int r = sizeof( struct iw_range ); r < len; r++ )
if (buffer[r] != 0)
max = r;
if (max > 0)
{
owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name()
<< "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl;
}
// </check if the driver overwrites stuff>
struct iw_range range;
memcpy( &range, buffer, sizeof range );
odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl;
for ( int i = 0; i < range.num_frequency; ++i )
{
int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl;
_channels.insert( freq, i+1 );
}
}
memcpy( &_range, buffer, sizeof( struct iw_range ) );
odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl;
}
short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index f0c4450..b13c7a3 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,52 +1,51 @@
/*
                This file is part of the Opie Project
-              Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
- =.
+ =. Copyright (C) 2003-2005 by Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; version 2 of the License.
     ._= =}       :
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef ONETWORK_H
#define ONETWORK_H
/* OPIE */
#include <opie2/onetutils.h>
#include <opie2/ostation.h>
/* QT */
#include <qvaluelist.h>
#include <qdict.h>
#include <qmap.h>
#include <qobject.h>
#include <qhostaddress.h>
/* STD */
// hacky workarounds until we have a true user space wireless.h
#include <net/if.h>
#define _LINUX_IF_H
#include <linux/wireless.h>
#ifndef IW_MAX_PRIV_DEF
#define IW_MAX_PRIV_DEF 128
#endif
@@ -153,116 +152,116 @@ class ONetworkInterface : public QObject
* but access them via @ref ONetwork::interface().
*/
ONetworkInterface( QObject* parent, const char* name );
/**
* Destructor.
*/
virtual ~ONetworkInterface();
/**
* Associates a @a monitoring interface with this network interface.
* @note This is currently only useful with @ref OWirelessNetworkInterface objects.
*/
void setMonitoring( OMonitoringInterface* monitoring );
/**
* @returns the currently associated monitoring interface or 0, if no monitoring is associated.
*/
OMonitoringInterface* monitoring() const;
/**
* Setting an interface to promiscuous mode enables the device to receive
* all packets on the shared medium - as opposed to packets which are addressed to this interface.
*/
bool setPromiscuousMode( bool );
/**
* @returns true if the interface is set to promiscuous mode.
*/
bool promiscuousMode() const;
/**
* Setting an interface to up enables it to receive packets.
*/
bool setUp( bool );
/**
* @returns true if the interface is up.
*/
bool isUp() const;
/**
* @returns true if the interface is a loopback interface.
*/
bool isLoopback() const;
/**
* @returns true if the interface is featuring supports the wireless extension protocol.
*/
bool isWireless() const;
/**
* Associate the IP address @ addr with the interface.
*/
void setIPV4Address( const QHostAddress& addr );
/**
* @returns the IPv4 address associated with the interface.
*/
- QString ipV4Address() const; //TODO: make this return an OHostAddress
+ OHostAddress ipV4Address() const;
/**
* Associate the MAC address @a addr with the interface.
* @note It can be necessary to shut down the interface prior to calling this method.
* @note This operation needs root privileges
* @warning This is not supported by all drivers.
*/
void setMacAddress( const OMacAddress& addr );
/**
* @returns the MAC address associated with the interface.
*/
OMacAddress macAddress() const;
/**
* Associate the IPv4 @a netmask with the interface.
*/
void setIPV4Netmask( const QHostAddress& netmask );
/**
* @returns the IPv4 netmask associated with the interface.
*/
- QString ipV4Netmask() const; //TODO: make this return an OHostAddress
+ OHostAddress ipV4Netmask() const;
/**
* @returns the data link type currently associated with the interface.
* @see #include <net/if_arp.h> for possible values.
*/
int dataLinkType() const;
/**
* @returns a ONetworkInterfaceDriverInfo driver information block
* @note This operation needs root privileges
* @warning This is not supported by all drivers
*/
ONetworkInterfaceDriverInfo driverInfo() const;
protected:
const int _sfd;
mutable ifreq _ifr;
OMonitoringInterface* _mon;
protected:
struct ifreq& ifr() const;
virtual void init();
bool ioctl( int call ) const;
bool ioctl( int call, struct ifreq& ) const;
private:
class Private;
Private *d;
};
/*======================================================================================
* OChannelHopper
*======================================================================================*/
/**
* @brief A radio frequency channel hopper.
*
* This class provides a channel hopper for radio frequencies. A channel hopper frequently
* changes the radio frequency channel of its associated @ref OWirelessNetworkInterface.
* This is necessary when in monitoring mode and scanning for other devices, because
* the radio frequency hardware can only detect packets sent on the same frequency.
*
* @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
class OChannelHopper : public QObject
{
Q_OBJECT
public:
/**
* Constructor.