summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-01-21 15:32:58 -0500
committerAaron <aaron@10gen.com>2009-01-21 15:32:58 -0500
commit9a36738d0c62e7a6d5950d0495e30f8c41f23e96 (patch)
tree23956c64e451355834082397e1730d1c7c595045
parent6bb5ca74b84ec83f2046fa7b90135448940a222b (diff)
downloadmongo-9a36738d0c62e7a6d5950d0495e30f8c41f23e96.tar.gz
Don't convert an ip to another ip; only convert a hostname to an ip
-rw-r--r--util/sock.cpp5
-rw-r--r--util/sock.h3
2 files changed, 6 insertions, 2 deletions
diff --git a/util/sock.cpp b/util/sock.cpp
index 560b016bf24..e31801633e0 100644
--- a/util/sock.cpp
+++ b/util/sock.cpp
@@ -22,9 +22,12 @@
namespace mongo {
static boost::mutex sock_mutex;
-// .empty() if err
+
string hostbyname(const char *hostname) {
boostlock lk(sock_mutex);
+ struct in_addr temp;
+ if ( inet_aton( hostname, &temp ) )
+ return hostname;
struct hostent *h;
h = gethostbyname(hostname);
if ( h == 0 ) return "";
diff --git a/util/sock.h b/util/sock.h
index 9450070593d..d72d70690ae 100644
--- a/util/sock.h
+++ b/util/sock.h
@@ -96,7 +96,8 @@ namespace mongo {
}
}
-// .empty() if err
+ // If an ip address is passed in, just return that. If a hostname is passed
+ // in, look up its ip and return that. Returns "" on failure.
string hostbyname(const char *hostname);
struct SockAddr {