author | zecke <zecke> | 2004-03-13 21:59:48 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-03-13 21:59:48 (UTC) |
commit | ee753c0009da5bec4a71d3263e9623d04dddc5c4 (patch) (unidiff) | |
tree | f578536203c4277cc124d622b50f46a025cbb3f9 /libopie2 | |
parent | 2eb5c075b612498c4b65f3d49389b8612612a930 (diff) | |
download | opie-ee753c0009da5bec4a71d3263e9623d04dddc5c4.zip opie-ee753c0009da5bec4a71d3263e9623d04dddc5c4.tar.gz opie-ee753c0009da5bec4a71d3263e9623d04dddc5c4.tar.bz2 |
Fix possible divide by null
Patch for mickeyl...
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index ab3e77f..26a6c81 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -36,61 +36,61 @@ | |||
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | 38 | ||
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <qtextstream.h> | 40 | #include <qtextstream.h> |
41 | 41 | ||
42 | /* UNIX */ | 42 | /* UNIX */ |
43 | 43 | ||
44 | #include <assert.h> | 44 | #include <assert.h> |
45 | #include <arpa/inet.h> | 45 | #include <arpa/inet.h> |
46 | #include <errno.h> | 46 | #include <errno.h> |
47 | #include <string.h> | 47 | #include <string.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <sys/ioctl.h> | 50 | #include <sys/ioctl.h> |
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 | 60 | ||
61 | 61 | ||
62 | using namespace Opie::Core; | 62 | using namespace Opie::Core; |
63 | using namespace Opie::Net::Private; | 63 | using namespace Opie::Net::Private; |
64 | DebugMapper* debugmapper = new DebugMapper(); | 64 | DebugMapper* debugmapper = new DebugMapper(); |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | /*====================================================================================== | 67 | /*====================================================================================== |
68 | * ONetwork | 68 | * ONetwork |
69 | *======================================================================================*/ | 69 | *======================================================================================*/ |
70 | 70 | ||
71 | namespace Opie { | 71 | namespace Opie { |
72 | namespace Net { | 72 | namespace Net { |
73 | ONetwork* ONetwork::_instance = 0; | 73 | ONetwork* ONetwork::_instance = 0; |
74 | 74 | ||
75 | ONetwork::ONetwork() | 75 | ONetwork::ONetwork() |
76 | { | 76 | { |
77 | odebug << "ONetwork::ONetwork()" << oendl; | 77 | odebug << "ONetwork::ONetwork()" << oendl; |
78 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; | 78 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; |
79 | synchronize(); | 79 | synchronize(); |
80 | } | 80 | } |
81 | 81 | ||
82 | void ONetwork::synchronize() | 82 | void ONetwork::synchronize() |
83 | { | 83 | { |
84 | // gather available interfaces by inspecting /proc/net/dev | 84 | // gather available interfaces by inspecting /proc/net/dev |
85 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 85 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
86 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 86 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
87 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | 87 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev |
88 | 88 | ||
89 | _interfaces.clear(); | 89 | _interfaces.clear(); |
90 | QString str; | 90 | QString str; |
91 | QFile f( "/proc/net/dev" ); | 91 | QFile f( "/proc/net/dev" ); |
92 | bool hasFile = f.open( IO_ReadOnly ); | 92 | bool hasFile = f.open( IO_ReadOnly ); |
93 | if ( !hasFile ) | 93 | if ( !hasFile ) |
94 | { | 94 | { |
95 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; | 95 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; |
96 | return; | 96 | return; |
@@ -985,49 +985,50 @@ OStationList* OWirelessNetworkInterface::scanNetwork() | |||
985 | odebug << " - no results (timeout) :(" << oendl; | 985 | odebug << " - no results (timeout) :(" << oendl; |
986 | return stations; | 986 | return stations; |
987 | } | 987 | } |
988 | } | 988 | } |
989 | 989 | ||
990 | 990 | ||
991 | int OWirelessNetworkInterface::signalStrength() const | 991 | int OWirelessNetworkInterface::signalStrength() const |
992 | { | 992 | { |
993 | iw_statistics stat; | 993 | iw_statistics stat; |
994 | ::memset( &stat, 0, sizeof stat ); | 994 | ::memset( &stat, 0, sizeof stat ); |
995 | _iwr.u.data.pointer = (char*) &stat; | 995 | _iwr.u.data.pointer = (char*) &stat; |
996 | _iwr.u.data.flags = 0; | 996 | _iwr.u.data.flags = 0; |
997 | _iwr.u.data.length = sizeof stat; | 997 | _iwr.u.data.length = sizeof stat; |
998 | 998 | ||
999 | if ( !wioctl( SIOCGIWSTATS ) ) | 999 | if ( !wioctl( SIOCGIWSTATS ) ) |
1000 | { | 1000 | { |
1001 | return -1; | 1001 | return -1; |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | int max = _range.max_qual.qual; | 1004 | int max = _range.max_qual.qual; |
1005 | int cur = stat.qual.qual; | 1005 | int cur = stat.qual.qual; |
1006 | int lev = stat.qual.level; //FIXME: Do something with them? | 1006 | int lev = stat.qual.level; //FIXME: Do something with them? |
1007 | int noi = stat.qual.noise; //FIXME: Do something with them? | 1007 | int noi = stat.qual.noise; //FIXME: Do something with them? |
1008 | 1008 | ||
1009 | return cur*100/max; | 1009 | |
1010 | return max != 0 ? cur*100/max: -1; | ||
1010 | } | 1011 | } |
1011 | 1012 | ||
1012 | 1013 | ||
1013 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 1014 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
1014 | { | 1015 | { |
1015 | #ifndef NODEBUG | 1016 | #ifndef NODEBUG |
1016 | int result = ::ioctl( _sfd, call, &iwreq ); | 1017 | int result = ::ioctl( _sfd, call, &iwreq ); |
1017 | 1018 | ||
1018 | if ( result == -1 ) | 1019 | if ( result == -1 ) |
1019 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1020 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1020 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | 1021 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
1021 | else | 1022 | else |
1022 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1023 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1023 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; | 1024 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; |
1024 | 1025 | ||
1025 | return ( result != -1 ); | 1026 | return ( result != -1 ); |
1026 | #else | 1027 | #else |
1027 | return ::ioctl( _sfd, call, &iwreq ) != -1; | 1028 | return ::ioctl( _sfd, call, &iwreq ) != -1; |
1028 | #endif | 1029 | #endif |
1029 | } | 1030 | } |
1030 | 1031 | ||
1031 | 1032 | ||
1032 | bool OWirelessNetworkInterface::wioctl( int call ) const | 1033 | bool OWirelessNetworkInterface::wioctl( int call ) const |
1033 | { | 1034 | { |
@@ -1222,27 +1223,27 @@ void OOrinocoMonitoringInterface::setChannel( int c ) | |||
1222 | { | 1223 | { |
1223 | int monitorCode = _prismHeader ? 1 : 2; | 1224 | int monitorCode = _prismHeader ? 1 : 2; |
1224 | _if->setPrivate( "monitor", 2, monitorCode, c ); | 1225 | _if->setPrivate( "monitor", 2, monitorCode, c ); |
1225 | } | 1226 | } |
1226 | } | 1227 | } |
1227 | 1228 | ||
1228 | 1229 | ||
1229 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 1230 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
1230 | { | 1231 | { |
1231 | if ( b ) | 1232 | if ( b ) |
1232 | { | 1233 | { |
1233 | setChannel( 1 ); | 1234 | setChannel( 1 ); |
1234 | } | 1235 | } |
1235 | else | 1236 | else |
1236 | { | 1237 | { |
1237 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1238 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1238 | } | 1239 | } |
1239 | } | 1240 | } |
1240 | 1241 | ||
1241 | 1242 | ||
1242 | QString OOrinocoMonitoringInterface::name() const | 1243 | QString OOrinocoMonitoringInterface::name() const |
1243 | { | 1244 | { |
1244 | return "orinoco"; | 1245 | return "orinoco"; |
1245 | } | 1246 | } |
1246 | 1247 | ||
1247 | } | 1248 | } |
1248 | } | 1249 | } |