summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.cpp4
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 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <qdir.h>
#include <qregexp.h>
#include <qstringlist.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qapplication.h>
#include "resources.h"
#include "system.h"
#define PROCNETDEV "/proc/net/dev"
+#ifndef ARPHRD_IEEE80211
+#define ARPHRD_IEEE80211 801
+#endif
+
static char Dig2Hex[] = {
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'
};
// get HIGH nibble of byte
#define HN(x) Dig2Hex[(((x)&0xf0)>>4)]
// get LOW nibble of byte
#define LN(x) Dig2Hex[((x)&0x0f)]
System::System( void ) : QObject(), ProbedInterfaces() {
probeInterfaces();
}
System::~System( void ) {
if( ProcDevNet )
delete ProcDevNet;
}
int System::runAsRoot( const QString & S ) {
QString MyS = S;
char * usr = getenv("USER");
char ch;
if( S.isEmpty() ) {
// loophole to start shell
return 8888;
}
if( usr == 0 || strcmp( usr, "root" ) ) {
// unknown or non-root user -> use SUDO
MyS.prepend( "sudo " );
}
Log(("Executing %s\n", MyS.latin1() ));
emit lineFromCommand( tr("Command : ") + MyS );
emit lineFromCommand( "---------------" );
Log(( "Command : %s\n", MyS.latin1() ) );
MyS += " 2>&1 ";
OutputOfCmd = popen( MyS.latin1(), "r" ) ;
if( ! OutputOfCmd ) {
// cannot fork
return 1;
}
// read all data
QString Line = "";
while( 1 ) {
if( fread( &ch, 1, 1, OutputOfCmd ) < 1 )
// eof
break;
if( ch == '\n' || ch == '\r' ) {
if( ! Line.isEmpty() ) {
Log(( "read cmd output : **%s**\n", Line.latin1() ) );
emit lineFromCommand( Line );
Line = "";
qApp->processEvents();
}
} else {
Line += ch;
}
}
if( ! Line.isEmpty() ) {
emit lineFromCommand( Line );
Log(( "read cmd output : **%s**\n", Line.latin1() ) );
}
Log(( "End of command\n", Line.latin1() ) );
if( pclose( OutputOfCmd ) < 0 ) {
// error in command
return 3;
}
// all is fine
return 0;
}
void System::refreshStatistics( InterfaceInfo & I ) {
if( ! ProcDevNet ) {
return;
}
// cannot seek on dev
ProcDevNet->close();
ProcDevNet->open( IO_ReadOnly );
QString line;
QTextStream procTs(ProcDevNet);
QStringList SL;
int loc = -1;
int version;
procTs.readLine();
line = procTs.readLine();
// get version
if( line.find("compressed") )
version = 3;
else if( line.find( "bytes" ) )
version = 2;
else
version = 1;
while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
if( (loc = line.find(":") ) == -1) {
continue;
}
if( I.Name != line.left(loc) )
continue;
// tokenize
SL = QStringList::split( ' ', line, FALSE );
// update data
switch( version ) {
case 1 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[6];
I.SndErrors = SL[8];
I.SndDropped = SL[9];
I.Collisions = SL[11];
break;
case 2 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];