Use AI_NUMERICHOST when using getaddrinfo to bind() our client sockets
This commit is contained in:
1 parent
73915e889d
commit
fa3d44e7aa
1 file changed
+5
-1
@@ -35,7 +35,11 @@ void TCPClientSocketHandler::init_socket(const struct addrinfo* rp)
|
|||||||
// Convert the address from string format to a sockaddr that can be
|
// Convert the address from string format to a sockaddr that can be
|
||||||
// used in bind()
|
// used in bind()
|
||||||
struct addrinfo* result;
|
struct addrinfo* result;
|
||||||
int err = ::getaddrinfo(this->bind_addr.data(), nullptr, nullptr, &result);
|
struct addrinfo hints;
|
||||||
|
memset(&hints, 0, sizeof(hints));
|
||||||
|
hints.ai_flags = AI_NUMERICHOST;
|
||||||
|
hints.ai_family = AF_UNSPEC;
|
||||||
|
int err = ::getaddrinfo(this->bind_addr.data(), nullptr, &hints, &result);
|
||||||
if (err != 0 || !result)
|
if (err != 0 || !result)
|
||||||
log_error("Failed to bind socket to ", this->bind_addr, ": ",
|
log_error("Failed to bind socket to ", this->bind_addr, ": ",
|
||||||
gai_strerror(err));
|
gai_strerror(err));
|
||||||
|
|||||||
Reference in new issue
Block a user