author | mickeyl <mickeyl> | 2004-02-24 22:56:24 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-02-24 22:56:24 (UTC) |
commit | 96ba6fcf27c785282c3fe05557df8b384df06852 (patch) (unidiff) | |
tree | 9b25648f8518c8d152d4774ac05f81548828f3d5 /libopie2/opienet | |
parent | a1a6a1013eae9a4ca4607f2d656c98821a30f431 (diff) | |
download | opie-96ba6fcf27c785282c3fe05557df8b384df06852.zip opie-96ba6fcf27c785282c3fe05557df8b384df06852.tar.gz opie-96ba6fcf27c785282c3fe05557df8b384df06852.tar.bz2 |
API extension: ONetwork::isPresent( const char* name )
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 11 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 4 |
2 files changed, 15 insertions, 0 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 915814d..e5b091f 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -51,192 +51,203 @@ | |||
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #include <sys/types.h> | 52 | #include <sys/types.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #include <linux/sockios.h> | 54 | #include <linux/sockios.h> |
55 | #include <net/if_arp.h> | 55 | #include <net/if_arp.h> |
56 | #include <stdarg.h> | 56 | #include <stdarg.h> |
57 | 57 | ||
58 | #ifndef NODEBUG | 58 | #ifndef NODEBUG |
59 | #include <opie2/odebugmapper.h> | 59 | #include <opie2/odebugmapper.h> |
60 | DebugMapper* debugmapper = new DebugMapper(); | 60 | DebugMapper* debugmapper = new DebugMapper(); |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | /*====================================================================================== | 63 | /*====================================================================================== |
64 | * ONetwork | 64 | * ONetwork |
65 | *======================================================================================*/ | 65 | *======================================================================================*/ |
66 | 66 | ||
67 | ONetwork* ONetwork::_instance = 0; | 67 | ONetwork* ONetwork::_instance = 0; |
68 | 68 | ||
69 | ONetwork::ONetwork() | 69 | ONetwork::ONetwork() |
70 | { | 70 | { |
71 | odebug << "ONetwork::ONetwork()" << oendl; | 71 | odebug << "ONetwork::ONetwork()" << oendl; |
72 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; | 72 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; |
73 | synchronize(); | 73 | synchronize(); |
74 | } | 74 | } |
75 | 75 | ||
76 | void ONetwork::synchronize() | 76 | void ONetwork::synchronize() |
77 | { | 77 | { |
78 | // gather available interfaces by inspecting /proc/net/dev | 78 | // gather available interfaces by inspecting /proc/net/dev |
79 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 79 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
80 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 80 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
81 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | 81 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev |
82 | 82 | ||
83 | _interfaces.clear(); | 83 | _interfaces.clear(); |
84 | QString str; | 84 | QString str; |
85 | QFile f( "/proc/net/dev" ); | 85 | QFile f( "/proc/net/dev" ); |
86 | bool hasFile = f.open( IO_ReadOnly ); | 86 | bool hasFile = f.open( IO_ReadOnly ); |
87 | if ( !hasFile ) | 87 | if ( !hasFile ) |
88 | { | 88 | { |
89 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; | 89 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; |
90 | return; | 90 | return; |
91 | } | 91 | } |
92 | QTextStream s( &f ); | 92 | QTextStream s( &f ); |
93 | s.readLine(); | 93 | s.readLine(); |
94 | s.readLine(); | 94 | s.readLine(); |
95 | while ( !s.atEnd() ) | 95 | while ( !s.atEnd() ) |
96 | { | 96 | { |
97 | s >> str; | 97 | s >> str; |
98 | str.truncate( str.find( ':' ) ); | 98 | str.truncate( str.find( ':' ) ); |
99 | odebug << "ONetwork: found interface '" << str << "'" << oendl; | 99 | odebug << "ONetwork: found interface '" << str << "'" << oendl; |
100 | ONetworkInterface* iface; | 100 | ONetworkInterface* iface; |
101 | if ( isWirelessInterface( str ) ) | 101 | if ( isWirelessInterface( str ) ) |
102 | { | 102 | { |
103 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 103 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
104 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; | 104 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; |
105 | } | 105 | } |
106 | else | 106 | else |
107 | { | 107 | { |
108 | iface = new ONetworkInterface( this, (const char*) str ); | 108 | iface = new ONetworkInterface( this, (const char*) str ); |
109 | } | 109 | } |
110 | _interfaces.insert( str, iface ); | 110 | _interfaces.insert( str, iface ); |
111 | s.readLine(); | 111 | s.readLine(); |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | short ONetwork::wirelessExtensionVersion() | 116 | short ONetwork::wirelessExtensionVersion() |
117 | { | 117 | { |
118 | return WIRELESS_EXT; | 118 | return WIRELESS_EXT; |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | int ONetwork::count() const | 122 | int ONetwork::count() const |
123 | { | 123 | { |
124 | return _interfaces.count(); | 124 | return _interfaces.count(); |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 128 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
129 | { | 129 | { |
130 | return _interfaces[iface]; | 130 | return _interfaces[iface]; |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | ONetwork* ONetwork::instance() | 134 | ONetwork* ONetwork::instance() |
135 | { | 135 | { |
136 | if ( !_instance ) _instance = new ONetwork(); | 136 | if ( !_instance ) _instance = new ONetwork(); |
137 | return _instance; | 137 | return _instance; |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | ONetwork::InterfaceIterator ONetwork::iterator() const | 141 | ONetwork::InterfaceIterator ONetwork::iterator() const |
142 | { | 142 | { |
143 | return ONetwork::InterfaceIterator( _interfaces ); | 143 | return ONetwork::InterfaceIterator( _interfaces ); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | bool ONetwork::isPresent( const char* name ) const | ||
148 | { | ||
149 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | ||
150 | struct ifreq ifr; | ||
151 | memset( &ifr, 0, sizeof( struct ifreq ) ); | ||
152 | strcpy( (char*) &ifr.ifr_name, name ); | ||
153 | int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); | ||
154 | return result != -1; | ||
155 | } | ||
156 | |||
157 | |||
147 | bool ONetwork::isWirelessInterface( const char* name ) const | 158 | bool ONetwork::isWirelessInterface( const char* name ) const |
148 | { | 159 | { |
149 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 160 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
150 | struct iwreq iwr; | 161 | struct iwreq iwr; |
151 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 162 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
152 | strcpy( (char*) &iwr.ifr_name, name ); | 163 | strcpy( (char*) &iwr.ifr_name, name ); |
153 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 164 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
154 | return result != -1; | 165 | return result != -1; |
155 | } | 166 | } |
156 | 167 | ||
157 | /*====================================================================================== | 168 | /*====================================================================================== |
158 | * ONetworkInterface | 169 | * ONetworkInterface |
159 | *======================================================================================*/ | 170 | *======================================================================================*/ |
160 | 171 | ||
161 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 172 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
162 | :QObject( parent, name ), | 173 | :QObject( parent, name ), |
163 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 174 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
164 | { | 175 | { |
165 | odebug << "ONetworkInterface::ONetworkInterface()" << oendl; | 176 | odebug << "ONetworkInterface::ONetworkInterface()" << oendl; |
166 | init(); | 177 | init(); |
167 | } | 178 | } |
168 | 179 | ||
169 | 180 | ||
170 | struct ifreq& ONetworkInterface::ifr() const | 181 | struct ifreq& ONetworkInterface::ifr() const |
171 | { | 182 | { |
172 | return _ifr; | 183 | return _ifr; |
173 | } | 184 | } |
174 | 185 | ||
175 | 186 | ||
176 | void ONetworkInterface::init() | 187 | void ONetworkInterface::init() |
177 | { | 188 | { |
178 | odebug << "ONetworkInterface::init()" << oendl; | 189 | odebug << "ONetworkInterface::init()" << oendl; |
179 | 190 | ||
180 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 191 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
181 | 192 | ||
182 | if ( _sfd == -1 ) | 193 | if ( _sfd == -1 ) |
183 | { | 194 | { |
184 | odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; | 195 | odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; |
185 | return; | 196 | return; |
186 | } | 197 | } |
187 | } | 198 | } |
188 | 199 | ||
189 | 200 | ||
190 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 201 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
191 | { | 202 | { |
192 | #ifndef NODEBUG | 203 | #ifndef NODEBUG |
193 | int result = ::ioctl( _sfd, call, &ifreq ); | 204 | int result = ::ioctl( _sfd, call, &ifreq ); |
194 | if ( result == -1 ) | 205 | if ( result == -1 ) |
195 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) | 206 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
196 | << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | 207 | << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
197 | else | 208 | else |
198 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) | 209 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
199 | << "' - Status: Ok." << oendl; | 210 | << "' - Status: Ok." << oendl; |
200 | return ( result != -1 ); | 211 | return ( result != -1 ); |
201 | #else | 212 | #else |
202 | return ::ioctl( _sfd, call, &ifreq ) != -1; | 213 | return ::ioctl( _sfd, call, &ifreq ) != -1; |
203 | #endif | 214 | #endif |
204 | } | 215 | } |
205 | 216 | ||
206 | 217 | ||
207 | bool ONetworkInterface::ioctl( int call ) const | 218 | bool ONetworkInterface::ioctl( int call ) const |
208 | { | 219 | { |
209 | strcpy( _ifr.ifr_name, name() ); | 220 | strcpy( _ifr.ifr_name, name() ); |
210 | return ioctl( call, _ifr ); | 221 | return ioctl( call, _ifr ); |
211 | } | 222 | } |
212 | 223 | ||
213 | 224 | ||
214 | bool ONetworkInterface::isLoopback() const | 225 | bool ONetworkInterface::isLoopback() const |
215 | { | 226 | { |
216 | ioctl( SIOCGIFFLAGS ); | 227 | ioctl( SIOCGIFFLAGS ); |
217 | return _ifr.ifr_flags & IFF_LOOPBACK; | 228 | return _ifr.ifr_flags & IFF_LOOPBACK; |
218 | } | 229 | } |
219 | 230 | ||
220 | 231 | ||
221 | bool ONetworkInterface::setUp( bool b ) | 232 | bool ONetworkInterface::setUp( bool b ) |
222 | { | 233 | { |
223 | ioctl( SIOCGIFFLAGS ); | 234 | ioctl( SIOCGIFFLAGS ); |
224 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 235 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
225 | else _ifr.ifr_flags &= (~IFF_UP); | 236 | else _ifr.ifr_flags &= (~IFF_UP); |
226 | return ioctl( SIOCSIFFLAGS ); | 237 | return ioctl( SIOCSIFFLAGS ); |
227 | } | 238 | } |
228 | 239 | ||
229 | 240 | ||
230 | bool ONetworkInterface::isUp() const | 241 | bool ONetworkInterface::isUp() const |
231 | { | 242 | { |
232 | ioctl( SIOCGIFFLAGS ); | 243 | ioctl( SIOCGIFFLAGS ); |
233 | return _ifr.ifr_flags & IFF_UP; | 244 | return _ifr.ifr_flags & IFF_UP; |
234 | } | 245 | } |
235 | 246 | ||
236 | 247 | ||
237 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | 248 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) |
238 | { | 249 | { |
239 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 250 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
240 | sa->sin_family = AF_INET; | 251 | sa->sin_family = AF_INET; |
241 | sa->sin_port = 0; | 252 | sa->sin_port = 0; |
242 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 253 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 0a51108..93b129f 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -1,192 +1,196 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer | 3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer |
4 | =. <mickey@Vanille.de> | 4 | =. <mickey@Vanille.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef ONETWORK_H | 31 | #ifndef ONETWORK_H |
32 | #define ONETWORK_H | 32 | #define ONETWORK_H |
33 | 33 | ||
34 | #if !defined( OPIE_WE_VERSION ) | 34 | #if !defined( OPIE_WE_VERSION ) |
35 | #error Need to define a wireless extension version to build against! | 35 | #error Need to define a wireless extension version to build against! |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #if OPIE_WE_VERSION == 15 | 38 | #if OPIE_WE_VERSION == 15 |
39 | #include "wireless.15.h" | 39 | #include "wireless.15.h" |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #if OPIE_WE_VERSION == 16 | 42 | #if OPIE_WE_VERSION == 16 |
43 | #include "wireless.16.h" | 43 | #include "wireless.16.h" |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | /* OPIE */ | 46 | /* OPIE */ |
47 | 47 | ||
48 | #include <opie2/onetutils.h> | 48 | #include <opie2/onetutils.h> |
49 | #include <opie2/ostation.h> | 49 | #include <opie2/ostation.h> |
50 | 50 | ||
51 | /* QT */ | 51 | /* QT */ |
52 | 52 | ||
53 | #include <qvaluelist.h> | 53 | #include <qvaluelist.h> |
54 | #include <qdict.h> | 54 | #include <qdict.h> |
55 | #include <qmap.h> | 55 | #include <qmap.h> |
56 | #include <qobject.h> | 56 | #include <qobject.h> |
57 | #include <qhostaddress.h> | 57 | #include <qhostaddress.h> |
58 | 58 | ||
59 | class ONetworkInterface; | 59 | class ONetworkInterface; |
60 | class OWirelessNetworkInterface; | 60 | class OWirelessNetworkInterface; |
61 | class OChannelHopper; | 61 | class OChannelHopper; |
62 | class OMonitoringInterface; | 62 | class OMonitoringInterface; |
63 | 63 | ||
64 | /*====================================================================================== | 64 | /*====================================================================================== |
65 | * ONetwork | 65 | * ONetwork |
66 | *======================================================================================*/ | 66 | *======================================================================================*/ |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * @brief A container class for all network interfaces | 69 | * @brief A container class for all network interfaces |
70 | * | 70 | * |
71 | * This class provides access to all available network interfaces of your computer. | 71 | * This class provides access to all available network interfaces of your computer. |
72 | * | 72 | * |
73 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 73 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
74 | */ | 74 | */ |
75 | class ONetwork : public QObject | 75 | class ONetwork : public QObject |
76 | { | 76 | { |
77 | Q_OBJECT | 77 | Q_OBJECT |
78 | 78 | ||
79 | public: | 79 | public: |
80 | typedef QDict<ONetworkInterface> InterfaceMap; | 80 | typedef QDict<ONetworkInterface> InterfaceMap; |
81 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 81 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
82 | 82 | ||
83 | public: | 83 | public: |
84 | /** | 84 | /** |
85 | * @returns the number of available interfaces | 85 | * @returns the number of available interfaces |
86 | */ | 86 | */ |
87 | int count() const; | 87 | int count() const; |
88 | /** | 88 | /** |
89 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 89 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
90 | */ | 90 | */ |
91 | static ONetwork* instance(); | 91 | static ONetwork* instance(); |
92 | /** | 92 | /** |
93 | * @returns an iterator usable for iterating through all network interfaces. | 93 | * @returns an iterator usable for iterating through all network interfaces. |
94 | */ | 94 | */ |
95 | InterfaceIterator iterator() const; | 95 | InterfaceIterator iterator() const; |
96 | /** | 96 | /** |
97 | * @returns true, if the @a interface is present. | ||
98 | */ | ||
99 | bool isPresent( const char* interface ) const; | ||
100 | /** | ||
97 | * @returns true, if the @a interface supports the wireless extension protocol. | 101 | * @returns true, if the @a interface supports the wireless extension protocol. |
98 | */ | 102 | */ |
99 | bool isWirelessInterface( const char* interface ) const; | 103 | bool isWirelessInterface( const char* interface ) const; |
100 | /** | 104 | /** |
101 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. | 105 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. |
102 | * @see ONetworkInterface | 106 | * @see ONetworkInterface |
103 | */ | 107 | */ |
104 | ONetworkInterface* interface( const QString& interface ) const; | 108 | ONetworkInterface* interface( const QString& interface ) const; |
105 | /** | 109 | /** |
106 | * @internal Rebuild the internal interface database | 110 | * @internal Rebuild the internal interface database |
107 | * @note Sometimes it might be useful to call this from client code, | 111 | * @note Sometimes it might be useful to call this from client code, |
108 | * e.g. after issuing a cardctl insert | 112 | * e.g. after issuing a cardctl insert |
109 | */ | 113 | */ |
110 | void synchronize(); | 114 | void synchronize(); |
111 | /** | 115 | /** |
112 | * @returns the wireless extension version used at compile time. | 116 | * @returns the wireless extension version used at compile time. |
113 | **/ | 117 | **/ |
114 | static short wirelessExtensionVersion(); | 118 | static short wirelessExtensionVersion(); |
115 | 119 | ||
116 | protected: | 120 | protected: |
117 | ONetwork(); | 121 | ONetwork(); |
118 | 122 | ||
119 | private: | 123 | private: |
120 | static ONetwork* _instance; | 124 | static ONetwork* _instance; |
121 | InterfaceMap _interfaces; | 125 | InterfaceMap _interfaces; |
122 | }; | 126 | }; |
123 | 127 | ||
124 | 128 | ||
125 | /*====================================================================================== | 129 | /*====================================================================================== |
126 | * ONetworkInterface | 130 | * ONetworkInterface |
127 | *======================================================================================*/ | 131 | *======================================================================================*/ |
128 | 132 | ||
129 | /** | 133 | /** |
130 | * @brief A network interface wrapper. | 134 | * @brief A network interface wrapper. |
131 | * | 135 | * |
132 | * 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 |
133 | * Linux ioctls are hidden under a convenient high-level interface. | 137 | * Linux ioctls are hidden under a convenient high-level interface. |
134 | * @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 |
135 | * process permissions to work. | 139 | * process permissions to work. |
136 | * | 140 | * |
137 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 141 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
138 | */ | 142 | */ |
139 | class ONetworkInterface : public QObject | 143 | class ONetworkInterface : public QObject |
140 | { | 144 | { |
141 | friend class OMonitoringInterface; | 145 | friend class OMonitoringInterface; |
142 | friend class OCiscoMonitoringInterface; | 146 | friend class OCiscoMonitoringInterface; |
143 | friend class OWlanNGMonitoringInterface; | 147 | friend class OWlanNGMonitoringInterface; |
144 | friend class OHostAPMonitoringInterface; | 148 | friend class OHostAPMonitoringInterface; |
145 | friend class OOrinocoMonitoringInterface; | 149 | friend class OOrinocoMonitoringInterface; |
146 | 150 | ||
147 | public: | 151 | public: |
148 | /** | 152 | /** |
149 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 153 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
150 | * but access them via @ref ONetwork::interface(). | 154 | * but access them via @ref ONetwork::interface(). |
151 | */ | 155 | */ |
152 | ONetworkInterface( QObject* parent, const char* name ); | 156 | ONetworkInterface( QObject* parent, const char* name ); |
153 | /** | 157 | /** |
154 | * Destructor. | 158 | * Destructor. |
155 | */ | 159 | */ |
156 | virtual ~ONetworkInterface(); | 160 | virtual ~ONetworkInterface(); |
157 | /** | 161 | /** |
158 | * Associates a @a monitoring interface with this network interface. | 162 | * Associates a @a monitoring interface with this network interface. |
159 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 163 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
160 | */ | 164 | */ |
161 | void setMonitoring( OMonitoringInterface* monitoring ); | 165 | void setMonitoring( OMonitoringInterface* monitoring ); |
162 | /** | 166 | /** |
163 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 167 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
164 | */ | 168 | */ |
165 | OMonitoringInterface* monitoring() const; | 169 | OMonitoringInterface* monitoring() const; |
166 | /** | 170 | /** |
167 | * Setting an interface to promiscuous mode enables the device to receive | 171 | * Setting an interface to promiscuous mode enables the device to receive |
168 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 172 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
169 | */ | 173 | */ |
170 | bool setPromiscuousMode( bool ); | 174 | bool setPromiscuousMode( bool ); |
171 | /** | 175 | /** |
172 | * @returns true if the interface is set to promiscuous mode. | 176 | * @returns true if the interface is set to promiscuous mode. |
173 | */ | 177 | */ |
174 | bool promiscuousMode() const; | 178 | bool promiscuousMode() const; |
175 | /** | 179 | /** |
176 | * Setting an interface to up enables it to receive packets. | 180 | * Setting an interface to up enables it to receive packets. |
177 | */ | 181 | */ |
178 | bool setUp( bool ); | 182 | bool setUp( bool ); |
179 | /** | 183 | /** |
180 | * @returns true if the interface is up. | 184 | * @returns true if the interface is up. |
181 | */ | 185 | */ |
182 | bool isUp() const; | 186 | bool isUp() const; |
183 | /** | 187 | /** |
184 | * @returns true if the interface is a loopback interface. | 188 | * @returns true if the interface is a loopback interface. |
185 | */ | 189 | */ |
186 | bool isLoopback() const; | 190 | bool isLoopback() const; |
187 | /** | 191 | /** |
188 | * @returns true if the interface is featuring supports the wireless extension protocol. | 192 | * @returns true if the interface is featuring supports the wireless extension protocol. |
189 | */ | 193 | */ |
190 | bool isWireless() const; | 194 | bool isWireless() const; |
191 | /** | 195 | /** |
192 | * Associate the IP address @ addr with the interface. | 196 | * Associate the IP address @ addr with the interface. |