-rw-r--r-- | libopie2/opienet/onetwork.cpp | 41 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 49 |
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 | |||
@@ -109,4 +109,10 @@ void ONetwork::synchronize() | |||
109 | 109 | ||
110 | 110 | ||
111 | int ONetwork::count() const | ||
112 | { | ||
113 | return _interfaces.count(); | ||
114 | } | ||
115 | |||
116 | |||
111 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 117 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
112 | { | 118 | { |
@@ -212,9 +218,19 @@ bool ONetworkInterface::isUp() const | |||
212 | 218 | ||
213 | 219 | ||
220 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | ||
221 | { | ||
222 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | ||
223 | sa->sin_family = AF_INET; | ||
224 | sa->sin_port = 0; | ||
225 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | ||
226 | ioctl( SIOCSIFADDR ); | ||
227 | } | ||
228 | |||
229 | |||
214 | QString ONetworkInterface::ipV4Address() const | 230 | QString ONetworkInterface::ipV4Address() const |
215 | { | 231 | { |
216 | if ( ioctl( SIOCGIFADDR ) ) | 232 | if ( ioctl( SIOCGIFADDR ) ) |
217 | { | 233 | { |
218 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 234 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
219 | //FIXME: Use QHostAddress here | 235 | //FIXME: Use QHostAddress here |
220 | return QString( inet_ntoa( sa->sin_addr ) ); | 236 | return QString( inet_ntoa( sa->sin_addr ) ); |
@@ -246,4 +262,27 @@ OMacAddress ONetworkInterface::macAddress() const | |||
246 | 262 | ||
247 | 263 | ||
264 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | ||
265 | { | ||
266 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | ||
267 | sa->sin_family = AF_INET; | ||
268 | sa->sin_port = 0; | ||
269 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | ||
270 | ioctl( SIOCSIFNETMASK ); | ||
271 | } | ||
272 | |||
273 | |||
274 | QString ONetworkInterface::ipV4Netmask() const | ||
275 | { | ||
276 | if ( ioctl( SIOCGIFNETMASK ) ) | ||
277 | { | ||
278 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | ||
279 | //FIXME: Use QHostAddress here | ||
280 | return QString( inet_ntoa( sa->sin_addr ) ); | ||
281 | } | ||
282 | else | ||
283 | return "<unknown>"; | ||
284 | } | ||
285 | |||
286 | |||
248 | int ONetworkInterface::dataLinkType() const | 287 | int ONetworkInterface::dataLinkType() const |
249 | { | 288 | { |
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 | |||
@@ -57,6 +57,6 @@ | |||
57 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> | 57 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> |
58 | // ML: which conflicts with the user header <net/if.h> | 58 | // ML: which conflicts with the user header <net/if.h> |
59 | // ML: We really a user header for the Wireless Extensions, something like <net/wireless.h> | 59 | // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> |
60 | // ML: I will drop Jean an mail on that subject | 60 | // ML: I will drop Jean a mail on that subject |
61 | 61 | ||
62 | #include <net/if.h> | 62 | #include <net/if.h> |
@@ -74,7 +74,7 @@ class OMonitoringInterface; | |||
74 | 74 | ||
75 | /** | 75 | /** |
76 | * @brief A container class for all network devices. | 76 | * @brief A container class for all network interfaces |
77 | * | 77 | * |
78 | * This class provides access to all available network devices of your computer. | 78 | * This class provides access to all available network interfaces of your computer. |
79 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 79 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
80 | */ | 80 | */ |
@@ -89,4 +89,8 @@ class ONetwork : public QObject | |||
89 | public: | 89 | public: |
90 | /** | 90 | /** |
91 | * @returns the number of available interfaces | ||
92 | */ | ||
93 | int count() const; | ||
94 | /** | ||
91 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 95 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
92 | */ | 96 | */ |
@@ -107,8 +111,13 @@ class ONetwork : public QObject | |||
107 | // FIXME: const QString& is prefered over QString!!! -zecke | 111 | // FIXME: const QString& is prefered over QString!!! -zecke |
108 | ONetworkInterface* interface( const QString& interface ) const; | 112 | ONetworkInterface* interface( const QString& interface ) const; |
113 | /** | ||
114 | * @internal Rebuild the internal interface database | ||
115 | * @note Sometimes it might be useful to call this from client code, | ||
116 | * e.g. after cardctl insert | ||
117 | */ | ||
118 | void synchronize(); | ||
109 | 119 | ||
110 | protected: | 120 | protected: |
111 | ONetwork(); | 121 | ONetwork(); |
112 | void synchronize(); | ||
113 | 122 | ||
114 | private: | 123 | private: |
@@ -175,17 +184,21 @@ class ONetworkInterface : public QObject | |||
175 | */ | 184 | */ |
176 | bool isUp() const; | 185 | bool isUp() const; |
177 | /* | 186 | /** |
178 | * @returns true if the interface is a loopback interface. | 187 | * @returns true if the interface is a loopback interface. |
179 | */ | 188 | */ |
180 | bool isLoopback() const; | 189 | bool isLoopback() const; |
181 | /* | 190 | /** |
182 | * @returns true if the interface is featuring supports the wireless extension protocol. | 191 | * @returns true if the interface is featuring supports the wireless extension protocol. |
183 | */ | 192 | */ |
184 | bool isWireless() const; | 193 | bool isWireless() const; |
185 | /* | 194 | /** |
186 | * @returns the IPv4 address associated with this interface. | 195 | * Associate the IP address @ addr with the interface. |
196 | */ | ||
197 | void setIPV4Address( const QHostAddress& addr ); | ||
198 | /** | ||
199 | * @returns the IPv4 address associated with the interface. | ||
187 | */ | 200 | */ |
188 | QString ipV4Address() const; | 201 | QString ipV4Address() const; |
189 | /* | 202 | /** |
190 | * Associate the MAC address @a addr with the interface. | 203 | * Associate the MAC address @a addr with the interface. |
191 | * @note It can be necessary to shut down the interface prior to calling this method. | 204 | * @note It can be necessary to shut down the interface prior to calling this method. |
@@ -193,10 +206,18 @@ class ONetworkInterface : public QObject | |||
193 | */ | 206 | */ |
194 | void setMacAddress( const OMacAddress& addr ); | 207 | void setMacAddress( const OMacAddress& addr ); |
195 | /* | 208 | /** |
196 | * @returns the MAC address associated with this interface. | 209 | * @returns the MAC address associated with the interface. |
197 | */ | 210 | */ |
198 | OMacAddress macAddress() const; | 211 | OMacAddress macAddress() const; |
199 | /* | 212 | /** |
200 | * @returns the data link type currently associated with this interface. | 213 | * Associate the IPv4 @a netmask with the interface. |
214 | */ | ||
215 | void setIPV4Netmask( const QHostAddress& netmask ); | ||
216 | /** | ||
217 | * @returns the IPv4 netmask associated with the interface. | ||
218 | */ | ||
219 | QString ipV4Netmask() const; | ||
220 | /** | ||
221 | * @returns the data link type currently associated with the interface. | ||
201 | * @see #include <net/if_arp.h> for possible values. | 222 | * @see #include <net/if_arp.h> for possible values. |
202 | */ | 223 | */ |