Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index be45924..918ba07 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -37,48 +37,53 @@ | |||
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | 39 | ||
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | 42 | ||
43 | /* UNIX */ | 43 | /* UNIX */ |
44 | 44 | ||
45 | #include <assert.h> | 45 | #include <assert.h> |
46 | #include <arpa/inet.h> | 46 | #include <arpa/inet.h> |
47 | #include <cerrno> | 47 | #include <cerrno> |
48 | #include <cstring> | 48 | #include <cstring> |
49 | #include <cstdlib> | 49 | #include <cstdlib> |
50 | #include <math.h> | 50 | #include <math.h> |
51 | #include <sys/ioctl.h> | 51 | #include <sys/ioctl.h> |
52 | #include <sys/socket.h> | 52 | #include <sys/socket.h> |
53 | #include <sys/types.h> | 53 | #include <sys/types.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #include <linux/sockios.h> | 55 | #include <linux/sockios.h> |
56 | #include <net/if_arp.h> | 56 | #include <net/if_arp.h> |
57 | #include <stdarg.h> | 57 | #include <stdarg.h> |
58 | 58 | ||
59 | using namespace std; | 59 | using namespace std; |
60 | 60 | ||
61 | #ifndef NODEBUG | ||
62 | #include <opie2/oioctlmap.h> | ||
63 | IntStringMap* _ioctlmap = constructIoctlMap(); | ||
64 | #endif | ||
65 | |||
61 | /*====================================================================================== | 66 | /*====================================================================================== |
62 | * ONetwork | 67 | * ONetwork |
63 | *======================================================================================*/ | 68 | *======================================================================================*/ |
64 | 69 | ||
65 | ONetwork* ONetwork::_instance = 0; | 70 | ONetwork* ONetwork::_instance = 0; |
66 | 71 | ||
67 | ONetwork::ONetwork() | 72 | ONetwork::ONetwork() |
68 | { | 73 | { |
69 | qDebug( "ONetwork::ONetwork()" ); | 74 | qDebug( "ONetwork::ONetwork()" ); |
70 | qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); | 75 | qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); |
71 | synchronize(); | 76 | synchronize(); |
72 | } | 77 | } |
73 | 78 | ||
74 | void ONetwork::synchronize() | 79 | void ONetwork::synchronize() |
75 | { | 80 | { |
76 | // gather available interfaces by inspecting /proc/net/dev | 81 | // gather available interfaces by inspecting /proc/net/dev |
77 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 82 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
78 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 83 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
79 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | 84 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev |
80 | 85 | ||
81 | _interfaces.clear(); | 86 | _interfaces.clear(); |
82 | QString str; | 87 | QString str; |
83 | QFile f( "/proc/net/dev" ); | 88 | QFile f( "/proc/net/dev" ); |
84 | bool hasFile = f.open( IO_ReadOnly ); | 89 | bool hasFile = f.open( IO_ReadOnly ); |
@@ -166,54 +171,58 @@ ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | |||
166 | 171 | ||
167 | 172 | ||
168 | struct ifreq& ONetworkInterface::ifr() const | 173 | struct ifreq& ONetworkInterface::ifr() const |
169 | { | 174 | { |
170 | return _ifr; | 175 | return _ifr; |
171 | } | 176 | } |
172 | 177 | ||
173 | 178 | ||
174 | void ONetworkInterface::init() | 179 | void ONetworkInterface::init() |
175 | { | 180 | { |
176 | qDebug( "ONetworkInterface::init()" ); | 181 | qDebug( "ONetworkInterface::init()" ); |
177 | 182 | ||
178 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 183 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
179 | 184 | ||
180 | if ( _sfd == -1 ) | 185 | if ( _sfd == -1 ) |
181 | { | 186 | { |
182 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 187 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
183 | return; | 188 | return; |
184 | } | 189 | } |
185 | } | 190 | } |
186 | 191 | ||
187 | 192 | ||
188 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 193 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
189 | { | 194 | { |
195 | #ifndef NODEBUG | ||
190 | int result = ::ioctl( _sfd, call, &ifreq ); | 196 | int result = ::ioctl( _sfd, call, &ifreq ); |
191 | if ( result == -1 ) | 197 | if ( result == -1 ) |
192 | qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) ); | 198 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) ); |
193 | else | 199 | else |
194 | qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call ); | 200 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call ); |
195 | return ( result != -1 ); | 201 | return ( result != -1 ); |
202 | #else | ||
203 | return ::ioctl( _sfd, call, &ifreq ) != -1; | ||
204 | #endif | ||
196 | } | 205 | } |
197 | 206 | ||
198 | 207 | ||
199 | bool ONetworkInterface::ioctl( int call ) const | 208 | bool ONetworkInterface::ioctl( int call ) const |
200 | { | 209 | { |
201 | strcpy( _ifr.ifr_name, name() ); | 210 | strcpy( _ifr.ifr_name, name() ); |
202 | return ioctl( call, _ifr ); | 211 | return ioctl( call, _ifr ); |
203 | } | 212 | } |
204 | 213 | ||
205 | 214 | ||
206 | bool ONetworkInterface::isLoopback() const | 215 | bool ONetworkInterface::isLoopback() const |
207 | { | 216 | { |
208 | ioctl( SIOCGIFFLAGS ); | 217 | ioctl( SIOCGIFFLAGS ); |
209 | return _ifr.ifr_flags & IFF_LOOPBACK; | 218 | return _ifr.ifr_flags & IFF_LOOPBACK; |
210 | } | 219 | } |
211 | 220 | ||
212 | 221 | ||
213 | bool ONetworkInterface::setUp( bool b ) | 222 | bool ONetworkInterface::setUp( bool b ) |
214 | { | 223 | { |
215 | ioctl( SIOCGIFFLAGS ); | 224 | ioctl( SIOCGIFFLAGS ); |
216 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 225 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
217 | else _ifr.ifr_flags &= (~IFF_UP); | 226 | else _ifr.ifr_flags &= (~IFF_UP); |
218 | return ioctl( SIOCSIFFLAGS ); | 227 | return ioctl( SIOCSIFFLAGS ); |
219 | } | 228 | } |
@@ -862,54 +871,58 @@ int OWirelessNetworkInterface::scanNetwork() | |||
862 | continue; | 871 | continue; |
863 | } | 872 | } |
864 | #endif | 873 | #endif |
865 | tv.tv_sec = 0; | 874 | tv.tv_sec = 0; |
866 | tv.tv_usec = 100000; | 875 | tv.tv_usec = 100000; |
867 | continue; | 876 | continue; |
868 | } | 877 | } |
869 | } | 878 | } |
870 | 879 | ||
871 | qDebug( "ONetworkInterface::scanNetwork() - scan finished." ); | 880 | qDebug( "ONetworkInterface::scanNetwork() - scan finished." ); |
872 | 881 | ||
873 | if ( results ) | 882 | if ( results ) |
874 | { | 883 | { |
875 | qDebug( " - results are in!" ); | 884 | qDebug( " - results are in!" ); |
876 | } | 885 | } |
877 | else | 886 | else |
878 | { | 887 | { |
879 | qDebug( " - no results :(" ); | 888 | qDebug( " - no results :(" ); |
880 | } | 889 | } |
881 | } | 890 | } |
882 | 891 | ||
883 | 892 | ||
884 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 893 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
885 | { | 894 | { |
895 | #ifndef NODEBUG | ||
886 | int result = ::ioctl( _sfd, call, &iwreq ); | 896 | int result = ::ioctl( _sfd, call, &iwreq ); |
887 | if ( result == -1 ) | 897 | if ( result == -1 ) |
888 | qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) ); | 898 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) ); |
889 | else | 899 | else |
890 | qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call ); | 900 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call ); |
891 | return ( result != -1 ); | 901 | return ( result != -1 ); |
902 | #else | ||
903 | return ::ioctl( _sfd, call, &iwreq ) != -1; | ||
904 | #endif | ||
892 | } | 905 | } |
893 | 906 | ||
894 | 907 | ||
895 | bool OWirelessNetworkInterface::wioctl( int call ) const | 908 | bool OWirelessNetworkInterface::wioctl( int call ) const |
896 | { | 909 | { |
897 | strcpy( _iwr.ifr_name, name() ); | 910 | strcpy( _iwr.ifr_name, name() ); |
898 | return wioctl( call, _iwr ); | 911 | return wioctl( call, _iwr ); |
899 | } | 912 | } |
900 | 913 | ||
901 | 914 | ||
902 | /*====================================================================================== | 915 | /*====================================================================================== |
903 | * OMonitoringInterface | 916 | * OMonitoringInterface |
904 | *======================================================================================*/ | 917 | *======================================================================================*/ |
905 | 918 | ||
906 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 919 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
907 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 920 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
908 | { | 921 | { |
909 | } | 922 | } |
910 | 923 | ||
911 | 924 | ||
912 | OMonitoringInterface::~OMonitoringInterface() | 925 | OMonitoringInterface::~OMonitoringInterface() |
913 | { | 926 | { |
914 | } | 927 | } |
915 | 928 | ||