mirror of
https://github.com/zeromq/libzmq.git
synced 2025-11-12 11:14:46 +01:00
Add IPv6 support to tcp_listener
Signed-off-by: Steven McCoy <steven.mccoy@miru.hk> Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
This commit is contained in:
committed by
Martin Sustrik
parent
3c3c0bfd1f
commit
57440b86e2
@@ -130,6 +130,20 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
|
||||
|
||||
// Create a listening socket.
|
||||
s = ::socket (addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
if (s == INVALID_SOCKET)
|
||||
wsa_error_to_errno ();
|
||||
#endif
|
||||
|
||||
// IPv6 address family not supported, try automatic downgrade to IPv4.
|
||||
if (addr.ss_family == AF_INET6 && errno == EAFNOSUPPORT &&
|
||||
!options.ipv4only) {
|
||||
rc = resolve_ip_interface (&addr, &addr_len, addr_, true);
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
s = ::socket (addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
}
|
||||
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
if (s == INVALID_SOCKET) {
|
||||
wsa_error_to_errno ();
|
||||
@@ -140,6 +154,11 @@ int zmq::tcp_listener_t::set_address (const char *addr_)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
// On some systems, IPv4 mapping in IPv6 sockets is disabled by default.
|
||||
// Switch it on in such cases.
|
||||
if (addr.ss_family == AF_INET6)
|
||||
enable_ipv4_mapping (s);
|
||||
|
||||
// Allow reusing of the address.
|
||||
int flag = 1;
|
||||
#ifdef ZMQ_HAVE_WINDOWS
|
||||
|
||||
Reference in New Issue
Block a user