From 9a36738d0c62e7a6d5950d0495e30f8c41f23e96 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 21 Jan 2009 15:32:58 -0500 Subject: Don't convert an ip to another ip; only convert a hostname to an ip --- util/sock.cpp | 5 ++++- util/sock.h | 3 ++- 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 { -- cgit v1.2.1