linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #01278
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2156: Fix Socket::resolve in *nix systems
------------------------------------------------------------
revno: 2156
fixes bug(s): https://launchpad.net/bugs/590359
committer: Razzloss <razzloss@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Sun 2010-06-06 14:52:52 +0300
message:
Fix Socket::resolve in *nix systems
modified:
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 'dcpp/Socket.cpp'
--- dcpp/Socket.cpp 2010-02-11 21:44:13 +0000
+++ dcpp/Socket.cpp 2010-06-06 11:52:52 +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.
+ struct addrinfo hints, *result;
+ string address = Util::emptyString;
+ memset(&hints, 0, sizeof(struct addrinfo));
+ 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() {