unix: implement uv_udp_set_ttl()

This commit is contained in:
Ben Noordhuis 2012-01-23 20:41:23 +01:00
parent 02b41f63dc
commit e710fdb518
3 changed files with 29 additions and 0 deletions

View File

@ -658,6 +658,19 @@ UV_EXTERN int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
*/
UV_EXTERN int uv_udp_set_broadcast(uv_udp_t* handle, int on);
/*
* Set the time to live
*
* Arguments:
* handle UDP handle. Should have been initialized with
* `uv_udp_init`.
* ttl 1 through 255
*
* Returns:
* 0 on success, -1 on error.
*/
UV_EXTERN int uv_udp_set_ttl(uv_udp_t* handle, int ttl);
/*
* Send data. If the socket has not previously been bound with `uv_udp_bind`
* or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address)

View File

@ -528,6 +528,16 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
}
int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
if (setsockopt(handle->fd, IPPROTO_IP, IP_TTL, &ttl, sizeof ttl)) {
uv__set_sys_error(handle->loop, errno);
return -1;
}
return 0;
}
int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
int* namelen) {
socklen_t socklen;

View File

@ -599,3 +599,9 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
return 0;
}
int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
uv__set_artificial_error(handle->loop, UV_ENOSYS);
return -1;
}