summaryrefslogtreecommitdiffstats
path: root/src/networkinterface.cpp
diff options
context:
space:
mode:
authorTimothy Pearson <[email protected]>2011-12-06 14:15:01 -0600
committerTimothy Pearson <[email protected]>2011-12-06 14:15:01 -0600
commit1b89319fd93b88313cab40f1e9de24c067b04efb (patch)
tree80132996de993c3dcab4040864d7729842875b2d /src/networkinterface.cpp
parentd08a0ede1d2cb15bb14b0ff75eacf5c682b1fa0a (diff)
downloadkvpnc-1b89319fd93b88313cab40f1e9de24c067b04efb.tar.gz
kvpnc-1b89319fd93b88313cab40f1e9de24c067b04efb.zip
Initial TQt conversion
Diffstat (limited to 'src/networkinterface.cpp')
-rw-r--r--src/networkinterface.cpp180
1 files changed, 90 insertions, 90 deletions
diff --git a/src/networkinterface.cpp b/src/networkinterface.cpp
index e757339..cddd016 100644
--- a/src/networkinterface.cpp
+++ b/src/networkinterface.cpp
@@ -20,14 +20,14 @@
//BEGIN INCLUDES
#include "networkinterface.h"
#include <iostream>
-#include <qfile.h>
-#include <qtextstream.h>
+#include <tqfile.h>
+#include <tqtextstream.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kglobal.h>
#include <kstddirs.h>
-#include <qnetwork.h>
-#include <qurloperator.h>
+#include <tqnetwork.h>
+#include <tqurloperator.h>
#include <kmessagebox.h>
#include <arpa/inet.h>
#include <linux/sockios.h>
@@ -35,22 +35,22 @@
#include <sys/ioctl.h>
//END INCLUDES
-NetworkInterface::NetworkInterface( KVpncConfig* GlobalConfig,QApplication *app, QObject *parent, const char *name ) : QObject( parent, name )
+NetworkInterface::NetworkInterface( KVpncConfig* GlobalConfig,TQApplication *app, TQObject *parent, const char *name ) : TQObject( parent, name )
{
this->app = app;
interfaceTest = false;
retrieveInterfaceAddress = false;
- QPtrList<QString>*InterfaceList = new QPtrList<QString>();
+ TQPtrList<TQString>*InterfaceList = new TQPtrList<TQString>();
InterfaceList->setAutoDelete( TRUE ); // the list owns the objects
- QString InterfaceIP = "";
- QString InterfaceAddress = "";
+ TQString InterfaceIP = "";
+ TQString InterfaceAddress = "";
IPforInterface = "";
tmpInterface = "";
interfaceExists = false;
defaultinterface="default";
readOutput=false;
- env = new QStringList();
+ env = new TQStringList();
*env << "LC_ALL=C" << "LANG=C" << "PATH=/bin:/usr/bin:/usr/sbin:/sbin";
this->GlobalConfig = GlobalConfig;
}
@@ -62,21 +62,21 @@ NetworkInterface::~NetworkInterface()
defaultinterface == "";
}
-bool NetworkInterface::interfaceExist( QString Interface )
+bool NetworkInterface::interfaceExist( TQString Interface )
{
if ( !Interface.isEmpty() )
{
- QFile NetdevFile( "/proc/net/dev" );
- QTextStream stream ( &NetdevFile );
+ TQFile NetdevFile( "/proc/net/dev" );
+ TQTextStream stream ( &NetdevFile );
if ( NetdevFile.open ( IO_ReadOnly ) )
{
- QString line = "";
+ TQString line = "";
while ( !stream.atEnd() )
{
line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank
if ( line.find ( ':' ) > -1 )
{
- QString tmpdev = line.section( ':', 0, 0 ).stripWhiteSpace();
+ TQString tmpdev = line.section( ':', 0, 0 ).stripWhiteSpace();
if ( tmpdev == Interface )
{
NetdevFile.close();
@@ -90,13 +90,13 @@ bool NetworkInterface::interfaceExist( QString Interface )
return false;
}
-QStringList NetworkInterface::getAllNetworkInterfaces()
+TQStringList NetworkInterface::getAllNetworkInterfaces()
{
- QFile NetdevFile( "/proc/net/dev" );
- QTextStream stream ( &NetdevFile );
+ TQFile NetdevFile( "/proc/net/dev" );
+ TQTextStream stream ( &NetdevFile );
if ( NetdevFile.open ( IO_ReadOnly ) )
{
- QString line = "";
+ TQString line = "";
while ( !stream.atEnd() )
{
line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank
@@ -111,14 +111,14 @@ QStringList NetworkInterface::getAllNetworkInterfaces()
return InterfaceList;
}
-QString NetworkInterface::getInterfaceIP( QString Interface )
+TQString NetworkInterface::getInterfaceIP( TQString Interface )
{
//FIXME why this dont work on ppp0 device of l2tp tunnel?
// if ( !Interface.isEmpty() )
// {
// int fd=-1;
-// QString tmpip="";
+// TQString tmpip="";
// struct ifreq ifr;
// fd = socket(AF_INET, SOCK_STREAM, 0);
// if (fd >= 0){
@@ -129,22 +129,22 @@ QString NetworkInterface::getInterfaceIP( QString Interface )
// return tmpip;
// }
// else
-// return QString("");
+// return TQString("");
// }
// else
-// return QString("");
+// return TQString("");
// }
// else
-// return QString("");
+// return TQString("");
return getInterfaceIP2(Interface);
}
-QString NetworkInterface::getInterfaceIP2( QString Interface )
+TQString NetworkInterface::getInterfaceIP2( TQString Interface )
{
if ( !Interface.isEmpty() )
{
- InterfaceIpProc = new QProcess(this);
+ InterfaceIpProc = new TQProcess(this);
InterfaceIpProc->addArgument( GlobalConfig->pathToIp );
InterfaceIpProc->addArgument("addr");
InterfaceIpProc->addArgument("show");
@@ -153,13 +153,13 @@ QString NetworkInterface::getInterfaceIP2( QString Interface )
retrieveInterfaceIP=true;
readOutput=true;
- connect( InterfaceIpProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_interfaceip() ) );
- connect( InterfaceIpProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_interfaceip() ) );
- connect( InterfaceIpProc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) );
+ connect( InterfaceIpProc, TQT_SIGNAL( readyReadStdout() ), this, TQT_SLOT( readFromStdout_interfaceip() ) );
+ connect( InterfaceIpProc, TQT_SIGNAL( readyReadStderr() ), this, TQT_SLOT( readFromStderr_interfaceip() ) );
+ connect( InterfaceIpProc, TQT_SIGNAL( processExited () ), this, TQT_SLOT( processHasFinished() ) );
if ( !InterfaceIpProc->start(env) )
{
- GlobalConfig->appendLogEntry(i18n("unable to start proc (%1)!").arg(i18n("getting IP address from interface")), KVpncConfig::error);
+ GlobalConfig->appendLogEntry(i18n("unable to start proc (%1)!").tqarg(i18n("getting IP address from interface")), KVpncConfig::error);
}
else
{
@@ -173,9 +173,9 @@ QString NetworkInterface::getInterfaceIP2( QString Interface )
while ( readOutput)
GlobalConfig->appPointer->processEvents();*/
}
- disconnect( InterfaceIpProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_interfaceip() ) );
- disconnect( InterfaceIpProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_interfaceip() ) );
- disconnect( InterfaceIpProc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) );
+ disconnect( InterfaceIpProc, TQT_SIGNAL( readyReadStdout() ), this, TQT_SLOT( readFromStdout_interfaceip() ) );
+ disconnect( InterfaceIpProc, TQT_SIGNAL( readyReadStderr() ), this, TQT_SLOT( readFromStderr_interfaceip() ) );
+ disconnect( InterfaceIpProc, TQT_SIGNAL( processExited () ), this, TQT_SLOT( processHasFinished() ) );
delete InterfaceIpProc;
InterfaceIpProc=0L;
}
@@ -183,20 +183,20 @@ QString NetworkInterface::getInterfaceIP2( QString Interface )
}
-QString NetworkInterface::getInterfaceAddress( QString IPforInterface )
+TQString NetworkInterface::getInterfaceAddress( TQString IPforInterface )
{
/*
// TODO fixme
if ( !IPforInterface.isEmpty() )
{
this->IPforInterface = IPforInterface;
- QStringList devlist = getAllNetworkInterfaces();
+ TQStringList devlist = getAllNetworkInterfaces();
tmpfile = new KTempFile();
- QString tmpPath = locateLocal ( "data", "kvpnc/" );
- QString GetIpForInterfaceScript = tmpPath + "get_interface_for_ip_"+IPforInterface+".sh";
+ TQString tmpPath = locateLocal ( "data", "kvpnc/" );
+ TQString GetIpForInterfaceScript = tmpPath + "get_interface_for_ip_"+IPforInterface+".sh";
- QFile file ( GetIpForInterfaceScript );
- QTextStream stream( &file );
+ TQFile file ( GetIpForInterfaceScript );
+ TQTextStream stream( &file );
if ( file.open( IO_WriteOnly ) )
{
stream << "# generated by kvpnc. Do not edit it." << "\n";
@@ -206,20 +206,20 @@ QString NetworkInterface::getInterfaceAddress( QString IPforInterface )
- InterfaceAddressProc = new QProcess(this);
+ InterfaceAddressProc = new TQProcess(this);
InterfaceAddressProc->addArgument( GlobalConfig->InterpreterShell );
InterfaceAddressProc->addArgument(GetIpForInterfaceScript);
retrieveInterfaceAddress=true;
readOutput=true;
- //connect( InterfaceAddressProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_interfaceaddress() ) );
- // connect( InterfaceAddressProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_interfaceaddress() ) );
- connect( InterfaceAddressProc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) );
+ //connect( InterfaceAddressProc, TQT_SIGNAL( readyReadStdout() ), this, TQT_SLOT( readFromStdout_interfaceaddress() ) );
+ // connect( InterfaceAddressProc, TQT_SIGNAL( readyReadStderr() ), this, TQT_SLOT( readFromStderr_interfaceaddress() ) );
+ connect( InterfaceAddressProc, TQT_SIGNAL( processExited () ), this, TQT_SLOT( processHasFinished() ) );
if ( !InterfaceAddressProc->start(env) )
{
- GlobalConfig->appendLogEntry(i18n("unable to start proc (%1)!").arg(i18n("script for get interface from IP address")), KVpncConfig::error);
+ GlobalConfig->appendLogEntry(i18n("unable to start proc (%1)!").tqarg(i18n("script for get interface from IP address")), KVpncConfig::error);
}
else
@@ -236,9 +236,9 @@ QString NetworkInterface::getInterfaceAddress( QString IPforInterface )
// GlobalConfig->appPointer->processEvents();
}
- // disconnect( InterfaceAddressProc, SIGNAL( readyReadStdout() ), this, SLOT( readFromStdout_interfaceaddress() ) );
- // disconnect( InterfaceAddressProc, SIGNAL( readyReadStderr() ), this, SLOT( readFromStderr_interfaceaddress() ) );
- disconnect( InterfaceAddressProc, SIGNAL( processExited () ), this, SLOT( processHasFinished() ) );
+ // disconnect( InterfaceAddressProc, TQT_SIGNAL( readyReadStdout() ), this, TQT_SLOT( readFromStdout_interfaceaddress() ) );
+ // disconnect( InterfaceAddressProc, TQT_SIGNAL( readyReadStderr() ), this, TQT_SLOT( readFromStderr_interfaceaddress() ) );
+ disconnect( InterfaceAddressProc, TQT_SIGNAL( processExited () ), this, TQT_SLOT( processHasFinished() ) );
//delete InterfaceAddressProc;
}
}
@@ -247,12 +247,12 @@ QString NetworkInterface::getInterfaceAddress( QString IPforInterface )
if ( !IPforInterface.isEmpty() )
{
this->IPforInterface = IPforInterface;
- QStringList devlist = getAllNetworkInterfaces();
+ TQStringList devlist = getAllNetworkInterfaces();
if (!devlist.isEmpty())
{
- for ( QStringList::Iterator it = devlist.begin(); it != devlist.end(); ++it ) {
+ for ( TQStringList::Iterator it = devlist.begin(); it != devlist.end(); ++it ) {
if (getInterfaceIP(*it) == IPforInterface)
- return QString(*it);
+ return TQString(*it);
}
}
else
@@ -263,14 +263,14 @@ QString NetworkInterface::getInterfaceAddress( QString IPforInterface )
}
-QString NetworkInterface::getNetmaskOfInterface(QString interface)
+TQString NetworkInterface::getNetmaskOfInterface(TQString interface)
{
- QFile NetRouteFile ( "/proc/net/route" );
- QTextStream stream ( &NetRouteFile );
- QString tmpmask;
+ TQFile NetRouteFile ( "/proc/net/route" );
+ TQTextStream stream ( &NetRouteFile );
+ TQString tmpmask;
if ( NetRouteFile .open ( IO_ReadOnly ) )
{
- QString line = "";
+ TQString line = "";
while ( !stream.atEnd() )
{
line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank
@@ -293,18 +293,18 @@ QString NetworkInterface::getNetmaskOfInterface(QString interface)
return "0.0.0.0";
}
-QString NetworkInterface::getDefaultInterface()
+TQString NetworkInterface::getDefaultInterface()
{
- QFile NetRouteFile ( "/proc/net/route" );
- QTextStream stream ( &NetRouteFile );
- QString tmpdev;
+ TQFile NetRouteFile ( "/proc/net/route" );
+ TQTextStream stream ( &NetRouteFile );
+ TQString tmpdev;
if ( NetRouteFile .open ( IO_ReadOnly ) )
{
- QString line = "";
+ TQString line = "";
while ( !stream.atEnd() )
{
line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank
- QString tmptarget = line.simplifyWhiteSpace().section( ' ', 1, 1 ); // return the value of the target which is 0.0.0.0
+ TQString tmptarget = line.simplifyWhiteSpace().section( ' ', 1, 1 ); // return the value of the target which is 0.0.0.0
if ( tmptarget == "00000000" )
{
tmpdev = line.simplifyWhiteSpace().section( ' ', 0, 0 ); // return the value of the target which is 0.0.0.0
@@ -320,16 +320,16 @@ QString NetworkInterface::getDefaultInterface()
int NetworkInterface::getDefaultRouteCount()
{
- QFile NetRouteFile ( "/proc/net/route" );
- QTextStream stream ( &NetRouteFile );
+ TQFile NetRouteFile ( "/proc/net/route" );
+ TQTextStream stream ( &NetRouteFile );
int defaultroutecount=0;
if ( NetRouteFile .open ( IO_ReadOnly ) )
{
- QString line = "";
+ TQString line = "";
while ( !stream.atEnd() )
{
line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank
- QString tmptarget = line.simplifyWhiteSpace().section( ' ', 1, 1 ); // return the value of the target which is 0.0.0.0
+ TQString tmptarget = line.simplifyWhiteSpace().section( ' ', 1, 1 ); // return the value of the target which is 0.0.0.0
if ( tmptarget == "00000000" )
defaultroutecount++;
}
@@ -339,14 +339,14 @@ int NetworkInterface::getDefaultRouteCount()
return defaultroutecount;
}
-QString NetworkInterface::getGatewayOfInterface(QString interface)
+TQString NetworkInterface::getGatewayOfInterface(TQString interface)
{
- QFile NetRouteFile ( "/proc/net/route" );
- QTextStream stream ( &NetRouteFile );
- QString tmpgw;
+ TQFile NetRouteFile ( "/proc/net/route" );
+ TQTextStream stream ( &NetRouteFile );
+ TQString tmpgw;
if ( NetRouteFile .open ( IO_ReadOnly ) )
{
- QString line = "";
+ TQString line = "";
while ( !stream.atEnd() )
{
line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank
@@ -367,14 +367,14 @@ QString NetworkInterface::getGatewayOfInterface(QString interface)
return "0.0.0.0";
}
-QString NetworkInterface::getGatewayOfDefaultInterface()
+TQString NetworkInterface::getGatewayOfDefaultInterface()
{
- QFile NetRouteFile ( "/proc/net/route" );
- QTextStream stream ( &NetRouteFile );
- QString tmpgw;
+ TQFile NetRouteFile ( "/proc/net/route" );
+ TQTextStream stream ( &NetRouteFile );
+ TQString tmpgw;
if ( NetRouteFile .open ( IO_ReadOnly ) )
{
- QString line = "";
+ TQString line = "";
while ( !stream.atEnd() )
{
line = stream.readLine(); // line of text excluding '\n' and replace all white chars with one blank
@@ -385,7 +385,7 @@ QString NetworkInterface::getGatewayOfDefaultInterface()
bool ok=true;
// std::cout << "gateway of default interface " << ": " << line.simplifyWhiteSpace().section( ' ', 2, 2 ).ascii() << "\n";
name.sin_addr.s_addr = line.simplifyWhiteSpace().section( ' ', 2, 2 ).toUInt(&ok,16);
-// std::cout << "s_addr: " << QString().setNum(line.simplifyWhiteSpace().section( ' ', 2, 2 ).stripWhiteSpace().toUInt(&ok,16)) << std::endl;
+// std::cout << "s_addr: " << TQString().setNum(line.simplifyWhiteSpace().section( ' ', 2, 2 ).stripWhiteSpace().toUInt(&ok,16)) << std::endl;
tmpgw = inet_ntoa(name.sin_addr); // return the value of the gateway
NetRouteFile .close();
// std::cout << "gateway of default interface (ascii)" << ": " << tmpgw<< "\n";
@@ -402,13 +402,13 @@ QString NetworkInterface::getGatewayOfDefaultInterface()
return "";
}
-QString NetworkInterface::getExternalIpAddress()
+TQString NetworkInterface::getExternalIpAddress()
{
qInitNetworkProtocols();
ExternalIpAddress="";
getExternalIpAddressRunning=true;
- http = new QHttp();
- connect (http,SIGNAL(readyRead(const QHttpResponseHeader &)), this, SLOT(externalIpDataRecieved(const QHttpResponseHeader &)));
+ http = new TQHttp();
+ connect (http,TQT_SIGNAL(readyRead(const TQHttpResponseHeader &)), this, TQT_SLOT(externalIpDataRecieved(const TQHttpResponseHeader &)));
// FIXME how it could be better?
http->setHost( "checkip.dyndns.org" );
@@ -424,7 +424,7 @@ QString NetworkInterface::getExternalIpAddress()
return ExternalIpAddress;
}
-bool NetworkInterface::inSameNetwork(QString ip1,QString Netmask1,QString ip2,QString Netmask2)
+bool NetworkInterface::inSameNetwork(TQString ip1,TQString Netmask1,TQString ip2,TQString Netmask2)
{
// FIXME add valid ipv4 ip check
// FIXME add netmask check (subnetworks!)
@@ -456,8 +456,8 @@ void NetworkInterface::readFromStdout()
{
while ( proc->canReadLineStdout() )
{
- QString line = proc->readLineStdout() ;
- // QString line = QString(proc->readStdout());
+ TQString line = proc->readLineStdout() ;
+ // TQString line = TQString(proc->readStdout());
/*
@@ -490,8 +490,8 @@ void NetworkInterface::readFromStdout()
void NetworkInterface::readFromStderr()
{
//while ( proc->canReadLineStderr() ) {
- // QString line = proc->readLineStderr() ;
- QString line = QString( proc->readStderr() );
+ // TQString line = proc->readLineStderr() ;
+ TQString line = TQString( proc->readStderr() );
if ( interfaceTest )
{
@@ -510,7 +510,7 @@ void NetworkInterface::processHasFinished()
if (retrieveInterfaceAddress )
{
// std::cout << "tmp file: " << tmpfile->name() << std::endl;
- InterfaceAddress = QString(tmpfile->file()->readAll()).stripWhiteSpace();
+ InterfaceAddress = TQString(tmpfile->file()->readAll()).stripWhiteSpace();
// KMessageBox::information( 0,this->defaultinterface,"default if");
// tmpfile->unlink();
retrieveInterfaceAddress=false;
@@ -522,9 +522,9 @@ void NetworkInterface::processHasFinished()
readOutput=false;
}
-void NetworkInterface::externalIpDataRecieved(const QHttpResponseHeader &)
+void NetworkInterface::externalIpDataRecieved(const TQHttpResponseHeader &)
{
- ExternalIpAddress=QString(http->readAll()).stripWhiteSpace().remove ("Current IP Address: ").stripWhiteSpace();
+ ExternalIpAddress=TQString(http->readAll()).stripWhiteSpace().remove ("Current IP Address: ").stripWhiteSpace();
getExternalIpAddressRunning=false;
}
@@ -532,8 +532,8 @@ void NetworkInterface::readFromStdout_interfaceip()
{
while ( InterfaceIpProc && InterfaceIpProc->canReadLineStdout() )
{
- QString line = InterfaceIpProc->readLineStdout() ;
- // QString line = QString(InterfaceIpProc->readStdout());
+ TQString line = InterfaceIpProc->readLineStdout() ;
+ // TQString line = TQString(InterfaceIpProc->readStdout());
if (line.find( "inet ", 0 , FALSE ) != -1 )
{
@@ -550,8 +550,8 @@ void NetworkInterface::readFromStderr_interfaceip()
{
while ( InterfaceIpProc && InterfaceIpProc->canReadLineStderr() )
{
- QString line = InterfaceIpProc->readLineStderr() ;
- // QString line = QString( InterfaceIpProc->readStderr() );
+ TQString line = InterfaceIpProc->readLineStderr() ;
+ // TQString line = TQString( InterfaceIpProc->readStderr() );
if ( interfaceTest )
{