diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2017-08-10 11:44:13 -0400 |
---|---|---|
committer | Sara Golemon <sara.golemon@mongodb.com> | 2017-08-17 00:51:01 -0400 |
commit | 1158a6b9b1de13ef2dd809b4515d881422163b5e (patch) | |
tree | e7e9620a155db736c5078a63cedff2d780501c39 /src/mongo/util/net/sockaddr.h | |
parent | 3c2e253dd0a2cb9b5cee72205eafd48c4d78b324 (diff) | |
download | mongo-1158a6b9b1de13ef2dd809b4515d881422163b5e.tar.gz |
SERVER-30588 Bind all addresses returned by getaddroinfo()
Diffstat (limited to 'src/mongo/util/net/sockaddr.h')
-rw-r--r-- | src/mongo/util/net/sockaddr.h | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/mongo/util/net/sockaddr.h b/src/mongo/util/net/sockaddr.h index 1475d98be1c..ba74655a570 100644 --- a/src/mongo/util/net/sockaddr.h +++ b/src/mongo/util/net/sockaddr.h @@ -29,6 +29,7 @@ #pragma once #include <string> +#include <vector> #ifndef _WIN32 @@ -71,10 +72,35 @@ struct SockAddr { explicit SockAddr(int sourcePort); /* listener side */ - explicit SockAddr(StringData ip, int port, sa_family_t familyHint); + /** + * Initialize a SockAddr for a given IP or Hostname. + * + * If target fails to resolve/parse, SockAddr.isValid() may return false, + * or the resulting SockAddr may be equivalent to SockAddr(port). + * + * If target is a unix domain socket, a uassert() exception will be thrown + * on windows or if addr exceeds maximum path length. + * + * If target resolves to more than one address, only the first address + * will be used. Others will be discarded. + * SockAddr::createAll() is recommended for capturing all addresses. + */ + explicit SockAddr(StringData target, int port, sa_family_t familyHint); explicit SockAddr(struct sockaddr_storage& other, socklen_t size); + /** + * Resolve an ip or hostname to a vector of SockAddr objects. + * + * Works similar to SockAddr(StringData, int, sa_family_t) above, + * however all addresses returned from ::getaddrinfo() are used, + * it never falls-open to SockAddr(port), + * and isInvalid() SockAddrs are excluded. + * + * May return an empty vector. + */ + static std::vector<SockAddr> createAll(StringData target, int port, sa_family_t familyHint); + template <typename T> T& as() { return *(T*)(&sa); @@ -123,6 +149,8 @@ struct SockAddr { socklen_t addressSize; private: + void initUnixDomainSocket(const std::string& path, int port); + std::string _hostOrIp; struct sockaddr_storage sa; bool _isValid; |