summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp39
-rw-r--r--libopie2/opienet/onetwork.h49
2 files changed, 74 insertions, 14 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
@@ -110,2 +110,8 @@ void ONetwork::synchronize()
+int ONetwork::count() const
+{
+ return _interfaces.count();
+}
+
+
ONetworkInterface* ONetwork::interface( const QString& iface ) const
@@ -213,2 +219,12 @@ 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
@@ -247,2 +263,25 @@ 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 ) )
+ {
+ 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
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
@@ -58,4 +58,4 @@
// 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
@@ -75,5 +75,5 @@ class OMonitoringInterface;
/**
- * @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>
@@ -90,2 +90,6 @@ class ONetwork : public QObject
/**
+ * @returns the number of available interfaces
+ */
+ int count() const;
+ /**
* @returns a pointer to the (one and only) @ref ONetwork instance.
@@ -108,2 +112,8 @@ class ONetwork : public QObject
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();
@@ -111,3 +121,2 @@ class ONetwork : public QObject
ONetwork();
- void synchronize();
@@ -176,3 +185,3 @@ class ONetworkInterface : public QObject
bool isUp() const;
- /*
+ /**
* @returns true if the interface is a loopback interface.
@@ -180,3 +189,3 @@ class ONetworkInterface : public QObject
bool isLoopback() const;
- /*
+ /**
* @returns true if the interface is featuring supports the wireless extension protocol.
@@ -184,7 +193,11 @@ class ONetworkInterface : public QObject
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.
@@ -194,8 +207,16 @@ class ONetworkInterface : public QObject
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.