-rw-r--r-- | libopie2/opienet/onetutils.cpp | 19 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 8 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 43 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 7 |
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,9 +1,7 @@ /* 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 @@ -135,8 +133,23 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) /*====================================================================================== * OHostAddress *======================================================================================*/ +OHostAddress::OHostAddress() + :QHostAddress() +{ +} + + +OHostAddress::OHostAddress( Q_UINT32 ip4Addr ) + :QHostAddress( ip4Addr ) +{ +} + + +OHostAddress::~OHostAddress() +{ +} /*====================================================================================== * 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,8 +1,7 @@ /* 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 @@ -88,12 +87,13 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); *======================================================================================*/ 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,8 +1,7 @@ /* 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 @@ -84,12 +83,8 @@ ONetwork::ONetwork() 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 ); @@ -201,9 +196,8 @@ struct ifreq& ONetworkInterface::ifr() const void ONetworkInterface::init() { odebug << "ONetworkInterface::init()" << oendl; - memset( &_ifr, 0, sizeof( struct ifreq ) ); if ( _sfd == -1 ) { @@ -269,19 +263,12 @@ void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) 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 ) @@ -314,18 +301,12 @@ void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) 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 @@ -546,9 +527,17 @@ void OWirelessNetworkInterface::buildInformation() 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 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,8 +1,7 @@ /* 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 @@ -197,9 +196,9 @@ class ONetworkInterface : public QObject 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 @@ -216,9 +215,9 @@ class ONetworkInterface : public QObject 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. */ |