From 66bd4a4f1cc9424b3adbd14ca38a9bb6509431df Mon Sep 17 00:00:00 2001 From: Niklas Date: Thu, 18 Aug 2011 14:50:37 +0200 Subject: added internet test. each configured interface will be tested if it is possible to ping the server. --- workspace/LogReceiver/LogReceiver | Bin 74661 -> 82545 bytes workspace/LogReceiver/logreceiver.cpp | 74 ++++++++++++++++++++++------------ workspace/LogReceiver/logreceiver.h | 12 ++++-- 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/workspace/LogReceiver/LogReceiver b/workspace/LogReceiver/LogReceiver index f60254e..e7aff30 100755 Binary files a/workspace/LogReceiver/LogReceiver and b/workspace/LogReceiver/LogReceiver differ diff --git a/workspace/LogReceiver/logreceiver.cpp b/workspace/LogReceiver/logreceiver.cpp index 2f41e08..c5331dc 100644 --- a/workspace/LogReceiver/logreceiver.cpp +++ b/workspace/LogReceiver/logreceiver.cpp @@ -57,7 +57,7 @@ void LogReceiver::initAndRun(QString serverPath, //dhcpcdArguments.append("-d"); QString ifName("eth0"); - runDHCPCD(ifName); + runDHCPCD(list); } void LogReceiver::handleNewConnection() { @@ -192,7 +192,8 @@ void LogReceiver::runDHCPCD(QList &interfaces) { qDebug() << dhcpcdArguments; - clientProcesses.insert(p->pid(),p); + clientProcessToIfNameMap.insert(p, ni.humanReadableName()); + qDebug() << clientProcessToIfNameMap; p->start(pathToDhcpcdExe,dhcpcdArguments); connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), @@ -207,7 +208,8 @@ void LogReceiver::runDHCPCD(QString interface) { qDebug() << dhcpcdArguments; - clientProcesses.insert(p->pid(),p); + clientProcessToIfNameMap.insert(p, interface); + qDebug() << clientProcessToIfNameMap; p->start(pathToDhcpcdExe,dhcpcdArguments); connect(p, SIGNAL(started()), this, SLOT(handleProcessStarted())); connect(p, SIGNAL(finished(int, QProcess::ExitStatus)), @@ -279,24 +281,33 @@ bool LogReceiver::checkCarrierState(QString interface) { return true; } +void LogReceiver::checkInternetConnection(QString ifName) { + QString command("ping"); + QStringList argList; + QString timeout("1"); + QString total("2"); + int exitCode = -1; + QString destination("www.google.de"); + argList << "-I" << "ifName" << "-W" << timeout << "-c" << total + << destination; + argList.replace(1, ifName); + QProcess * p = new QProcess(this); + p->start(command, argList); + p->waitForFinished(); + exitCode = p->exitCode(); + if (exitCode > 0) { + qDebug() << "no internet connection with interface" << ifName; + //remove interface from list and inform user via debug console + } else if (exitCode == 0) { + qDebug() << "internet: check passed! for interface" << ifName; + } +} -void LogReceiver::checkInternetConnection(/*QList &interfaces*/) { - qDebug() << "check internet connection"; - QList allConfigs = manager.allConfigurations(QNetworkConfiguration::Discovered); - foreach(QNetworkConfiguration nC, allConfigs) { - qDebug() << nC.name(); - if(nC.isValid()) { - qDebug() << "config is valid"; - qDebug() << "try to open a new session"; - QNetworkSession session = new QNetworkSession(nC, this); - conntect(session,SIGNAL(error), this, SLOT(handleSessionError())); - conntect(session,SIGNAL(opened), this, SLOT(handleSessionOpened())); - session.open(); - session.waitForOpened(); - - } - } - qDebug() << "check internet connection done"; +void LogReceiver::checkInternetConnection(QList &interfaces) { + foreach(QNetworkInterface ni, interfaces) + { + checkInternetConnection(ni.humanReadableName()); + } } @@ -304,18 +315,29 @@ void LogReceiver::handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus) { QProcess* p = qobject_cast(QObject::sender()); - QProcess * client = clientProcesses.value(p->pid(),0); - if(client <= 0) { - qDebug() << "--- \t [LogReceiver::handleProcessFinished] haven't found process!"; + QString ifName = clientProcessToIfNameMap.value(p,"ifName"); + + if(ifName.compare("ifName") == 0) { + qDebug() << "--- \t [LogReceiver::handleProcessFinished] haven't found process!"; } else { - qDebug() << "process finished: " << client->pid() << exitCode << exitStatus; - checkInternetConnection(); + qDebug() << "process for interface"<< ifName << "finished" << exitCode << exitStatus; + if(exitCode > 0) { + qDebug() << "process exited unexpected"; + } + else { + qDebug() << "process normal exit"; + qDebug() << "check internet connction"; + checkInternetConnection(ifName); + } + } } void LogReceiver::handleProcessStarted() { - qDebug() << "process started: "; + QProcess* p = qobject_cast(QObject::sender()); + QString ifName = clientProcessToIfNameMap.value(p,"ifName"); + qDebug() << "process started for interface:" << ifName; } diff --git a/workspace/LogReceiver/logreceiver.h b/workspace/LogReceiver/logreceiver.h index fb65d58..06a1f3e 100644 --- a/workspace/LogReceiver/logreceiver.h +++ b/workspace/LogReceiver/logreceiver.h @@ -4,6 +4,10 @@ #include #include #include +#include +#include +#include +#include class QLocalServer; class QLocalSocket; @@ -39,17 +43,19 @@ private: QMap interfacesMap; QMap indexToIfaceNameMap; QMap clients; - QMap clientProcesses; + QMap clientProcessToIfNameMap; QString pathToDhcpcdExe; QStringList dhcpcdArguments; - QNetworkConfigurationManager manager; + QNetworkConfigurationManager configurationManager; + QNetworkAccessManager *accessManager; void runDHCPCD(QList &interfaces); void runDHCPCD(QString interface); void checkCarrierState(QList &interfaces); bool checkCarrierState(QString interface); - void checkInternetConnection(/*QList &interfaces*/); + void checkInternetConnection(QString ifName); + void checkInternetConnection(QList &interfaces); QList getListOfNetworkInterfaces(); bool checkBlackList(QString i); -- cgit v1.2.3-55-g7522