unix: add uv_udp_set_broadcast() and uv_udp_set_multicast_ttl()
This commit is contained in:
parent
b674187c38
commit
497b1ecd00
26
include/uv.h
26
include/uv.h
@ -631,6 +631,32 @@ UV_EXTERN int uv_udp_set_membership(uv_udp_t* handle,
|
|||||||
const char* multicast_addr, const char* interface_addr,
|
const char* multicast_addr, const char* interface_addr,
|
||||||
uv_membership membership);
|
uv_membership membership);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set the multicast ttl
|
||||||
|
*
|
||||||
|
* Arguments:
|
||||||
|
* handle UDP handle. Should have been initialized with
|
||||||
|
* `uv_udp_init`.
|
||||||
|
* ttl 1 through 255
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* 0 on success, -1 on error.
|
||||||
|
*/
|
||||||
|
int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set broadcast on or off
|
||||||
|
*
|
||||||
|
* Arguments:
|
||||||
|
* handle UDP handle. Should have been initialized with
|
||||||
|
* `uv_udp_init`.
|
||||||
|
* on 1 for on, 0 for off
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* 0 on success, -1 on error.
|
||||||
|
*/
|
||||||
|
int uv_udp_set_broadcast(uv_udp_t* handle, int on);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send data. If the socket has not previously been bound with `uv_udp_bind`
|
* 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)
|
* or `uv_udp_bind6`, it is bound to 0.0.0.0 (the "all interfaces" address)
|
||||||
|
|||||||
@ -509,6 +509,24 @@ int uv_udp_set_membership(uv_udp_t* handle, const char* multicast_addr,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
|
||||||
|
if (setsockopt(handle->fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof ttl) == -1) {
|
||||||
|
uv__set_sys_error(handle->loop, errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
|
||||||
|
if (setsockopt(handle->fd, SOL_SOCKET, SO_BROADCAST, &on, sizeof on) == -1) {
|
||||||
|
uv__set_sys_error(handle->loop, errno);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
|
int uv_udp_getsockname(uv_udp_t* handle, struct sockaddr* name,
|
||||||
int* namelen) {
|
int* namelen) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user