-rw-r--r-- | noncore/settings/networksettings2/networksettings2/system.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index 271e73d..298bdc9 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp | |||
@@ -1,155 +1,159 @@ | |||
1 | #include <sys/types.h> | 1 | #include <sys/types.h> |
2 | #include <sys/wait.h> | 2 | #include <sys/wait.h> |
3 | 3 | ||
4 | #include <net/if.h> | 4 | #include <net/if.h> |
5 | #include <net/if_arp.h> | 5 | #include <net/if_arp.h> |
6 | #include <netinet/in.h> | 6 | #include <netinet/in.h> |
7 | #include <arpa/inet.h> | 7 | #include <arpa/inet.h> |
8 | #include <sys/ioctl.h> | 8 | #include <sys/ioctl.h> |
9 | #include <sys/socket.h> | 9 | #include <sys/socket.h> |
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
11 | #include <stdio.h> | 11 | #include <stdio.h> |
12 | #include <fcntl.h> | 12 | #include <fcntl.h> |
13 | #include <errno.h> | 13 | #include <errno.h> |
14 | #include <unistd.h> | 14 | #include <unistd.h> |
15 | 15 | ||
16 | #include <qdir.h> | 16 | #include <qdir.h> |
17 | #include <qregexp.h> | 17 | #include <qregexp.h> |
18 | #include <qstringlist.h> | 18 | #include <qstringlist.h> |
19 | #include <qfile.h> | 19 | #include <qfile.h> |
20 | #include <qtextstream.h> | 20 | #include <qtextstream.h> |
21 | #include <qapplication.h> | 21 | #include <qapplication.h> |
22 | 22 | ||
23 | #include "resources.h" | 23 | #include "resources.h" |
24 | #include "system.h" | 24 | #include "system.h" |
25 | 25 | ||
26 | #define PROCNETDEV "/proc/net/dev" | 26 | #define PROCNETDEV "/proc/net/dev" |
27 | 27 | ||
28 | #ifndef ARPHRD_IEEE80211 | ||
29 | #define ARPHRD_IEEE80211 801 | ||
30 | #endif | ||
31 | |||
28 | static char Dig2Hex[] = { | 32 | static char Dig2Hex[] = { |
29 | '0', '1', '2', '3', | 33 | '0', '1', '2', '3', |
30 | '4', '5', '6', '7', | 34 | '4', '5', '6', '7', |
31 | '8', '9', 'A', 'B', | 35 | '8', '9', 'A', 'B', |
32 | 'C', 'D', 'E', 'F' | 36 | 'C', 'D', 'E', 'F' |
33 | }; | 37 | }; |
34 | 38 | ||
35 | // get HIGH nibble of byte | 39 | // get HIGH nibble of byte |
36 | #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] | 40 | #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] |
37 | // get LOW nibble of byte | 41 | // get LOW nibble of byte |
38 | #define LN(x) Dig2Hex[((x)&0x0f)] | 42 | #define LN(x) Dig2Hex[((x)&0x0f)] |
39 | 43 | ||
40 | System::System( void ) : QObject(), ProbedInterfaces() { | 44 | System::System( void ) : QObject(), ProbedInterfaces() { |
41 | probeInterfaces(); | 45 | probeInterfaces(); |
42 | } | 46 | } |
43 | 47 | ||
44 | System::~System( void ) { | 48 | System::~System( void ) { |
45 | if( ProcDevNet ) | 49 | if( ProcDevNet ) |
46 | delete ProcDevNet; | 50 | delete ProcDevNet; |
47 | } | 51 | } |
48 | 52 | ||
49 | int System::runAsRoot( const QString & S ) { | 53 | int System::runAsRoot( const QString & S ) { |
50 | QString MyS = S; | 54 | QString MyS = S; |
51 | char * usr = getenv("USER"); | 55 | char * usr = getenv("USER"); |
52 | char ch; | 56 | char ch; |
53 | 57 | ||
54 | if( S.isEmpty() ) { | 58 | if( S.isEmpty() ) { |
55 | // loophole to start shell | 59 | // loophole to start shell |
56 | return 8888; | 60 | return 8888; |
57 | } | 61 | } |
58 | if( usr == 0 || strcmp( usr, "root" ) ) { | 62 | if( usr == 0 || strcmp( usr, "root" ) ) { |
59 | // unknown or non-root user -> use SUDO | 63 | // unknown or non-root user -> use SUDO |
60 | MyS.prepend( "sudo " ); | 64 | MyS.prepend( "sudo " ); |
61 | } | 65 | } |
62 | 66 | ||
63 | Log(("Executing %s\n", MyS.latin1() )); | 67 | Log(("Executing %s\n", MyS.latin1() )); |
64 | 68 | ||
65 | emit lineFromCommand( tr("Command : ") + MyS ); | 69 | emit lineFromCommand( tr("Command : ") + MyS ); |
66 | emit lineFromCommand( "---------------" ); | 70 | emit lineFromCommand( "---------------" ); |
67 | Log(( "Command : %s\n", MyS.latin1() ) ); | 71 | Log(( "Command : %s\n", MyS.latin1() ) ); |
68 | MyS += " 2>&1 "; | 72 | MyS += " 2>&1 "; |
69 | OutputOfCmd = popen( MyS.latin1(), "r" ) ; | 73 | OutputOfCmd = popen( MyS.latin1(), "r" ) ; |
70 | if( ! OutputOfCmd ) { | 74 | if( ! OutputOfCmd ) { |
71 | // cannot fork | 75 | // cannot fork |
72 | return 1; | 76 | return 1; |
73 | } | 77 | } |
74 | 78 | ||
75 | // read all data | 79 | // read all data |
76 | QString Line = ""; | 80 | QString Line = ""; |
77 | while( 1 ) { | 81 | while( 1 ) { |
78 | if( fread( &ch, 1, 1, OutputOfCmd ) < 1 ) | 82 | if( fread( &ch, 1, 1, OutputOfCmd ) < 1 ) |
79 | // eof | 83 | // eof |
80 | break; | 84 | break; |
81 | if( ch == '\n' || ch == '\r' ) { | 85 | if( ch == '\n' || ch == '\r' ) { |
82 | if( ! Line.isEmpty() ) { | 86 | if( ! Line.isEmpty() ) { |
83 | Log(( "read cmd output : **%s**\n", Line.latin1() ) ); | 87 | Log(( "read cmd output : **%s**\n", Line.latin1() ) ); |
84 | emit lineFromCommand( Line ); | 88 | emit lineFromCommand( Line ); |
85 | Line = ""; | 89 | Line = ""; |
86 | qApp->processEvents(); | 90 | qApp->processEvents(); |
87 | } | 91 | } |
88 | } else { | 92 | } else { |
89 | Line += ch; | 93 | Line += ch; |
90 | } | 94 | } |
91 | } | 95 | } |
92 | 96 | ||
93 | if( ! Line.isEmpty() ) { | 97 | if( ! Line.isEmpty() ) { |
94 | emit lineFromCommand( Line ); | 98 | emit lineFromCommand( Line ); |
95 | Log(( "read cmd output : **%s**\n", Line.latin1() ) ); | 99 | Log(( "read cmd output : **%s**\n", Line.latin1() ) ); |
96 | } | 100 | } |
97 | Log(( "End of command\n", Line.latin1() ) ); | 101 | Log(( "End of command\n", Line.latin1() ) ); |
98 | 102 | ||
99 | if( pclose( OutputOfCmd ) < 0 ) { | 103 | if( pclose( OutputOfCmd ) < 0 ) { |
100 | // error in command | 104 | // error in command |
101 | return 3; | 105 | return 3; |
102 | } | 106 | } |
103 | 107 | ||
104 | // all is fine | 108 | // all is fine |
105 | return 0; | 109 | return 0; |
106 | } | 110 | } |
107 | 111 | ||
108 | void System::refreshStatistics( InterfaceInfo & I ) { | 112 | void System::refreshStatistics( InterfaceInfo & I ) { |
109 | if( ! ProcDevNet ) { | 113 | if( ! ProcDevNet ) { |
110 | return; | 114 | return; |
111 | } | 115 | } |
112 | // cannot seek on dev | 116 | // cannot seek on dev |
113 | ProcDevNet->close(); | 117 | ProcDevNet->close(); |
114 | ProcDevNet->open( IO_ReadOnly ); | 118 | ProcDevNet->open( IO_ReadOnly ); |
115 | 119 | ||
116 | QString line; | 120 | QString line; |
117 | QTextStream procTs(ProcDevNet); | 121 | QTextStream procTs(ProcDevNet); |
118 | QStringList SL; | 122 | QStringList SL; |
119 | int loc = -1; | 123 | int loc = -1; |
120 | int version; | 124 | int version; |
121 | 125 | ||
122 | procTs.readLine(); | 126 | procTs.readLine(); |
123 | line = procTs.readLine(); | 127 | line = procTs.readLine(); |
124 | // get version | 128 | // get version |
125 | if( line.find("compressed") ) | 129 | if( line.find("compressed") ) |
126 | version = 3; | 130 | version = 3; |
127 | else if( line.find( "bytes" ) ) | 131 | else if( line.find( "bytes" ) ) |
128 | version = 2; | 132 | version = 2; |
129 | else | 133 | else |
130 | version = 1; | 134 | version = 1; |
131 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { | 135 | while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { |
132 | if( (loc = line.find(":") ) == -1) { | 136 | if( (loc = line.find(":") ) == -1) { |
133 | continue; | 137 | continue; |
134 | } | 138 | } |
135 | 139 | ||
136 | if( I.Name != line.left(loc) ) | 140 | if( I.Name != line.left(loc) ) |
137 | continue; | 141 | continue; |
138 | 142 | ||
139 | // tokenize | 143 | // tokenize |
140 | SL = QStringList::split( ' ', line, FALSE ); | 144 | SL = QStringList::split( ' ', line, FALSE ); |
141 | 145 | ||
142 | // update data | 146 | // update data |
143 | switch( version ) { | 147 | switch( version ) { |
144 | case 1 : | 148 | case 1 : |
145 | I.RcvBytes = SL[1]; | 149 | I.RcvBytes = SL[1]; |
146 | I.RcvErrors = SL[3]; | 150 | I.RcvErrors = SL[3]; |
147 | I.RcvDropped = SL[4]; | 151 | I.RcvDropped = SL[4]; |
148 | I.SndBytes = SL[6]; | 152 | I.SndBytes = SL[6]; |
149 | I.SndErrors = SL[8]; | 153 | I.SndErrors = SL[8]; |
150 | I.SndDropped = SL[9]; | 154 | I.SndDropped = SL[9]; |
151 | I.Collisions = SL[11]; | 155 | I.Collisions = SL[11]; |
152 | break; | 156 | break; |
153 | case 2 : | 157 | case 2 : |
154 | I.RcvBytes = SL[1]; | 158 | I.RcvBytes = SL[1]; |
155 | I.RcvErrors = SL[3]; | 159 | I.RcvErrors = SL[3]; |