Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

sunos: fix uv_udp_set_ttl and uv_udp_multicast_ttl

The argument to setsockopt(IP_TTL|IP_MULTICAST_TTL) should be a char, not an int
like on other Unices.
  • Loading branch information...
bnoordhuis committed Jan 27, 2012
1 parent 3f1bad2 commit 16124bb34e8afdf0c9a8e968bc3f2b4b3594134a
Showing with 33 additions and 2 deletions.
  1. +33 −2 src/unix/udp.c
@@ -528,13 +528,44 @@ int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
}

X(multicast_loop, IPPROTO_IP, IP_MULTICAST_LOOP)
X(multicast_ttl, IPPROTO_IP, IP_MULTICAST_TTL)
X(broadcast, SOL_SOCKET, SO_BROADCAST)
X(ttl, IPPROTO_IP, IP_TTL)

#undef X


static int uv__udp_set_ttl(uv_udp_t* handle, int option, int ttl) {
#if __sun
char arg = ttl;
#else
int arg = ttl;
#endif

#if __sun
if (ttl < 0 || ttl > 255) {
uv__set_sys_error(handle->loop, EINVAL);
return -1;
}
#endif

if (setsockopt(handle->fd, IPPROTO_IP, option, &arg, sizeof(arg))) {
uv__set_sys_error(handle->loop, errno);
return -1;
}

return 0;
}


int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
return uv__udp_set_ttl(handle, IP_TTL, ttl);
}


int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
return uv__udp_set_ttl(handle, IP_MULTICAST_TTL, ttl);
}


int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name, int* namelen) {
socklen_t socklen;
int saved_errno;

0 comments on commit 16124bb

Please sign in to comment.
You can’t perform that action at this time.