From d377435b5e58e612d1bdba541606350f0aabc9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Fri, 26 Jun 2015 11:38:38 +0200 Subject: [PATCH] unix: consolidate tcp and udp bind error OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a socket created with AF_INET to an AF_INET6 address or vice versa. PR-URL: https://github.com/libuv/libuv/pull/407 Reviewed-By: Ben Noordhuis --- src/unix/tcp.c | 7 ++++++- src/unix/udp.c | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/unix/tcp.c b/src/unix/tcp.c index 4711efea..6d213a49 100644 --- a/src/unix/tcp.c +++ b/src/unix/tcp.c @@ -121,8 +121,13 @@ int uv__tcp_bind(uv_tcp_t* tcp, #endif errno = 0; - if (bind(tcp->io_watcher.fd, addr, addrlen) && errno != EADDRINUSE) + if (bind(tcp->io_watcher.fd, addr, addrlen) && errno != EADDRINUSE) { + if (errno == EAFNOSUPPORT) + /* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a + * socket created with AF_INET to an AF_INET6 address or vice versa. */ + return -EINVAL; return -errno; + } tcp->delayed_error = -errno; if (addr->sa_family == AF_INET6) diff --git a/src/unix/udp.c b/src/unix/udp.c index 2778fd9b..d5fc5cec 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -321,6 +321,10 @@ int uv__udp_bind(uv_udp_t* handle, if (bind(fd, addr, addrlen)) { err = -errno; + if (errno == EAFNOSUPPORT) + /* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a + * socket created with AF_INET to an AF_INET6 address or vice versa. */ + err = -EINVAL; goto out; }