summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2003-04-16 22:24:29 (UTC)
committer mickeyl <mickeyl>2003-04-16 22:24:29 (UTC)
commit0ac702419b3b8450b689e0ee2500f34b577f1a72 (patch) (side-by-side diff)
treeef9e8101430c1429992b43a780bd68ca10daa77f /libopie2
parent14db7d7d1ea99b8d9715f11daaa3ca9f4d8a554a (diff)
downloadopie-0ac702419b3b8450b689e0ee2500f34b577f1a72.zip
opie-0ac702419b3b8450b689e0ee2500f34b577f1a72.tar.gz
opie-0ac702419b3b8450b689e0ee2500f34b577f1a72.tar.bz2
add some missing APIs to ONetworkInterface
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp41
-rw-r--r--libopie2/opienet/onetwork.h49
2 files changed, 75 insertions, 15 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index f0094c7..be2736a 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -105,12 +105,18 @@ void ONetwork::synchronize()
_interfaces.insert( str, iface );
s.readLine();
}
}
+int ONetwork::count() const
+{
+ return _interfaces.count();
+}
+
+
ONetworkInterface* ONetwork::interface( const QString& iface ) const
{
return _interfaces[iface];
}
@@ -208,17 +214,27 @@ 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
{
if ( ioctl( SIOCGIFADDR ) )
{
- struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
+ struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
//FIXME: Use QHostAddress here
return QString( inet_ntoa( sa->sin_addr ) );
}
else
return "<unknown>";
}
@@ -242,12 +258,35 @@ OMacAddress ONetworkInterface::macAddress() const
{
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
+{
+ 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>";
+}
+
+
int ONetworkInterface::dataLinkType() const
{
if ( ioctl( SIOCGIFHWADDR ) )
{
return _ifr.ifr_hwaddr.sa_family;
}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index db8e702..2348bbc 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -53,14 +53,14 @@
#define IW_MAX_PRIV_DEF 128
#endif
// ML: Yeah, I hate to include kernel headers, but it's necessary here
// ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h>
// ML: which conflicts with the user header <net/if.h>
-// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h>
-// ML: I will drop Jean an mail on that subject
+// ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h>
+// ML: I will drop Jean a mail on that subject
#include <net/if.h>
#define _LINUX_IF_H
#include <linux/wireless.h>
class ONetworkInterface;
@@ -70,27 +70,31 @@ class OMonitoringInterface;
/*======================================================================================
* ONetwork
*======================================================================================*/
/**
- * @brief A container class for all network devices.
+ * @brief A container class for all network interfaces
*
- * This class provides access to all available network devices of your computer.
+ * This class provides access to all available network interfaces of your computer.
* @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
*/
class ONetwork : public QObject
{
Q_OBJECT
public:
typedef QDict<ONetworkInterface> InterfaceMap;
typedef QDictIterator<ONetworkInterface> InterfaceIterator;
public:
/**
+ * @returns the number of available interfaces
+ */
+ int count() const;
+ /**
* @returns a pointer to the (one and only) @ref ONetwork instance.
*/
static ONetwork* instance();
/**
* @returns an iterator usable for iterating through all network interfaces.
*/
@@ -103,16 +107,21 @@ class ONetwork : public QObject
/**
* @returns a pointer to the @ref ONetworkInterface object for the specified @p interface or 0, if not found
* @see ONetworkInterface
*/
// FIXME: const QString& is prefered over QString!!! -zecke
ONetworkInterface* interface( const QString& interface ) const;
+ /**
+ * @internal Rebuild the internal interface database
+ * @note Sometimes it might be useful to call this from client code,
+ * e.g. after cardctl insert
+ */
+ void synchronize();
protected:
ONetwork();
- void synchronize();
private:
static ONetwork* _instance;
InterfaceMap _interfaces;
};
@@ -171,36 +180,48 @@ class ONetworkInterface : public QObject
*/
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;
- /*
- * @returns the IPv4 address associated with this interface.
+ /**
+ * Associate the IP address @ addr with the interface.
+ */
+ void setIPV4Address( const QHostAddress& addr );
+ /**
+ * @returns the IPv4 address associated with the interface.
*/
QString 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.
* @warning This is not supported by all drivers.
*/
void setMacAddress( const OMacAddress& addr );
- /*
- * @returns the MAC address associated with this interface.
+ /**
+ * @returns the MAC address associated with the interface.
*/
OMacAddress macAddress() const;
- /*
- * @returns the data link type currently associated with this interface.
+ /**
+ * Associate the IPv4 @a netmask with the interface.
+ */
+ void setIPV4Netmask( const QHostAddress& netmask );
+ /**
+ * @returns the IPv4 netmask associated with the interface.
+ */
+ QString ipV4Netmask() const;
+ /**
+ * @returns the data link type currently associated with the interface.
* @see #include <net/if_arp.h> for possible values.
*/
int dataLinkType() const;
protected:
const int _sfd;