[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/network/kvpnc
From:       Christoph Thielecke <christoph.thielecke () gmx ! de>
Date:       2008-05-21 7:48:51
Message-ID: 1211356131.027618.21956.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 810631 by crissi:

detecing gw ip of default interface fixed

 M  +1 -0      ChangeLog  
 M  +13 -2     src/kvpnc.cpp  
 M  +31 -8     src/networkinterface.cpp  
 M  +2 -0      src/networkinterface.h  


--- trunk/playground/network/kvpnc/ChangeLog #810630:810631
@@ -2,6 +2,7 @@
 	interface combobox now editable in addnetworkroute dialog
 	description fixed on openvpn import
 	todo updated
+	detecing gw ip of default interface fixed
 
 2008-05-20 Christoph Thielecke <crissi99@gmx.de>
 	cert import fixed
--- trunk/playground/network/kvpnc/src/kvpnc.cpp #810630:810631
@@ -4672,6 +4672,11 @@
 
 			GlobalConfig->OldDefaultDev =  iface.getDefaultInterface();
 			GlobalConfig->OldDefaultGw = iface.getGatewayOfDefaultInterface();
+
+			if ( GlobalConfig->KvpncDebugLevel > 3 )
+				GlobalConfig->appendLogEntry ( i18n ( "Old default device: %1, old default gw: \
%2" ).arg (GlobalConfig->OldDefaultDev  ).arg(GlobalConfig->OldDefaultGw), \
GlobalConfig->debug ); +
+
 			
 			OldDefaultroute = tmpPath + "default-route." + \
GlobalConfig->currentProfile->getName(); // default-route.<id>  PptpGateway = tmpPath \
+ "gateway." + GlobalConfig->currentProfile->getName(); // gateway.<id> @@ -10535,9 \
+10540,15 @@  
 				if ( GlobalConfig->currentProfile->getReplaceDefaultRoute() )
 				{
-					pppdupstream << GlobalConfig->pathToIp + " route add " + \
GlobalConfig->currentProfile->getGateway() + "/32 via " << GlobalConfig->OldDefaultGw \
                << " dev " << GlobalConfig->OldDefaultDev << "\n";
-					if ( ! pppdHasReplacedefaultrouteSupport && \
GlobalConfig->currentProfile->getReplaceDefaultRoute() ) +					if ( ! \
pppdHasReplacedefaultrouteSupport ) +					{
 						pppdupstream << GlobalConfig->pathToIp + " route replace default dev " + \
pppdev + "\n"; +					}
+						if ( GlobalConfig->KvpncDebugLevel > 3 )
+							GlobalConfig->appendLogEntry ( i18n ( "Setting extra route: %1 over %2 gw %3" \
).arg ( GlobalConfig->currentProfile->getGateway() \
).arg(GlobalConfig->OldDefaultDev).arg( GlobalConfig->OldDefaultGw), \
GlobalConfig->debug ); +
+
+						pppdupstream << GlobalConfig->pathToIp + " route add " + \
GlobalConfig->currentProfile->getGateway() + "/32 via " << GlobalConfig->OldDefaultGw \
<< " dev " << GlobalConfig->OldDefaultDev << "\n";  }
 
 				if ( !TmpDns1.isEmpty() && !TmpDns2.isEmpty() )
--- trunk/playground/network/kvpnc/src/networkinterface.cpp #810630:810631
@@ -293,7 +293,7 @@
 				struct sockaddr_in name;
 				bool ok=true;
 // 				std::cout << "gateway of interface "<< interface.ascii() << ": " << \
                line.simplified().section( ' ', 2, 2 ).ascii() << "\n";
-				name.sin_addr.s_addr = line.simplified().section( ' ', 2, 2 ).toInt(&ok,16);
+				name.sin_addr.s_addr = line.simplified().section( ' ', 2, 2 ).toUInt(&ok,16);
 				tmpgw = inet_ntoa(name.sin_addr); // return the value of the gateway
 				NetRouteFile .close();
 				return tmpgw;
@@ -308,29 +308,52 @@
 QString NetworkInterface::getGatewayOfDefaultInterface()
 {
 	QFile NetRouteFile ( "/proc/net/route" );
-	Q3TextStream stream ( &NetRouteFile );
+	QTextStream stream ( &NetRouteFile );
 	QString tmpgw;
-	if ( NetRouteFile .open( QIODevice::ReadOnly ) ) {
+	if ( NetRouteFile .open( IO_ReadOnly ) ) {
 		QString line = "";
 		while ( !stream.atEnd() ) {
 			line = stream.readLine(); // line of text excluding '\n' and replace all white \
                chars with one blank
-			if (line.simplified().section( ' ', 1, 1 ) == "00000000" )
+			std::cout << "line: \"" << qPrintable(line) << "\"" << "\n";
+			if (line.simplifyWhiteSpace().section( ' ', 1, 1 ) == "00000000" )
 			{
 					struct sockaddr_in name;
 					bool ok=true;
-// 					std::cout << "gateway of default interface " << ": " << \
                line.simplified().section( ' ', 2, 2 ).ascii() << "\n";
-					name.sin_addr.s_addr = line.simplified().section( ' ', 2, 2 ).toInt(&ok,16);
+// 					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: " << \
qPrintable(QString().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";
+// 					std::cout << "gateway of default interface (ascii)" << ": " << \
qPrintable(tmpgw) << "\n";  return tmpgw;
 			}
 		}
+		NetRouteFile .close();
 	}
-	NetRouteFile .close();
+	else
+	{
+		std::cerr << "/proc/net/route cant be opened" << std::endl;
+	}
+	
 	return "";
 }
 
+bool NetworkInterface::inSameNetwork(QString ip1,QString ip2)
+{
+	// FIXME add valid ipv4 ip check
+	// FIXME add netmask check (subnetworks!)
+	if (ip1==ip2)
+		return true;
+	else
+	{
+		if (ip1.section( '.', 1, 3 ).toInt() == ip1.section( '.', 1, 3 ))
+			return true;
+		else
+			return false;
+
+	}
+}
+
 QString  NetworkInterface::getExternalIpAddress()
 {
 	q3InitNetworkProtocols();
--- trunk/playground/network/kvpnc/src/networkinterface.h #810630:810631
@@ -106,6 +106,8 @@
 	 */
 	QString  getExternalIpAddress();
 
+	bool inSameNetwork(QString ip1,QString ip2);
+
 public slots:
 	void readFromStdout();
 	void readFromStderr();


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic