summaryrefslogtreecommitdiff
path: root/libopie2/opienet
Side-by-side diff
Diffstat (limited to 'libopie2/opienet') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opienet/onetutils.cpp19
-rw-r--r--libopie2/opienet/onetutils.h8
-rw-r--r--libopie2/opienet/onetwork.cpp39
-rw-r--r--libopie2/opienet/onetwork.h7
4 files changed, 37 insertions, 36 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,17 +1,15 @@
/*
                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
@@ -127,24 +125,39 @@ QString OMacAddress::manufacturer() const
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()
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,16 +1,15 @@
/*
                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
@@ -80,28 +79,29 @@ class OMacAddress
};
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
{
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,16 +1,15 @@
/*
                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
@@ -76,28 +75,24 @@ 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();
@@ -193,25 +188,24 @@ ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
}
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
{
@@ -261,35 +255,28 @@ bool ONetworkInterface::isUp() const
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
-{
- if ( ioctl( SIOCGIFADDR ) )
+OHostAddress ONetworkInterface::ipV4Address() const
{
struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
- //FIXME: Use QHostAddress here
- return QString( inet_ntoa( sa->sin_addr ) );
- }
- else
- return "<unknown>";
-
+ 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
@@ -306,34 +293,28 @@ OMacAddress ONetworkInterface::macAddress() const
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
-{
- if ( ioctl( SIOCGIFNETMASK ) )
+OHostAddress ONetworkInterface::ipV4Netmask() const
{
struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
- //FIXME: Use QHostAddress here
- return QString( inet_ntoa( sa->sin_addr ) );
- }
- else
- return "<unknown>";
+ 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;
@@ -538,25 +519,33 @@ void OWirelessNetworkInterface::buildInformation()
//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
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,16 +1,15 @@
/*
                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
@@ -189,44 +188,44 @@ class ONetworkInterface : public QObject
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;