author | simon <simon> | 2002-11-02 13:42:02 (UTC) |
---|---|---|
committer | simon <simon> | 2002-11-02 13:42:02 (UTC) |
commit | f655415f77b200f9edfbe5732cd5f8da2b4dec47 (patch) (unidiff) | |
tree | c5c700cda16dff17876aabae3e676358907b8868 | |
parent | c795a77698b9fc785fb5f04fab8fed33f0570c3f (diff) | |
download | opie-f655415f77b200f9edfbe5732cd5f8da2b4dec47.zip opie-f655415f77b200f9edfbe5732cd5f8da2b4dec47.tar.gz opie-f655415f77b200f9edfbe5732cd5f8da2b4dec47.tar.bz2 |
- fixed warning about missing return statement in non-void function.
Okayed by Michael Lauer
-rw-r--r-- | noncore/applets/wirelessapplet/networkinfo.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp index 2274d99..e0c487b 100644 --- a/noncore/applets/wirelessapplet/networkinfo.cpp +++ b/noncore/applets/wirelessapplet/networkinfo.cpp | |||
@@ -1,286 +1,284 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** MNetwork* classes | 2 | ** MNetwork* classes |
3 | ** | 3 | ** |
4 | ** Encapsulate network information | 4 | ** Encapsulate network information |
5 | ** | 5 | ** |
6 | ** Copyright (C) 2002, Michael Lauer | 6 | ** Copyright (C) 2002, Michael Lauer |
7 | ** mickey@tm.informatik.uni-frankfurt.de | 7 | ** mickey@tm.informatik.uni-frankfurt.de |
8 | ** http://www.Vanille.de | 8 | ** http://www.Vanille.de |
9 | ** | 9 | ** |
10 | ** Based on portions of the Wireless Extensions | 10 | ** Based on portions of the Wireless Extensions |
11 | ** Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com> | 11 | ** Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com> |
12 | ** | 12 | ** |
13 | ** This file may be distributed and/or modified under the terms of the | 13 | ** This file may be distributed and/or modified under the terms of the |
14 | ** GNU General Public License version 2 as published by the Free Software | 14 | ** GNU General Public License version 2 as published by the Free Software |
15 | ** Foundation and appearing in the file LICENSE.GPL included in the | 15 | ** Foundation and appearing in the file LICENSE.GPL included in the |
16 | ** packaging of this file. | 16 | ** packaging of this file. |
17 | ** | 17 | ** |
18 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 18 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
19 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 19 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
20 | ** | 20 | ** |
21 | **********************************************************************/ | 21 | **********************************************************************/ |
22 | 22 | ||
23 | #include "networkinfo.h" | 23 | #include "networkinfo.h" |
24 | 24 | ||
25 | #include <arpa/inet.h> | 25 | #include <arpa/inet.h> |
26 | #include <sys/socket.h> | 26 | #include <sys/socket.h> |
27 | #include <linux/if_ether.h> | 27 | #include <linux/if_ether.h> |
28 | #include <netinet/ip.h> | 28 | #include <netinet/ip.h> |
29 | #include <sys/ioctl.h> | 29 | #include <sys/ioctl.h> |
30 | #include <linux/wireless.h> | 30 | #include <linux/wireless.h> |
31 | 31 | ||
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #include <math.h> | 33 | #include <math.h> |
34 | #include <errno.h> | 34 | #include <errno.h> |
35 | #include <string.h> | 35 | #include <string.h> |
36 | 36 | ||
37 | #include <stdlib.h> | 37 | #include <stdlib.h> |
38 | 38 | ||
39 | #include <qstring.h> | 39 | #include <qstring.h> |
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | 42 | ||
43 | /* estimated wireless signal strength and noise level values | 43 | /* estimated wireless signal strength and noise level values |
44 | based on experimentation with Orinoco and Prism2 cards. | 44 | based on experimentation with Orinoco and Prism2 cards. |
45 | Seem to be correct, but please inform me, if you got values | 45 | Seem to be correct, but please inform me, if you got values |
46 | outside these boundaries. :Mickey: */ | 46 | outside these boundaries. :Mickey: */ |
47 | 47 | ||
48 | #define IW_UPPER 220 | 48 | #define IW_UPPER 220 |
49 | #define IW_LOWER 140 | 49 | #define IW_LOWER 140 |
50 | 50 | ||
51 | #define PROCNETDEV "/proc/net/dev" | 51 | #define PROCNETDEV "/proc/net/dev" |
52 | #define PROCNETWIRELESS "/proc/net/wireless" | 52 | #define PROCNETWIRELESS "/proc/net/wireless" |
53 | 53 | ||
54 | //#define MDEBUG 0 | 54 | //#define MDEBUG 0 |
55 | #undef MDEBUG | 55 | #undef MDEBUG |
56 | 56 | ||
57 | //--------------------------------------------------------------------------- | 57 | //--------------------------------------------------------------------------- |
58 | // class MNetworkInterface | 58 | // class MNetworkInterface |
59 | // | 59 | // |
60 | 60 | ||
61 | MNetworkInterface::MNetworkInterface( const char* name ) | 61 | MNetworkInterface::MNetworkInterface( const char* name ) |
62 | :name( name ) | 62 | :name( name ) |
63 | { | 63 | { |
64 | struct ifreq ifr; | 64 | struct ifreq ifr; |
65 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; | 65 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; |
66 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); | 66 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); |
67 | } | 67 | } |
68 | 68 | ||
69 | MNetworkInterface::~MNetworkInterface() | 69 | MNetworkInterface::~MNetworkInterface() |
70 | { | 70 | { |
71 | if ( fd != -1 ) | 71 | if ( fd != -1 ) |
72 | close( fd ); | 72 | close( fd ); |
73 | } | 73 | } |
74 | 74 | ||
75 | bool MNetworkInterface::updateStatistics() | 75 | bool MNetworkInterface::updateStatistics() |
76 | { | 76 | { |
77 | return true; | 77 | return true; |
78 | } | 78 | } |
79 | 79 | ||
80 | //--------------------------------------------------------------------------- | 80 | //--------------------------------------------------------------------------- |
81 | // class MWirelessNetworkInterface | 81 | // class MWirelessNetworkInterface |
82 | // | 82 | // |
83 | 83 | ||
84 | MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n ) | 84 | MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n ) |
85 | :MNetworkInterface( n ) | 85 | :MNetworkInterface( n ) |
86 | { | 86 | { |
87 | signal = 0; | 87 | signal = 0; |
88 | noise = 0; | 88 | noise = 0; |
89 | quality = 0; | 89 | quality = 0; |
90 | } | 90 | } |
91 | 91 | ||
92 | MWirelessNetworkInterface::~MWirelessNetworkInterface() | 92 | MWirelessNetworkInterface::~MWirelessNetworkInterface() |
93 | { | 93 | { |
94 | } | 94 | } |
95 | 95 | ||
96 | int MWirelessNetworkInterface::qualityPercent() | 96 | int MWirelessNetworkInterface::qualityPercent() |
97 | { | 97 | { |
98 | return ( quality*100 ) / 92; | 98 | return ( quality*100 ) / 92; |
99 | } | 99 | } |
100 | 100 | ||
101 | int MWirelessNetworkInterface::signalPercent() | 101 | int MWirelessNetworkInterface::signalPercent() |
102 | { | 102 | { |
103 | return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; | 103 | return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; |
104 | } | 104 | } |
105 | 105 | ||
106 | int MWirelessNetworkInterface::noisePercent() | 106 | int MWirelessNetworkInterface::noisePercent() |
107 | { | 107 | { |
108 | return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; | 108 | return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; |
109 | } | 109 | } |
110 | 110 | ||
111 | bool MWirelessNetworkInterface::updateStatistics() | 111 | bool MWirelessNetworkInterface::updateStatistics() |
112 | { | 112 | { |
113 | bool base = MNetworkInterface::updateStatistics(); | 113 | bool base = MNetworkInterface::updateStatistics(); |
114 | if ( !base ) | 114 | if ( !base ) |
115 | return false; | 115 | return false; |
116 | 116 | ||
117 | const char* buffer[200]; | 117 | const char* buffer[200]; |
118 | 118 | ||
119 | struct iwreq iwr; | 119 | struct iwreq iwr; |
120 | memset( &iwr, 0, sizeof( iwr ) ); | 120 | memset( &iwr, 0, sizeof( iwr ) ); |
121 | iwr.u.essid.pointer = (caddr_t) buffer; | 121 | iwr.u.essid.pointer = (caddr_t) buffer; |
122 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 122 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
123 | iwr.u.essid.flags = 0; | 123 | iwr.u.essid.flags = 0; |
124 | 124 | ||
125 | // check if it is an IEEE 802.11 standard conform | 125 | // check if it is an IEEE 802.11 standard conform |
126 | // wireless device by sending SIOCGIWESSID | 126 | // wireless device by sending SIOCGIWESSID |
127 | // which also gives back the Extended Service Set ID | 127 | // which also gives back the Extended Service Set ID |
128 | // (see IEEE 802.11 for more information) | 128 | // (see IEEE 802.11 for more information) |
129 | 129 | ||
130 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name ); | 130 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name ); |
131 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); | 131 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); |
132 | if ( result == 0 ) | 132 | if ( result == 0 ) |
133 | { | 133 | { |
134 | hasWirelessExtensions = true; | 134 | hasWirelessExtensions = true; |
135 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; | 135 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; |
136 | essid = iwr.u.essid.pointer; | 136 | essid = iwr.u.essid.pointer; |
137 | } | 137 | } |
138 | else essid = "*** Unknown ***"; | 138 | else essid = "*** Unknown ***"; |
139 | 139 | ||
140 | // Address of associated access-point | 140 | // Address of associated access-point |
141 | 141 | ||
142 | result = ioctl( fd, SIOCGIWAP, &iwr ); | 142 | result = ioctl( fd, SIOCGIWAP, &iwr ); |
143 | if ( result == 0 ) | 143 | if ( result == 0 ) |
144 | { | 144 | { |
145 | APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 145 | APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
146 | iwr.u.ap_addr.sa_data[0]&0xff, | 146 | iwr.u.ap_addr.sa_data[0]&0xff, |
147 | iwr.u.ap_addr.sa_data[1]&0xff, | 147 | iwr.u.ap_addr.sa_data[1]&0xff, |
148 | iwr.u.ap_addr.sa_data[2]&0xff, | 148 | iwr.u.ap_addr.sa_data[2]&0xff, |
149 | iwr.u.ap_addr.sa_data[3]&0xff, | 149 | iwr.u.ap_addr.sa_data[3]&0xff, |
150 | iwr.u.ap_addr.sa_data[4]&0xff, | 150 | iwr.u.ap_addr.sa_data[4]&0xff, |
151 | iwr.u.ap_addr.sa_data[5]&0xff ); | 151 | iwr.u.ap_addr.sa_data[5]&0xff ); |
152 | } else APAddr = "*** Unknown ***"; | 152 | } else APAddr = "*** Unknown ***"; |
153 | 153 | ||
154 | iwr.u.data.pointer = (caddr_t) buffer; | 154 | iwr.u.data.pointer = (caddr_t) buffer; |
155 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | 155 | iwr.u.data.length = IW_ESSID_MAX_SIZE; |
156 | iwr.u.data.flags = 0; | 156 | iwr.u.data.flags = 0; |
157 | 157 | ||
158 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); | 158 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); |
159 | if ( result == 0 ) | 159 | if ( result == 0 ) |
160 | { | 160 | { |
161 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; | 161 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; |
162 | nick = iwr.u.data.pointer; | 162 | nick = iwr.u.data.pointer; |
163 | } else nick = "*** Unknown ***"; | 163 | } else nick = "*** Unknown ***"; |
164 | 164 | ||
165 | result = ioctl( fd, SIOCGIWMODE, &iwr ); | 165 | result = ioctl( fd, SIOCGIWMODE, &iwr ); |
166 | if ( result == 0 ) | 166 | if ( result == 0 ) |
167 | mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed"; | 167 | mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed"; |
168 | else mode = "*** Unknown ***"; | 168 | else mode = "*** Unknown ***"; |
169 | 169 | ||
170 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); | 170 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); |
171 | if ( result == 0 ) | 171 | if ( result == 0 ) |
172 | freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000; | 172 | freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000; |
173 | else freq = 0; | 173 | else freq = 0; |
174 | 174 | ||
175 | // gather link quality from /proc/net/wireless | 175 | // gather link quality from /proc/net/wireless |
176 | 176 | ||
177 | char c; | 177 | char c; |
178 | QString status; | 178 | QString status; |
179 | QString name; | 179 | QString name; |
180 | QFile wfile( PROCNETWIRELESS ); | 180 | QFile wfile( PROCNETWIRELESS ); |
181 | bool hasFile = wfile.open( IO_ReadOnly ); | 181 | bool hasFile = wfile.open( IO_ReadOnly ); |
182 | QTextStream wstream( &wfile ); | 182 | QTextStream wstream( &wfile ); |
183 | if ( hasFile ) | 183 | if ( hasFile ) |
184 | { | 184 | { |
185 | wstream.readLine(); // skip the first two lines | 185 | wstream.readLine(); // skip the first two lines |
186 | wstream.readLine(); // because they only contain headers | 186 | wstream.readLine(); // because they only contain headers |
187 | } | 187 | } |
188 | if ( ( !hasFile ) || ( wstream.atEnd() ) ) | 188 | if ( ( !hasFile ) || ( wstream.atEnd() ) ) |
189 | { | 189 | { |
190 | #ifdef MDEBUG | 190 | #ifdef MDEBUG |
191 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); | 191 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); |
192 | #endif | 192 | #endif |
193 | quality = -1; | 193 | quality = -1; |
194 | signal = IW_LOWER; | 194 | signal = IW_LOWER; |
195 | noise = IW_LOWER; | 195 | noise = IW_LOWER; |
196 | return false; | 196 | return false; |
197 | } | 197 | } |
198 | 198 | ||
199 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | 199 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; |
200 | 200 | ||
201 | if ( quality > 92 ) | ||
202 | #ifdef MDEBUG | 201 | #ifdef MDEBUG |
202 | if ( quality > 92 ) | ||
203 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); | 203 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); |
204 | #endif | 204 | |
205 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | 205 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) |
206 | #ifdef MDEBUG | ||
207 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); | 206 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); |
208 | #endif | 207 | |
209 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | 208 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) |
210 | #ifdef MDEBUG | ||
211 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); | 209 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); |
212 | #endif | 210 | #endif |
213 | 211 | ||
214 | return true; | 212 | return true; |
215 | 213 | ||
216 | } | 214 | } |
217 | 215 | ||
218 | //--------------------------------------------------------------------------- | 216 | //--------------------------------------------------------------------------- |
219 | // class Network | 217 | // class Network |
220 | // | 218 | // |
221 | 219 | ||
222 | MNetwork::MNetwork() | 220 | MNetwork::MNetwork() |
223 | { | 221 | { |
224 | procfile = PROCNETDEV; | 222 | procfile = PROCNETDEV; |
225 | } | 223 | } |
226 | 224 | ||
227 | MNetwork::~MNetwork() | 225 | MNetwork::~MNetwork() |
228 | { | 226 | { |
229 | } | 227 | } |
230 | 228 | ||
231 | //--------------------------------------------------------------------------- | 229 | //--------------------------------------------------------------------------- |
232 | // class WirelessNetwork | 230 | // class WirelessNetwork |
233 | // | 231 | // |
234 | 232 | ||
235 | MWirelessNetwork::MWirelessNetwork() | 233 | MWirelessNetwork::MWirelessNetwork() |
236 | { | 234 | { |
237 | procfile = PROCNETWIRELESS; | 235 | procfile = PROCNETWIRELESS; |
238 | } | 236 | } |
239 | 237 | ||
240 | MWirelessNetwork::~MWirelessNetwork() | 238 | MWirelessNetwork::~MWirelessNetwork() |
241 | { | 239 | { |
242 | } | 240 | } |
243 | 241 | ||
244 | MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const | 242 | MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const |
245 | { | 243 | { |
246 | return new MWirelessNetworkInterface( n ); | 244 | return new MWirelessNetworkInterface( n ); |
247 | } | 245 | } |
248 | 246 | ||
249 | //--------------------------------------------------------------------------- | 247 | //--------------------------------------------------------------------------- |
250 | // class NetworkInterface | 248 | // class NetworkInterface |
251 | // | 249 | // |
252 | 250 | ||
253 | MNetworkInterface* MNetwork::getFirstInterface() | 251 | MNetworkInterface* MNetwork::getFirstInterface() |
254 | { | 252 | { |
255 | enumerateInterfaces(); | 253 | enumerateInterfaces(); |
256 | InterfaceMapIterator it( interfaces ); | 254 | InterfaceMapIterator it( interfaces ); |
257 | return ( it.count() > 0 ) ? it.toFirst() : 0; | 255 | return ( it.count() > 0 ) ? it.toFirst() : 0; |
258 | } | 256 | } |
259 | 257 | ||
260 | void MNetwork::enumerateInterfaces() | 258 | void MNetwork::enumerateInterfaces() |
261 | { | 259 | { |
262 | interfaces.clear(); | 260 | interfaces.clear(); |
263 | QString str; | 261 | QString str; |
264 | QFile f( procfile ); | 262 | QFile f( procfile ); |
265 | bool hasFile = f.open( IO_ReadOnly ); | 263 | bool hasFile = f.open( IO_ReadOnly ); |
266 | if ( !hasFile ) | 264 | if ( !hasFile ) |
267 | return; | 265 | return; |
268 | QTextStream s( &f ); | 266 | QTextStream s( &f ); |
269 | s.readLine(); | 267 | s.readLine(); |
270 | s.readLine(); | 268 | s.readLine(); |
271 | while ( !s.atEnd() ) | 269 | while ( !s.atEnd() ) |
272 | { | 270 | { |
273 | s >> str; | 271 | s >> str; |
274 | str.truncate( str.find( ':' ) ); | 272 | str.truncate( str.find( ':' ) ); |
275 | #ifdef MDEBUG | 273 | #ifdef MDEBUG |
276 | qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); | 274 | qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); |
277 | #endif | 275 | #endif |
278 | interfaces.insert( str, createInterface( str ) ); | 276 | interfaces.insert( str, createInterface( str ) ); |
279 | s.readLine(); | 277 | s.readLine(); |
280 | } | 278 | } |
281 | } | 279 | } |
282 | 280 | ||
283 | MNetworkInterface* MNetwork::createInterface( const char* n ) const | 281 | MNetworkInterface* MNetwork::createInterface( const char* n ) const |
284 | { | 282 | { |
285 | return new MNetworkInterface( n ); | 283 | return new MNetworkInterface( n ); |
286 | } | 284 | } |