static int uv__udp_maybe_deferred_bind(uv_udp_t* handle, int domain) { struct sockaddr_storage taddr; socklen_t addrlen; assert(domain == AF_INET || domain == AF_INET6); if (handle->fd != -1) return 0; switch (domain) { case AF_INET: { struct sockaddr_in* addr = (void*)&taddr; memset(addr, 0, sizeof *addr); addr->sin_family = AF_INET; addr->sin_addr.s_addr = INADDR_ANY; addrlen = sizeof *addr; break; } case AF_INET6: { struct sockaddr_in6* addr = (void*)&taddr; memset(addr, 0, sizeof *addr); addr->sin6_family = AF_INET6; addr->sin6_addr = in6addr_any; addrlen = sizeof *addr; break; } default: assert(0 && "unsupported address family"); abort(); } return uv__udp_bind(handle, domain, (struct sockaddr*)&taddr, addrlen, 0); }
static int uv__udp_maybe_deferred_bind(uv_udp_t* handle, int domain, unsigned int flags) { unsigned char taddr[sizeof(struct sockaddr_in6)]; socklen_t addrlen; if (handle->io_watcher.fd != -1) return 0; switch (domain) { case AF_INET: { struct sockaddr_in* addr = (void*)&taddr; memset(addr, 0, sizeof *addr); addr->sin_family = AF_INET; addr->sin_addr.s_addr = INADDR_ANY; addrlen = sizeof *addr; break; } case AF_INET6: { struct sockaddr_in6* addr = (void*)&taddr; memset(addr, 0, sizeof *addr); addr->sin6_family = AF_INET6; addr->sin6_addr = in6addr_any; addrlen = sizeof *addr; break; } default: assert(0 && "unsupported address family"); abort(); } return uv__udp_bind(handle, (const struct sockaddr*) &taddr, addrlen, flags); }
int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned int flags) { if (handle->type != UV_UDP || addr.sin_family != AF_INET) return UV_EINVAL; else return uv__udp_bind(handle, addr, flags); }
int uv_udp_bind(uv_udp_t* handle, struct sockaddr_in addr, unsigned int flags) { if (handle->type != UV_UDP || addr.sin_family != AF_INET) { uv__set_artificial_error(handle->loop, UV_EFAULT); return -1; } return uv__udp_bind(handle, addr, flags); }
int uv_udp_bind6(uv_udp_t* handle, const struct sockaddr_in6* addr, unsigned int flags) { if (handle->type == UV_UDP && addr->sin6_family == AF_INET6) { return uv__udp_bind(handle, (const struct sockaddr*) addr, sizeof(*addr), flags); } return UV_EINVAL; }
int uv_udp_bind6(uv_udp_t* handle, struct sockaddr_in6 addr, unsigned flags) { if (handle->type != UV_UDP || addr.sin6_family != AF_INET6) { uv__set_sys_error(handle->loop, EFAULT); return -1; } return uv__udp_bind(handle, AF_INET6, (struct sockaddr*)&addr, sizeof addr, flags); }
int uv_udp_bind(uv_udp_t* handle, const struct sockaddr* addr, unsigned int flags) { unsigned int addrlen; if (handle->type != UV_UDP) return UV_EINVAL; if (addr->sa_family == AF_INET) addrlen = sizeof(struct sockaddr_in); else if (addr->sa_family == AF_INET6) addrlen = sizeof(struct sockaddr_in6); else return UV_EINVAL; return uv__udp_bind(handle, addr, addrlen, flags); }