/* * Localwebfaker - Web sites faker for LAN * Copyright (C) 2007-2009 Lucas J. González * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see #include #include #include tcpD::tcpD (QString inInterfaz, QString inCliente ) { QString( interfaz ) ; QString( cliente ) ; this->interfaz = inInterfaz ; this->cliente = inCliente ; this->result = new( QByteArray ) ; this->proceder = true ; } void tcpD::run() { this->tcpdump = new QProcess() ; connect(tcpdump, SIGNAL(error( QProcess::ProcessError)), this, SLOT(tcpdumpPrintStderr(QProcess::ProcessError)),Qt::DirectConnection ) ; connect(tcpdump, SIGNAL(readyReadStandardError() ), this, SLOT(tcpdumpPrintStderr()),Qt::DirectConnection ) ; connect(tcpdump, SIGNAL(readyReadStandardOutput() ), this, SLOT(extraeResolver()),Qt::DirectConnection ) ; connect(tcpdump, SIGNAL(started()), this, SLOT(inicioTcpdump() ),Qt::DirectConnection ) ; QString( comando ) ; comando.append( "tcpdump -n -l -f -i " ) ; comando.append( interfaz ) ; comando.append( " host " ) ; comando.append( cliente ) ; comando.append( " && dst port 53" ) ; tcpdump->start( comando ) ; if (!tcpdump->waitForStarted() ) { qFatal( "Config::resolvConfig(): Could not start tcpdump" ) ; } QEventLoop *eventloop = new QEventLoop() ; eventloop->exec() ; exec(); } void tcpD::tcpdumpPrintStdout() { *result = this->tcpdump->readAllStandardOutput() ; std::cout << "stdout from tcpdump:" << std::endl ; std::cout << result->data() << std::endl ; emit newTcpDOutput( QString(*result) ) ; } void tcpD::tcpdumpPrintStderr() { *result = this->tcpdump->readAllStandardError() ; std::cout << "stderr from tcpdump:" << std::endl ; std::cout << result->data() << std::endl ; emit newTcpDOutput( QString(*result) ) ; } void tcpD::tcpdumpPrintStderr(QProcess::ProcessError error) { *result = this->tcpdump->readAllStandardError() ; std::cout << "Lines from tcpdump:" << std::endl ; std::cout << result->data() << "Error: " << error << std::endl ; } void tcpD::inicioTcpdump() { } void tcpD::pararTcpdump() { std::cout << "Restoring: tcpdump" << std::endl ; this->tcpdump->terminate() ; } void tcpD::extraeResolver() { if ( proceder ) { proceder = false ; *result = this->tcpdump->readAllStandardOutput() ; QList trozos = result->split ( '>' ) ; QList::iterator iter ; QString( ipResolv ) ; trozos.removeFirst() ; *result = trozos.first() ; trozos = result->split( '.' ) ; int i ; for( i=0 ; i< 4 ; i++ ) { ipResolv.append( trozos.takeFirst().data() ) ; if (i != 3) ipResolv.append( "." ) ; } emit gotResolver( ipResolv ) ; this->tcpdump->kill() ; terminate() ; } } void tcpD::kill() { this->tcpdump->kill(); }