← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~linuxdcpp-team/linuxdcpp/trunk] Rev 374: Fix Socket::resolve in *nix systems

 

------------------------------------------------------------
revno: 374
fixes bug(s): https://launchpad.net/bugs/590359
committer: Razzloss <razzloss@xxxxxxxxx>
branch nick: master
timestamp: Sun 2010-06-06 15:13:09 +0300
message:
  Fix Socket::resolve in *nix systems
modified:
  Changelog.txt
  dcpp/Socket.cpp


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

Your team LinuxDC++ Team is subscribed to branch lp:linuxdcpp.
To unsubscribe from this branch go to https://code.launchpad.net/~linuxdcpp-team/linuxdcpp/trunk/+edit-subscription
=== modified file 'Changelog.txt'
--- Changelog.txt	2010-05-22 14:23:56 +0000
+++ Changelog.txt	2010-06-06 12:13:09 +0000
@@ -51,6 +51,7 @@
 [2010-03-22] Application now registers as the default magnet URI handler on Debian systems. (Steven)
 [2010-04-17] Compilation fixes for OpenSolaris. (thanks Andrew Browne)
 [2010-05-22] lp#317346: Favorite Users tab merged from freedcpp. 
+[2010-06-06] lp#590359: Fix crash with two simultaneous Socket::resolve calls (Razzloss)
 
 *** 1.0.3 2009-02-01 ***
 [2008-08-10] lp#256236: Fixed a crash on startup when using auto-open options.

=== modified file 'dcpp/Socket.cpp'
--- dcpp/Socket.cpp	2009-03-01 05:27:41 +0000
+++ dcpp/Socket.cpp	2010-06-06 12:13:09 +0000
@@ -530,6 +530,7 @@
 }
 
 string Socket::resolve(const string& aDns) {
+#ifdef _WIN32
 	sockaddr_in sock_addr;
 
 	memset(&sock_addr, 0, sizeof(sock_addr));
@@ -548,6 +549,22 @@
 	} else {
 		return aDns;
 	}
+#else
+	// POSIX doesn't guarantee the gethostbyname to be thread safe. And it may (will) return a pointer to static data.
+	string address = Util::emptyString;
+	addrinfo hints = { 0 };
+	addrinfo *result;
+	hints.ai_family = AF_INET;
+
+	if (getaddrinfo(aDns.c_str(), NULL, &hints, &result) == 0) {
+		if (result->ai_addr != NULL)
+			address = inet_ntoa(((sockaddr_in*)(result->ai_addr))->sin_addr);
+
+		freeaddrinfo(result);
+	}
+
+	return address;		
+#endif
 }
 
 string Socket::getLocalIp() throw() {