← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3382: Correct connecting to IPv6 addresses

 

------------------------------------------------------------
revno: 3382
author: maksis <maksis@xxxxxxxxxxxxxxxxxxxxxx>
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2013-12-10 00:12:01 +0100
message:
  Correct connecting to IPv6 addresses
modified:
  Compile.txt
  changelog.txt
  dcpp/Socket.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'Compile.txt'
--- Compile.txt	2013-12-06 00:08:00 +0000
+++ Compile.txt	2013-12-09 23:12:01 +0000
@@ -7,8 +7,8 @@
 		although I recommend getting them directly from their hosts.
 
 		* A modern C++ compiler. I am currently using these 2 packages by the MinGW-w64 project:
-		- 64-bit: <http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.8.1/threads-win32/seh/>
-		- 32-bit: <http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.1/threads-win32/dwarf/>
+		- 64-bit: <http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.8.2/threads-win32/seh/>
+		- 32-bit: <http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.2/threads-win32/dwarf/>
 
 		Make sure that the compiler's "bin" directory is in your PATH environment variable.
 
@@ -119,8 +119,8 @@
 		be avoided for performance reasons.
 
 		I am currently using these 2 packages by the MinGW-w64 project:
-		- 64-bit: <http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.8.1/threads-win32/seh/>
-		- 32-bit: <http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.1/threads-win32/dwarf/>
+		- 64-bit: <http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.8.2/threads-win32/seh/>
+		- 32-bit: <http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.2/threads-win32/dwarf/>
 
 		To install compilers from regular MinGW (not MinGW-w64), the easiest way is to use
 		mingw-get. Extract it to C:\MinGW and run:

=== modified file 'changelog.txt'
--- changelog.txt	2013-12-09 22:28:12 +0000
+++ changelog.txt	2013-12-09 23:12:01 +0000
@@ -7,6 +7,7 @@
 * [L#210217] Add connectivity status for hubs to the favorite hubs window (ullner)
 * [L#593613] Added /lastmessage in PMs to show the time of the last message (ullner)
 * [L#363092] Disallow transfer port and encrypted transfer port to be the same (ullner)
+* [L#1245179] Correct connecting to IPv6 addresses (maksis)
 
 -- 0.831 2013-11-11 --
 * [L#1249810] Fix NMDC TTH search responses (emtee)

=== modified file 'dcpp/Socket.cpp'
--- dcpp/Socket.cpp	2013-08-08 18:04:01 +0000
+++ dcpp/Socket.cpp	2013-12-09 23:12:01 +0000
@@ -344,22 +344,31 @@
 	// We try to connect to both IPv4 and IPv6 if available
 	auto addr = resolveAddr(aAddr, aPort);
 
+	string lastError;
 	for(auto ai = addr.get(); ai; ai = ai->ai_next) {
 		if((ai->ai_family == AF_INET && !sock4.valid()) ||
 			(ai->ai_family == AF_INET6 && !sock6.valid() && !v4only))
 		{
-			auto sock = create(*ai);
-			auto &localIp = ai->ai_family == AF_INET ? getLocalIp4() : getLocalIp6();
-
-			if(!localPort.empty() || !localIp.empty()) {
-				auto local = resolveAddr(localIp, localPort, ai->ai_family);
-				check([&] { return ::bind(sock, local->ai_addr, local->ai_addrlen); });
+			try {
+				auto sock = create(*ai);
+				auto &localIp = ai->ai_family == AF_INET ? getLocalIp4() : getLocalIp6();
+
+				if(!localPort.empty() || !localIp.empty()) {
+					auto local = resolveAddr(localIp, localPort, ai->ai_family);
+					check([&] { return ::bind(sock, local->ai_addr, local->ai_addrlen); });
+				}
+
+				check([&] { return ::connect(sock, ai->ai_addr, ai->ai_addrlen); }, true);
+				setIp(resolveName(ai->ai_addr, ai->ai_addrlen));
+			} catch(const SocketException& e) {
+				ai->ai_family == AF_INET ? sock4.reset() : sock6.reset();
+				lastError = e.getError();
 			}
-
-			check([&] { return ::connect(sock, ai->ai_addr, ai->ai_addrlen); }, true);
-			setIp(resolveName(ai->ai_addr, ai->ai_addrlen));
 		}
 	}
+
+	if(!lastError.empty())
+		throw SocketException(lastError);
 }
 
 namespace {