From d3612f403d0122a6929837764fad849634b26e1b Mon Sep 17 00:00:00 2001 From: Niklas Date: Tue, 20 Sep 2011 16:46:11 +0200 Subject: the checkConnectivity method is working now. we use the rtnl functions of the libnl. --- LogReceiver/logreceiver.cpp | 111 ++------------------------------------------ 1 file changed, 4 insertions(+), 107 deletions(-) (limited to 'LogReceiver/logreceiver.cpp') diff --git a/LogReceiver/logreceiver.cpp b/LogReceiver/logreceiver.cpp index 8dc2938..b034013 100644 --- a/LogReceiver/logreceiver.cpp +++ b/LogReceiver/logreceiver.cpp @@ -179,45 +179,7 @@ void LogReceiver::runDHCPCD(QString interface) { dhcpcdArguments.removeLast(); } -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 - emit updateStatusLabel(ifName, "connection not possible"); - } else if (exitCode == 0) { - qDebug() << "internet: check passed! for interface" << ifName; - emit - updateStatusLabel(ifName, "connection possible"); - emit connectionEstablished(ifName, ""); - } -} - -void LogReceiver::checkInternetConnection(QList &interfaces) { - foreach(QString nI, interfaces) - { - checkInternetConnection(nI); - } -} - void LogReceiver::checkConnectivity(QString ifName) { - QString command("route"); - QStringList argList; - QString gateway(" "); - QByteArray ba; - struct in_addr destination, netmask, gw; int metric = 0; // get gateway address @@ -226,37 +188,13 @@ void LogReceiver::checkConnectivity(QString ifName) { interfaceconfiguration ifConf; ifConf.readConfigOutOfFile(pathToGatewayFile); - // delete default route - ba = ifName.toAscii(); - char *ifname = ba.data(); - inet_aton("0.0.0.0", &destination); - inet_aton("0.0.0.0", &netmask); - ba = ifConf.getGateway().toAscii(); - const char * gwaddr = ba.data(); - inet_aton(gwaddr,&gw); - //del_route(ifname, destination, netmask, gw, metric); - - QProcess * p = new QProcess(this); - /* - argList << "del" << "default"; - - p->start(command, argList); - p->waitForFinished(); - */ - // add new default route - argList.clear(); - qDebug() << "add default route with:" << ifConf.getGateway() - << ifConf.getInterface(); - argList << "add" << "default" << "gw" << ifConf.getGateway() - << ifConf.getInterface(); - p = new QProcess(this); - p->start(command, argList); - p->waitForFinished(); + // replace default route + qDebug() << rm.replaceDefaultRoute(ifName, ifConf.getGateway(), 0, AF_INET); // check connectivity via tcp connection QTcpSocket *tcpSocket = new QTcpSocket(this); tcpSocket->connectToHost(QString("209.85.148.105"), 80); - if (!tcpSocket->waitForConnected(2000)) { + if (!tcpSocket->waitForConnected(500)) { qDebug() << "no internet connection with interface" << ifName; qDebug() << tcpSocket->errorString(); emit updateStatusLabel(ifName, "connection not possible"); @@ -264,51 +202,10 @@ void LogReceiver::checkConnectivity(QString ifName) { qDebug() << "internet: check passed! for interface" << ifName; emit updateStatusLabel(ifName, "connection possible"); - emit connectionEstablished(ifName, gateway); + emit connectionEstablished(ifName, ifConf.getGateway()); } } -void LogReceiver::checkInternetConnectionViaTCP(QString ifName) { -/* - bool canStartIAP = (configurationManager.capabilities() - & QNetworkConfigurationManager::CanStartAndStopInterfaces); - QList configs = - configurationManager.allConfigurations(); - QNetworkConfiguration cfg; - foreach(QNetworkConfiguration nC, configs) - { - if (nC.name() == ifName) { - qDebug() << "found config" << nC.name(); - cfg = nC; - break; - } - } - if (!cfg.isValid() || (!canStartIAP && cfg.state() - != QNetworkConfiguration::Active)) { - qDebug() << "config is not valid" << cfg.name(); - return; - } - QNetworkSession *session = new QNetworkSession(cfg, this); - session->open(); - if (session->waitForOpened(-1)) { - - qDebug() << "used interface for connectivity check:" - << session->interface().humanReadableName(); - QTcpSocket *tcpSocket = new QTcpSocket(this); - tcpSocket->connectToHost(QString("209.85.148.105"), 80); - if (!tcpSocket->waitForConnected(2000)) { - qDebug() << tcpSocket->errorString(); - emit updateStatusLabel(ifName, "connection not possible"); - } else { - emit updateStatusLabel(ifName, "connection possible"); - emit connectionEstablished(ifName, ""); - } - } else { - qDebug() << "couldn't open session"; - } - session->close(); - */ -} /** * -- cgit v1.2.3-55-g7522