summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2005-05-17 16:57:08 (UTC)
committer mickeyl <mickeyl>2005-05-17 16:57:08 (UTC)
commitd2ae68c413873e234b34f733818427902e738948 (patch) (side-by-side diff)
treef5748014d7b1785302c167c6f43fbd0622bf1019 /libopie2
parentcce15d6b9a27880df72ea2638f9295900ea6c21e (diff)
downloadopie-d2ae68c413873e234b34f733818427902e738948.zip
opie-d2ae68c413873e234b34f733818427902e738948.tar.gz
opie-d2ae68c413873e234b34f733818427902e738948.tar.bz2
libopienet API cleanups
Diffstat (limited to 'libopie2') (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,11 +1,9 @@
/*
                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
@@ -133,12 +131,27 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
/*======================================================================================
* 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 )
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,10 +1,9 @@
/*
                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
@@ -86,16 +85,17 @@ 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;
};
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,10 +1,9 @@
/*
                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
@@ -82,16 +81,12 @@ ONetwork::ONetwork()
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 )
{
@@ -199,13 +194,12 @@ struct ifreq& ONetworkInterface::ifr() const
}
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;
@@ -267,23 +261,16 @@ void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
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;
@@ -312,22 +299,16 @@ void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
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 ) )
@@ -544,13 +525,21 @@ void OWirelessNetworkInterface::buildInformation()
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
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,10 +1,9 @@
/*
                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
@@ -195,13 +194,13 @@ class ONetworkInterface : public QObject
* 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.
*/
@@ -214,13 +213,13 @@ class ONetworkInterface : public QObject
* 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;
/**