From 8024e86b5ce80beb2870654cf29308a0f1f208b8 Mon Sep 17 00:00:00 2001 From: Niklas Date: Thu, 1 Sep 2011 16:16:07 +0200 Subject: bigger changes in the checkConnectivity method. using now route command to delete and add the default route. for this i am writing the gateways for every interface into a new file. located at /var/tmp/gateways_ --- LogReceiver/LogReceiver | Bin 122376 -> 130952 bytes LogReceiver/Makefile | 2 +- LogReceiver/logreceiver.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++- LogReceiver/logreceiver.h | 4 +++- 4 files changed, 60 insertions(+), 3 deletions(-) (limited to 'LogReceiver') diff --git a/LogReceiver/LogReceiver b/LogReceiver/LogReceiver index a16897b..21d42f2 100755 Binary files a/LogReceiver/LogReceiver and b/LogReceiver/LogReceiver differ diff --git a/LogReceiver/Makefile b/LogReceiver/Makefile index cd541af..2b6b8c6 100644 --- a/LogReceiver/Makefile +++ b/LogReceiver/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: LogReceiver -# Generated by qmake (2.01a) (Qt 4.7.2) on: Wed Aug 24 10:11:58 2011 +# Generated by qmake (2.01a) (Qt 4.7.2) on: Thu Sep 1 13:01:39 2011 # Project: LogReceiver.pro # Template: app # Command: /usr/local/Trolltech/QtEmbedded-4.7.2/bin/qmake -o Makefile LogReceiver.pro diff --git a/LogReceiver/logreceiver.cpp b/LogReceiver/logreceiver.cpp index 802f442..1256bfe 100644 --- a/LogReceiver/logreceiver.cpp +++ b/LogReceiver/logreceiver.cpp @@ -222,6 +222,60 @@ void LogReceiver::checkInternetConnection(QList &interfaces) { checkInternetConnection(nI); } } + +void LogReceiver::checkConnectivity(QString ifName) { + QString command("route"); + QStringList argList; + QString gateway(" "); + + // get gateway address + QString pathToGatewayFile(DEFAULT_GATEWAY_INFO_LOCATION); + pathToGatewayFile += ifName; + QFile file(pathToGatewayFile); + if(file.exists()) { + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + qDebug() << "couldnt open file:" << pathToGatewayFile; + return; + } + while(!file.atEnd()) { + QString line(file.readLine()); + QStringList gateways = line.split(","); + gateway = gateways.first().trimmed(); + } + } + else { + qDebug() << "file doesn't exist:" << pathToGatewayFile; + return; + } + + // delete default route + argList << "del" << "default"; + QProcess * p = new QProcess(this); + p->start(command, argList); + p->waitForFinished(); + + // add new default route + argList.clear(); + argList << "add" << "default" << "gw" << gateway << ifName; + p = new QProcess(this); + p->start(command, argList); + p->waitForFinished(); + + // check connectivity via tcp connection + QTcpSocket *tcpSocket = new QTcpSocket(this); + tcpSocket->connectToHost(QString("209.85.148.105"), 80); + if (!tcpSocket->waitForConnected(2000)) { + qDebug() << "no internet connection with interface" << ifName; + qDebug() << tcpSocket->errorString(); + emit updateStatusLabel(ifName, "connection not possible"); + } else { + qDebug() << "internet: check passed! for interface" << ifName; + emit + updateStatusLabel(ifName, "connection possible"); + emit connectionEstablished(ifName); + } +} + void LogReceiver::checkInternetConnectionViaTCP(QString ifName) { const bool canStartIAP = (configurationManager.capabilities() @@ -418,7 +472,8 @@ void LogReceiver::handleProcessFinished(int exitCode, emit updateStatusLabel(ifName, "check connectivity"); //checkInternetConnection(ifName); - checkInternetConnectionViaTCP(ifName); + //checkInternetConnectionViaTCP(ifName); + checkConnectivity(ifName); } } QLocalSocket *client = ifNameToClient.value(ifName, 0); diff --git a/LogReceiver/logreceiver.h b/LogReceiver/logreceiver.h index ce6d070..a8572d0 100644 --- a/LogReceiver/logreceiver.h +++ b/LogReceiver/logreceiver.h @@ -16,7 +16,8 @@ class LogReceiver: public QObject { Q_OBJECT #define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default" -#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/workspace/customdhcpcd/src/customdhcpcd" +#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/customdhcpcd/src/customdhcpcd" +#define DEFAULT_GATEWAY_INFO_LOCATION "/var/tmp/gateways_" public: LogReceiver(); @@ -66,6 +67,7 @@ private: void checkInternetConnection(QString ifName); void checkInternetConnection(QList &interfaces); void checkInternetConnectionViaTCP(QString ifName); + void checkConnectivity(QString ifName); QList getListOfNetworkInterfaces(); bool checkBlackList(QString i); -- cgit v1.2.3-55-g7522