summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-16 22:24:29 (UTC)
committer mickeyl <mickeyl>2003-04-16 22:24:29 (UTC)
commit0ac702419b3b8450b689e0ee2500f34b577f1a72 (patch) (unidiff)
treeef9e8101430c1429992b43a780bd68ca10daa77f
parent14db7d7d1ea99b8d9715f11daaa3ca9f4d8a554a (diff)
downloadopie-0ac702419b3b8450b689e0ee2500f34b577f1a72.zip
opie-0ac702419b3b8450b689e0ee2500f34b577f1a72.tar.gz
opie-0ac702419b3b8450b689e0ee2500f34b577f1a72.tar.bz2
add some missing APIs to ONetworkInterface
Diffstat (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
@@ -63,96 +63,102 @@ using namespace std;
63 63
64ONetwork* ONetwork::_instance = 0; 64ONetwork* ONetwork::_instance = 0;
65 65
66ONetwork::ONetwork() 66ONetwork::ONetwork()
67{ 67{
68 qDebug( "ONetwork::ONetwork()" ); 68 qDebug( "ONetwork::ONetwork()" );
69 synchronize(); 69 synchronize();
70} 70}
71 71
72void ONetwork::synchronize() 72void ONetwork::synchronize()
73{ 73{
74 // gather available interfaces by inspecting /proc/net/dev 74 // gather available interfaces by inspecting /proc/net/dev
75 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 75 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
76 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 76 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
77 77
78 _interfaces.clear(); 78 _interfaces.clear();
79 QString str; 79 QString str;
80 QFile f( "/proc/net/dev" ); 80 QFile f( "/proc/net/dev" );
81 bool hasFile = f.open( IO_ReadOnly ); 81 bool hasFile = f.open( IO_ReadOnly );
82 if ( !hasFile ) 82 if ( !hasFile )
83 { 83 {
84 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 84 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
85 return; 85 return;
86 } 86 }
87 QTextStream s( &f ); 87 QTextStream s( &f );
88 s.readLine(); 88 s.readLine();
89 s.readLine(); 89 s.readLine();
90 while ( !s.atEnd() ) 90 while ( !s.atEnd() )
91 { 91 {
92 s >> str; 92 s >> str;
93 str.truncate( str.find( ':' ) ); 93 str.truncate( str.find( ':' ) );
94 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 94 qDebug( "ONetwork: found interface '%s'", (const char*) str );
95 ONetworkInterface* iface; 95 ONetworkInterface* iface;
96 if ( isWirelessInterface( str ) ) 96 if ( isWirelessInterface( str ) )
97 { 97 {
98 iface = new OWirelessNetworkInterface( this, (const char*) str ); 98 iface = new OWirelessNetworkInterface( this, (const char*) str );
99 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 99 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
100 } 100 }
101 else 101 else
102 { 102 {
103 iface = new ONetworkInterface( this, (const char*) str ); 103 iface = new ONetworkInterface( this, (const char*) str );
104 } 104 }
105 _interfaces.insert( str, iface ); 105 _interfaces.insert( str, iface );
106 s.readLine(); 106 s.readLine();
107 } 107 }
108} 108}
109 109
110 110
111int ONetwork::count() const
112{
113 return _interfaces.count();
114}
115
116
111ONetworkInterface* ONetwork::interface( const QString& iface ) const 117ONetworkInterface* ONetwork::interface( const QString& iface ) const
112{ 118{
113 return _interfaces[iface]; 119 return _interfaces[iface];
114} 120}
115 121
116 122
117ONetwork* ONetwork::instance() 123ONetwork* ONetwork::instance()
118{ 124{
119 if ( !_instance ) _instance = new ONetwork(); 125 if ( !_instance ) _instance = new ONetwork();
120 return _instance; 126 return _instance;
121} 127}
122 128
123 129
124ONetwork::InterfaceIterator ONetwork::iterator() const 130ONetwork::InterfaceIterator ONetwork::iterator() const
125{ 131{
126 return ONetwork::InterfaceIterator( _interfaces ); 132 return ONetwork::InterfaceIterator( _interfaces );
127} 133}
128 134
129 135
130bool ONetwork::isWirelessInterface( const char* name ) const 136bool ONetwork::isWirelessInterface( const char* name ) const
131{ 137{
132 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 138 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
133 struct iwreq iwr; 139 struct iwreq iwr;
134 memset( &iwr, 0, sizeof( struct iwreq ) ); 140 memset( &iwr, 0, sizeof( struct iwreq ) );
135 strcpy( (char*) &iwr.ifr_name, name ); 141 strcpy( (char*) &iwr.ifr_name, name );
136 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 142 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
137 return result != -1; 143 return result != -1;
138} 144}
139 145
140/*====================================================================================== 146/*======================================================================================
141 * ONetworkInterface 147 * ONetworkInterface
142 *======================================================================================*/ 148 *======================================================================================*/
143 149
144ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 150ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
145 :QObject( parent, name ), 151 :QObject( parent, name ),
146 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 152 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
147{ 153{
148 qDebug( "ONetworkInterface::ONetworkInterface()" ); 154 qDebug( "ONetworkInterface::ONetworkInterface()" );
149 init(); 155 init();
150} 156}
151 157
152 158
153struct ifreq& ONetworkInterface::ifr() const 159struct ifreq& ONetworkInterface::ifr() const
154{ 160{
155 return _ifr; 161 return _ifr;
156} 162}
157 163
158 164
@@ -166,130 +172,163 @@ void ONetworkInterface::init()
166 { 172 {
167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); 173 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() );
168 return; 174 return;
169 } 175 }
170} 176}
171 177
172 178
173bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 179bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
174{ 180{
175 int result = ::ioctl( _sfd, call, &ifreq ); 181 int result = ::ioctl( _sfd, call, &ifreq );
176 if ( result == -1 ) 182 if ( result == -1 )
177 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 183 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
178 else 184 else
179 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); 185 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call );
180 return ( result != -1 ); 186 return ( result != -1 );
181} 187}
182 188
183 189
184bool ONetworkInterface::ioctl( int call ) const 190bool ONetworkInterface::ioctl( int call ) const
185{ 191{
186 strcpy( _ifr.ifr_name, name() ); 192 strcpy( _ifr.ifr_name, name() );
187 return ioctl( call, _ifr ); 193 return ioctl( call, _ifr );
188} 194}
189 195
190 196
191bool ONetworkInterface::isLoopback() const 197bool ONetworkInterface::isLoopback() const
192{ 198{
193 ioctl( SIOCGIFFLAGS ); 199 ioctl( SIOCGIFFLAGS );
194 return _ifr.ifr_flags & IFF_LOOPBACK; 200 return _ifr.ifr_flags & IFF_LOOPBACK;
195} 201}
196 202
197 203
198bool ONetworkInterface::setUp( bool b ) 204bool ONetworkInterface::setUp( bool b )
199{ 205{
200 ioctl( SIOCGIFFLAGS ); 206 ioctl( SIOCGIFFLAGS );
201 if ( b ) _ifr.ifr_flags |= IFF_UP; 207 if ( b ) _ifr.ifr_flags |= IFF_UP;
202 else _ifr.ifr_flags &= (~IFF_UP); 208 else _ifr.ifr_flags &= (~IFF_UP);
203 return ioctl( SIOCSIFFLAGS ); 209 return ioctl( SIOCSIFFLAGS );
204} 210}
205 211
206 212
207bool ONetworkInterface::isUp() const 213bool ONetworkInterface::isUp() const
208{ 214{
209 ioctl( SIOCGIFFLAGS ); 215 ioctl( SIOCGIFFLAGS );
210 return _ifr.ifr_flags & IFF_UP; 216 return _ifr.ifr_flags & IFF_UP;
211} 217}
212 218
213 219
220void 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
214QString ONetworkInterface::ipV4Address() const 230QString 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 ) );
221 } 237 }
222 else 238 else
223 return "<unknown>"; 239 return "<unknown>";
224} 240}
225 241
226 242
227void ONetworkInterface::setMacAddress( const OMacAddress& addr ) 243void ONetworkInterface::setMacAddress( const OMacAddress& addr )
228{ 244{
229 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 245 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
230 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); 246 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
231 ioctl( SIOCSIFHWADDR ); 247 ioctl( SIOCSIFHWADDR );
232} 248}
233 249
234 250
235OMacAddress ONetworkInterface::macAddress() const 251OMacAddress ONetworkInterface::macAddress() const
236{ 252{
237 if ( ioctl( SIOCGIFHWADDR ) ) 253 if ( ioctl( SIOCGIFHWADDR ) )
238 { 254 {
239 return OMacAddress( _ifr ); 255 return OMacAddress( _ifr );
240 } 256 }
241 else 257 else
242 { 258 {
243 return OMacAddress::unknown; 259 return OMacAddress::unknown;
244 } 260 }
245} 261}
246 262
247 263
264void 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
274QString 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
248int ONetworkInterface::dataLinkType() const 287int ONetworkInterface::dataLinkType() const
249{ 288{
250 if ( ioctl( SIOCGIFHWADDR ) ) 289 if ( ioctl( SIOCGIFHWADDR ) )
251 { 290 {
252 return _ifr.ifr_hwaddr.sa_family; 291 return _ifr.ifr_hwaddr.sa_family;
253 } 292 }
254 else 293 else
255 { 294 {
256 return -1; 295 return -1;
257 } 296 }
258} 297}
259 298
260 299
261void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 300void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
262{ 301{
263 _mon = m; 302 _mon = m;
264 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); 303 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() );
265} 304}
266 305
267 306
268OMonitoringInterface* ONetworkInterface::monitoring() const 307OMonitoringInterface* ONetworkInterface::monitoring() const
269{ 308{
270 return _mon; 309 return _mon;
271} 310}
272 311
273 312
274ONetworkInterface::~ONetworkInterface() 313ONetworkInterface::~ONetworkInterface()
275{ 314{
276 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 315 qDebug( "ONetworkInterface::~ONetworkInterface()" );
277 if ( _sfd != -1 ) ::close( _sfd ); 316 if ( _sfd != -1 ) ::close( _sfd );
278} 317}
279 318
280 319
281bool ONetworkInterface::setPromiscuousMode( bool b ) 320bool ONetworkInterface::setPromiscuousMode( bool b )
282{ 321{
283 ioctl( SIOCGIFFLAGS ); 322 ioctl( SIOCGIFFLAGS );
284 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 323 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
285 else _ifr.ifr_flags &= (~IFF_PROMISC); 324 else _ifr.ifr_flags &= (~IFF_PROMISC);
286 return ioctl( SIOCSIFFLAGS ); 325 return ioctl( SIOCSIFFLAGS );
287} 326}
288 327
289 328
290bool ONetworkInterface::promiscuousMode() const 329bool ONetworkInterface::promiscuousMode() const
291{ 330{
292 ioctl( SIOCGIFFLAGS ); 331 ioctl( SIOCGIFFLAGS );
293 return _ifr.ifr_flags & IFF_PROMISC; 332 return _ifr.ifr_flags & IFF_PROMISC;
294} 333}
295 334
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
@@ -11,238 +11,259 @@
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef ONETWORK_H 34#ifndef ONETWORK_H
35#define ONETWORK_H 35#define ONETWORK_H
36 36
37/* QT */ 37/* QT */
38 38
39#include <qvaluelist.h> 39#include <qvaluelist.h>
40#include <qdict.h> 40#include <qdict.h>
41#include <qmap.h> 41#include <qmap.h>
42#include <qobject.h> 42#include <qobject.h>
43#include <qhostaddress.h> 43#include <qhostaddress.h>
44 44
45/* OPIE */ 45/* OPIE */
46 46
47#include <opie2/onetutils.h> 47#include <opie2/onetutils.h>
48 48
49#ifndef IFNAMSIZ 49#ifndef IFNAMSIZ
50#define IFNAMSIZ 16 50#define IFNAMSIZ 16
51#endif 51#endif
52#ifndef IW_MAX_PRIV_DEF 52#ifndef IW_MAX_PRIV_DEF
53#define IW_MAX_PRIV_DEF 128 53#define IW_MAX_PRIV_DEF 128
54#endif 54#endif
55 55
56// ML: Yeah, I hate to include kernel headers, but it's necessary here 56// ML: Yeah, I hate to include kernel headers, but it's necessary here
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>
63#define _LINUX_IF_H 63#define _LINUX_IF_H
64#include <linux/wireless.h> 64#include <linux/wireless.h>
65 65
66class ONetworkInterface; 66class ONetworkInterface;
67class OWirelessNetworkInterface; 67class OWirelessNetworkInterface;
68class OChannelHopper; 68class OChannelHopper;
69class OMonitoringInterface; 69class OMonitoringInterface;
70 70
71/*====================================================================================== 71/*======================================================================================
72 * ONetwork 72 * ONetwork
73 *======================================================================================*/ 73 *======================================================================================*/
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 */
81class ONetwork : public QObject 81class ONetwork : public QObject
82{ 82{
83 Q_OBJECT 83 Q_OBJECT
84 84
85 public: 85 public:
86 typedef QDict<ONetworkInterface> InterfaceMap; 86 typedef QDict<ONetworkInterface> InterfaceMap;
87 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 87 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
88 88
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 */
93 static ONetwork* instance(); 97 static ONetwork* instance();
94 /** 98 /**
95 * @returns an iterator usable for iterating through all network interfaces. 99 * @returns an iterator usable for iterating through all network interfaces.
96 */ 100 */
97 InterfaceIterator iterator() const; 101 InterfaceIterator iterator() const;
98 /** 102 /**
99 * @returns true, if the @p interface supports the wireless extension protocol. 103 * @returns true, if the @p interface supports the wireless extension protocol.
100 */ 104 */
101 // FIXME QString? -zecke 105 // FIXME QString? -zecke
102 bool isWirelessInterface( const char* interface ) const; 106 bool isWirelessInterface( const char* interface ) const;
103 /** 107 /**
104 * @returns a pointer to the @ref ONetworkInterface object for the specified @p interface or 0, if not found 108 * @returns a pointer to the @ref ONetworkInterface object for the specified @p interface or 0, if not found
105 * @see ONetworkInterface 109 * @see ONetworkInterface
106 */ 110 */
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:
115 static ONetwork* _instance; 124 static ONetwork* _instance;
116 InterfaceMap _interfaces; 125 InterfaceMap _interfaces;
117}; 126};
118 127
119 128
120/*====================================================================================== 129/*======================================================================================
121 * ONetworkInterface 130 * ONetworkInterface
122 *======================================================================================*/ 131 *======================================================================================*/
123 132
124/** 133/**
125 * @brief A network interface wrapper. 134 * @brief A network interface wrapper.
126 * 135 *
127 * This class provides a wrapper for a network interface. All the cumbersume details of 136 * This class provides a wrapper for a network interface. All the cumbersume details of
128 * Linux ioctls are hidden under a convenient high-level interface. 137 * Linux ioctls are hidden under a convenient high-level interface.
129 * @warning Most of the setting methods contained in this class require the appropriate 138 * @warning Most of the setting methods contained in this class require the appropriate
130 * process permissions to work. 139 * process permissions to work.
131 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 140 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
132 */ 141 */
133class ONetworkInterface : public QObject 142class ONetworkInterface : public QObject
134{ 143{
135 friend class OMonitoringInterface; 144 friend class OMonitoringInterface;
136 friend class OCiscoMonitoringInterface; 145 friend class OCiscoMonitoringInterface;
137 friend class OWlanNGMonitoringInterface; 146 friend class OWlanNGMonitoringInterface;
138 friend class OHostAPMonitoringInterface; 147 friend class OHostAPMonitoringInterface;
139 friend class OOrinocoMonitoringInterface; 148 friend class OOrinocoMonitoringInterface;
140 149
141 public: 150 public:
142 /** 151 /**
143 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, 152 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself,
144 * but access them via @ref ONetwork::interface(). 153 * but access them via @ref ONetwork::interface().
145 */ 154 */
146 ONetworkInterface( QObject* parent, const char* name ); 155 ONetworkInterface( QObject* parent, const char* name );
147 /** 156 /**
148 * Destructor. 157 * Destructor.
149 */ 158 */
150 virtual ~ONetworkInterface(); 159 virtual ~ONetworkInterface();
151 /** 160 /**
152 * Associates a @a monitoring interface with this network interface. 161 * Associates a @a monitoring interface with this network interface.
153 * @note This is currently only useful with @ref OWirelessNetworkInterface objects. 162 * @note This is currently only useful with @ref OWirelessNetworkInterface objects.
154 */ 163 */
155 void setMonitoring( OMonitoringInterface* monitoring ); 164 void setMonitoring( OMonitoringInterface* monitoring );
156 /** 165 /**
157 * @returns the currently associated monitoring interface or 0, if no monitoring is associated. 166 * @returns the currently associated monitoring interface or 0, if no monitoring is associated.
158 */ 167 */
159 OMonitoringInterface* monitoring() const; 168 OMonitoringInterface* monitoring() const;
160 /** 169 /**
161 * Setting an interface to promiscuous mode enables the device to receive 170 * Setting an interface to promiscuous mode enables the device to receive
162 * all packets on the shared medium - as opposed to packets which are addressed to this interface. 171 * all packets on the shared medium - as opposed to packets which are addressed to this interface.
163 */ 172 */
164 bool setPromiscuousMode( bool ); 173 bool setPromiscuousMode( bool );
165 /** 174 /**
166 * @returns true if the interface is set to promiscuous mode. 175 * @returns true if the interface is set to promiscuous mode.
167 */ 176 */
168 bool promiscuousMode() const; 177 bool promiscuousMode() const;
169 /** 178 /**
170 * Setting an interface to up enables it to receive packets. 179 * Setting an interface to up enables it to receive packets.
171 */ 180 */
172 bool setUp( bool ); 181 bool setUp( bool );
173 /** 182 /**
174 * @returns true if the interface is up. 183 * @returns true if the interface is up.
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.
192 * @warning This is not supported by all drivers. 205 * @warning This is not supported by all drivers.
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 */
203 int dataLinkType() const; 224 int dataLinkType() const;
204 225
205 protected: 226 protected:
206 const int _sfd; 227 const int _sfd;
207 mutable ifreq _ifr; 228 mutable ifreq _ifr;
208 OMonitoringInterface* _mon; 229 OMonitoringInterface* _mon;
209 230
210 protected: 231 protected:
211 struct ifreq& ifr() const; 232 struct ifreq& ifr() const;
212 virtual void init(); 233 virtual void init();
213 bool ioctl( int call ) const; 234 bool ioctl( int call ) const;
214 bool ioctl( int call, struct ifreq& ) const; 235 bool ioctl( int call, struct ifreq& ) const;
215}; 236};
216 237
217/*====================================================================================== 238/*======================================================================================
218 * OChannelHopper 239 * OChannelHopper
219 *======================================================================================*/ 240 *======================================================================================*/
220 241
221/** 242/**
222 * @brief A radio frequency channel hopper. 243 * @brief A radio frequency channel hopper.
223 * 244 *
224 * This class provides a channel hopper for radio frequencies. A channel hopper frequently 245 * This class provides a channel hopper for radio frequencies. A channel hopper frequently
225 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. 246 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface.
226 * This is necessary when in monitoring mode and scanning for other devices, because 247 * This is necessary when in monitoring mode and scanning for other devices, because
227 * the radio frequency hardware can only detect packets sent on the same frequency. 248 * the radio frequency hardware can only detect packets sent on the same frequency.
228 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 249 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
229 */ 250 */
230class OChannelHopper : public QObject 251class OChannelHopper : public QObject
231{ 252{
232 Q_OBJECT 253 Q_OBJECT
233 254
234 public: 255 public:
235 OChannelHopper( OWirelessNetworkInterface* ); 256 OChannelHopper( OWirelessNetworkInterface* );
236 virtual ~OChannelHopper(); 257 virtual ~OChannelHopper();
237 bool isActive() const; 258 bool isActive() const;
238 int channel() const; 259 int channel() const;
239 virtual void timerEvent( QTimerEvent* ); 260 virtual void timerEvent( QTimerEvent* );
240 void setInterval( int ); 261 void setInterval( int );
241 int interval() const; 262 int interval() const;
242 263
243 signals: 264 signals:
244 void hopped( int ); 265 void hopped( int );
245 266
246 private: 267 private:
247 OWirelessNetworkInterface* _iface; 268 OWirelessNetworkInterface* _iface;
248 int _interval; 269 int _interval;