Added http downloader and multicast socket options (#1467)

Add a group of socket options used by cURL and rust stdlib, as well as some UDP multicast options.
This commit is contained in:
Callum Macmillan
2022-09-15 10:09:39 +01:00
committed by GitHub
parent b731ca4668
commit 4de5b52ba0
12 changed files with 3493 additions and 64 deletions

View File

@ -8,6 +8,8 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
static bool
textual_addr_to_sockaddr(const char *textual, int port, struct sockaddr *out)
@ -400,6 +402,485 @@ os_socket_addr_resolve(const char *host, const char *service,
return BHT_OK;
}
static int
os_socket_setbooloption(bh_socket_t socket, int level, int optname,
bool is_enabled)
{
int option = (int)is_enabled;
if (setsockopt(socket, level, optname, &option, sizeof(option)) != 0) {
return BHT_ERROR;
}
return BHT_OK;
}
static int
os_socket_getbooloption(bh_socket_t socket, int level, int optname,
bool *is_enabled)
{
assert(is_enabled);
int optval;
int optval_size = sizeof(optval);
if (getsockopt(socket, level, optname, &optval, &optval_size) != 0) {
return BHT_ERROR;
}
*is_enabled = (bool)optval;
return BHT_OK;
}
int
os_socket_set_send_buf_size(bh_socket_t socket, size_t bufsiz)
{
int buf_size_int = (int)bufsiz;
if (setsockopt(socket, SOL_SOCKET, SO_SNDBUF, &buf_size_int,
sizeof(buf_size_int))
!= 0) {
return BHT_ERROR;
}
return BHT_OK;
}
int
os_socket_get_send_buf_size(bh_socket_t socket, size_t *bufsiz)
{
assert(bufsiz);
int buf_size_int;
socklen_t bufsiz_len = sizeof(buf_size_int);
if (getsockopt(socket, SOL_SOCKET, SO_SNDBUF, &buf_size_int, &bufsiz_len)
!= 0) {
return BHT_ERROR;
}
*bufsiz = (size_t)buf_size_int;
return BHT_OK;
}
int
os_socket_set_recv_buf_size(bh_socket_t socket, size_t bufsiz)
{
int buf_size_int = (int)bufsiz;
if (setsockopt(socket, SOL_SOCKET, SO_RCVBUF, &buf_size_int,
sizeof(buf_size_int))
!= 0) {
return BHT_ERROR;
}
return BHT_OK;
}
int
os_socket_get_recv_buf_size(bh_socket_t socket, size_t *bufsiz)
{
assert(bufsiz);
int buf_size_int;
socklen_t bufsiz_len = sizeof(buf_size_int);
if (getsockopt(socket, SOL_SOCKET, SO_RCVBUF, &buf_size_int, &bufsiz_len)
!= 0) {
return BHT_ERROR;
}
*bufsiz = (size_t)buf_size_int;
return BHT_OK;
}
int
os_socket_set_keep_alive(bh_socket_t socket, bool is_enabled)
{
return os_socket_setbooloption(socket, SOL_SOCKET, SO_KEEPALIVE,
is_enabled);
}
int
os_socket_get_keep_alive(bh_socket_t socket, bool *is_enabled)
{
return os_socket_getbooloption(socket, SOL_SOCKET, SO_KEEPALIVE,
is_enabled);
}
int
os_socket_set_reuse_addr(bh_socket_t socket, bool is_enabled)
{
return os_socket_setbooloption(socket, SOL_SOCKET, SO_REUSEADDR,
is_enabled);
}
int
os_socket_get_reuse_addr(bh_socket_t socket, bool *is_enabled)
{
return os_socket_getbooloption(socket, SOL_SOCKET, SO_REUSEADDR,
is_enabled);
}
int
os_socket_set_reuse_port(bh_socket_t socket, bool is_enabled)
{
return os_socket_setbooloption(socket, SOL_SOCKET, SO_REUSEPORT,
is_enabled);
}
int
os_socket_get_reuse_port(bh_socket_t socket, bool *is_enabled)
{
return os_socket_getbooloption(socket, SOL_SOCKET, SO_REUSEPORT,
is_enabled);
}
int
os_socket_set_linger(bh_socket_t socket, bool is_enabled, int linger_s)
{
struct linger linger_opts = { .l_onoff = (int)is_enabled,
.l_linger = linger_s };
if (setsockopt(socket, SOL_SOCKET, SO_LINGER, &linger_opts,
sizeof(linger_opts))
!= 0) {
return BHT_ERROR;
}
return BHT_OK;
}
int
os_socket_get_linger(bh_socket_t socket, bool *is_enabled, int *linger_s)
{
assert(time_s);
struct linger linger_opts;
socklen_t linger_opts_len = sizeof(linger_opts);
if (getsockopt(socket, SOL_SOCKET, SO_LINGER, &linger_opts,
&linger_opts_len)
!= 0) {
return BHT_ERROR;
}
*linger_s = linger_opts.l_linger;
*is_enabled = (bool)linger_opts.l_onoff;
return BHT_OK;
}
int
os_socket_set_tcp_no_delay(bh_socket_t socket, bool is_enabled)
{
return os_socket_setbooloption(socket, IPPROTO_TCP, TCP_NODELAY,
is_enabled);
}
int
os_socket_get_tcp_no_delay(bh_socket_t socket, bool *is_enabled)
{
return os_socket_getbooloption(socket, IPPROTO_TCP, TCP_NODELAY,
is_enabled);
}
int
os_socket_set_tcp_quick_ack(bh_socket_t socket, bool is_enabled)
{
#ifdef TCP_QUICKACK
return os_socket_setbooloption(socket, IPPROTO_TCP, TCP_QUICKACK,
is_enabled);
#else
errno = ENOSYS;
return BHT_ERROR;
#endif
}
int
os_socket_get_tcp_quick_ack(bh_socket_t socket, bool *is_enabled)
{
#ifdef TCP_QUICKACK
return os_socket_getbooloption(socket, IPPROTO_TCP, TCP_QUICKACK,
is_enabled);
#else
errno = ENOSYS;
return BHT_ERROR;
#endif
}
int
os_socket_set_tcp_keep_idle(bh_socket_t socket, uint32 time_s)
{
int time_s_int = (int)time_s;
#ifdef TCP_KEEPIDLE
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPIDLE, &time_s_int,
sizeof(time_s_int))
!= 0) {
return BHT_ERROR;
}
return BHT_OK;
#elif defined(TCP_KEEPALIVE)
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPALIVE, &time_s_int,
sizeof(time_s_int))
!= 0) {
return BHT_ERROR;
}
return BHT_OK;
#else
errno = ENOSYS;
return BHT_ERROR;
#endif
}
int
os_socket_get_tcp_keep_idle(bh_socket_t socket, uint32 *time_s)
{
assert(time_s);
int time_s_int;
socklen_t time_s_len = sizeof(time_s_int);
#ifdef TCP_KEEPIDLE
if (getsockopt(socket, IPPROTO_TCP, TCP_KEEPIDLE, &time_s_int, &time_s_len)
!= 0) {
return BHT_ERROR;
}
*time_s = (uint32)time_s_int;
return BHT_OK;
#elif defined(TCP_KEEPALIVE)
if (getsockopt(socket, IPPROTO_TCP, TCP_KEEPALIVE, &time_s_int, &time_s_len)
!= 0) {
return BHT_ERROR;
}
*time_s = (uint32)time_s_int;
return BHT_OK;
#else
errno = ENOSYS;
return BHT_ERROR;
#endif
}
int
os_socket_set_tcp_keep_intvl(bh_socket_t socket, uint32 time_s)
{
int time_s_int = (int)time_s;
#ifdef TCP_KEEPINTVL
if (setsockopt(socket, IPPROTO_TCP, TCP_KEEPINTVL, &time_s_int,
sizeof(time_s_int))
!= 0) {
return BHT_ERROR;
}
return BHT_OK;
#else
errno = ENOSYS;
return BHT_ERROR;
#endif
}
int
os_socket_get_tcp_keep_intvl(bh_socket_t socket, uint32 *time_s)
{
#ifdef TCP_KEEPINTVL
assert(time_s);
int time_s_int;
socklen_t time_s_len = sizeof(time_s_int);
if (getsockopt(socket, IPPROTO_TCP, TCP_KEEPINTVL, &time_s_int, &time_s_len)
!= 0) {
return BHT_ERROR;
}
*time_s = (uint32)time_s_int;
return BHT_OK;
#else
errno = ENOSYS;
return BHT_ERROR;
#endif
}
int
os_socket_set_tcp_fastopen_connect(bh_socket_t socket, bool is_enabled)
{
#ifdef TCP_FASTOPEN_CONNECT
return os_socket_setbooloption(socket, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
is_enabled);
#else
errno = ENOSYS;
return BHT_ERROR;
#endif
}
int
os_socket_get_tcp_fastopen_connect(bh_socket_t socket, bool *is_enabled)
{
#ifdef TCP_FASTOPEN_CONNECT
return os_socket_getbooloption(socket, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
is_enabled);
#else
errno = ENOSYS;
return BHT_ERROR;
#endif
}
int
os_socket_set_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool is_enabled)
{
if (ipv6) {
return os_socket_setbooloption(socket, IPPROTO_IPV6,
IPV6_MULTICAST_LOOP, is_enabled);
}
else {
return os_socket_setbooloption(socket, IPPROTO_IP, IP_MULTICAST_LOOP,
is_enabled);
}
}
int
os_socket_get_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool *is_enabled)
{
if (ipv6) {
return os_socket_getbooloption(socket, IPPROTO_IPV6,
IPV6_MULTICAST_LOOP, is_enabled);
}
else {
return os_socket_getbooloption(socket, IPPROTO_IP, IP_MULTICAST_LOOP,
is_enabled);
}
}
int
os_socket_set_ip_add_membership(bh_socket_t socket,
bh_ip_addr_buffer_t *imr_multiaddr,
uint32_t imr_interface, bool is_ipv6)
{
assert(imr_multiaddr);
if (is_ipv6) {
struct ipv6_mreq mreq;
for (int i = 0; i < 8; i++) {
((uint16_t *)mreq.ipv6mr_multiaddr.s6_addr)[i] =
imr_multiaddr->ipv6[i];
}
mreq.ipv6mr_interface = imr_interface;
if (setsockopt(socket, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq,
sizeof(mreq))
!= 0) {
return BHT_ERROR;
}
}
else {
struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = imr_multiaddr->ipv4;
mreq.imr_interface.s_addr = imr_interface;
if (setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
sizeof(mreq))
!= 0) {
return BHT_ERROR;
}
}
return BHT_OK;
}
int
os_socket_set_ip_drop_membership(bh_socket_t socket,
bh_ip_addr_buffer_t *imr_multiaddr,
uint32_t imr_interface, bool is_ipv6)
{
assert(imr_multiaddr);
if (is_ipv6) {
struct ipv6_mreq mreq;
for (int i = 0; i < 8; i++) {
((uint16_t *)mreq.ipv6mr_multiaddr.s6_addr)[i] =
imr_multiaddr->ipv6[i];
}
mreq.ipv6mr_interface = imr_interface;
if (setsockopt(socket, IPPROTO_IPV6, IPV6_LEAVE_GROUP, &mreq,
sizeof(mreq))
!= 0) {
return BHT_ERROR;
}
}
else {
struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = imr_multiaddr->ipv4;
mreq.imr_interface.s_addr = imr_interface;
if (setsockopt(socket, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq,
sizeof(mreq))
!= 0) {
return BHT_ERROR;
}
}
return BHT_OK;
}
int
os_socket_set_ip_ttl(bh_socket_t socket, uint8_t ttl_s)
{
if (setsockopt(socket, IPPROTO_IP, IP_TTL, &ttl_s, sizeof(ttl_s)) != 0) {
return BHT_ERROR;
}
return BHT_OK;
}
int
os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s)
{
socklen_t opt_len = sizeof(ttl_s);
if (getsockopt(socket, IPPROTO_IP, IP_TTL, ttl_s, &opt_len) != 0) {
return BHT_ERROR;
}
return BHT_OK;
}
int
os_socket_set_ip_multicast_ttl(bh_socket_t socket, uint8_t ttl_s)
{
if (setsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, &ttl_s, sizeof(ttl_s))
!= 0) {
return BHT_ERROR;
}
return BHT_OK;
}
int
os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s)
{
socklen_t opt_len = sizeof(ttl_s);
if (getsockopt(socket, IPPROTO_IP, IP_MULTICAST_TTL, ttl_s, &opt_len)
!= 0) {
return BHT_ERROR;
}
return BHT_OK;
}
int
os_socket_set_ipv6_only(bh_socket_t socket, bool is_enabled)
{
return os_socket_setbooloption(socket, IPPROTO_IPV6, IPV6_V6ONLY,
is_enabled);
}
int
os_socket_get_ipv6_only(bh_socket_t socket, bool *is_enabled)
{
return os_socket_getbooloption(socket, IPPROTO_IPV6, IPV6_V6ONLY,
is_enabled);
}
int
os_socket_set_broadcast(bh_socket_t socket, bool is_enabled)
{
return os_socket_setbooloption(socket, SOL_SOCKET, SO_BROADCAST,
is_enabled);
}
int
os_socket_get_broadcast(bh_socket_t socket, bool *is_enabled)
{
return os_socket_getbooloption(socket, SOL_SOCKET, SO_BROADCAST,
is_enabled);
}
int
os_socket_set_send_timeout(bh_socket_t socket, uint64 timeout_us)
{

View File

@ -531,6 +531,73 @@ os_socket_addr_local(bh_socket_t socket, bh_sockaddr_t *sockaddr);
int
os_socket_addr_remote(bh_socket_t socket, bh_sockaddr_t *sockaddr);
/**
* Set the maximum send buffer size.
*
* @param socket the socket to set
* @param bufsiz requested kernel buffer size
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_send_buf_size(bh_socket_t socket, size_t bufsiz);
/**
* Get the maximum send buffer size.
*
* @param socket the socket to set
* @param bufsiz the returned kernel buffer size
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_send_buf_size(bh_socket_t socket, size_t *bufsiz);
/**
* Set the maximum receive buffer size.
*
* @param socket the socket to set
* @param bufsiz requested kernel buffer size
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_recv_buf_size(bh_socket_t socket, size_t bufsiz);
/**
* Get the maximum receive buffer size.
*
* @param socket the socket to set
* @param bufsiz the returned kernel buffer size
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_recv_buf_size(bh_socket_t socket, size_t *bufsiz);
/**
* Enable sending of keep-alive messages on connection-oriented sockets
*
* @param socket the socket to set the flag
* @param is_enabled 1 to enable or 0 to disable
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_keep_alive(bh_socket_t socket, bool is_enabled);
/**
* Get if sending of keep-alive messages on connection-oriented sockets is
* enabled
*
* @param socket the socket to check
* @param is_enabled 1 if enabled or 0 if disabled
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_keep_alive(bh_socket_t socket, bool *is_enabled);
/**
* Set the send timeout until reporting an error
*
@ -575,6 +642,341 @@ os_socket_set_recv_timeout(bh_socket_t socket, uint64 timeout_us);
int
os_socket_get_recv_timeout(bh_socket_t socket, uint64 *timeout_us);
/**
* Enable re-use of local addresses
*
* @param socket the socket to set
* @param is_enabled 1 to enable or 0 to disable
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_reuse_addr(bh_socket_t socket, bool is_enabled);
/**
* Get whether re-use of local addresses is enabled
*
* @param socket the socket to set
* @param is_enabled 1 for enabled or 0 for disabled
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_reuse_addr(bh_socket_t socket, bool *is_enabled);
/**
* Enable re-use of local ports
*
* @param socket the socket to set
* @param is_enabled 1 to enable or 0 to disable
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_reuse_port(bh_socket_t socket, bool is_enabled);
/**
* Get whether re-use of local ports is enabled
*
* @param socket the socket to set
* @param is_enabled 1 for enabled or 0 for disabled
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_reuse_port(bh_socket_t socket, bool *is_enabled);
/**
* Set the linger options for the given socket
*
* @param socket the socket to set
* @param is_enabled whether linger is enabled
* @param linger_s linger time (seconds)
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_linger(bh_socket_t socket, bool is_enabled, int linger_s);
/**
* Get the linger options for the given socket
*
* @param socket the socket to get
* @param is_enabled whether linger is enabled
* @param linger_s linger time (seconds)
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_linger(bh_socket_t socket, bool *is_enabled, int *linger_s);
/**
* Set no delay TCP
* If set, disable the Nagle algorithm.
* This means that segments are always sent as soon as possible,
* even if there is only a small amount of data
*
* @param socket the socket to set the flag
* @param is_enabled 1 to enable or 0 to disable
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_tcp_no_delay(bh_socket_t socket, bool is_enabled);
/**
* Get no delay TCP
* If set, disable the Nagle algorithm.
* This means that segments are always sent as soon as possible,
* even if there is only a small amount of data
*
* @param socket the socket to check
* @param is_enabled 1 if enabled or 0 if disabled
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_tcp_no_delay(bh_socket_t socket, bool *is_enabled);
/**
* Enable/Disable tcp quickack mode
* In quickack mode, acks are sent immediately, rather than delayed if needed in
* accordance to normal TCP operation
*
* @param socket the socket to set the flag
* @param is_enabled 1 to enable or 0 to disable
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_tcp_quick_ack(bh_socket_t socket, bool is_enabled);
/**
* Enable/Disable tcp quickack mode
* In quickack mode, acks are sent immediately, rather than delayed if needed in
* accordance to normal TCP operation
*
* @param socket the socket to check
* @param is_enabled 1 if enabled or 0 if disabled
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_tcp_quick_ack(bh_socket_t socket, bool *is_enabled);
/**
* Set the time the connection needs to remain idle before sending keepalive
* probes
*
* @param socket the socket to set
* @param time_s seconds until keepalive probes are sent
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_tcp_keep_idle(bh_socket_t socket, uint32_t time_s);
/**
* Gets the time the connection needs to remain idle before sending keepalive
* probes
*
* @param socket the socket to check
* @param time_s seconds until keepalive probes are sent
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_tcp_keep_idle(bh_socket_t socket, uint32_t *time_s);
/**
* Set the time between individual keepalive probes
*
* @param socket the socket to set
* @param time_us seconds between individual keepalive probes
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_tcp_keep_intvl(bh_socket_t socket, uint32_t time_s);
/**
* Get the time between individual keepalive probes
*
* @param socket the socket to get
* @param time_s seconds between individual keepalive probes
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_tcp_keep_intvl(bh_socket_t socket, uint32_t *time_s);
/**
* Set use of TCP Fast Open
*
* @param socket the socket to set
* @param is_enabled 1 to enable or 0 to disable
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_tcp_fastopen_connect(bh_socket_t socket, bool is_enabled);
/**
* Get whether use of TCP Fast Open is enabled
*
* @param socket the socket to get
* @param is_enabled 1 to enabled or 0 to disabled
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_tcp_fastopen_connect(bh_socket_t socket, bool *is_enabled);
/**
* Set enable or disable IPv4 or IPv6 multicast loopback.
*
* @param socket the socket to set
* @param ipv6 true to set ipv6 loopback or false for ipv4
* @param is_enabled 1 to enable or 0 to disable
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool is_enabled);
/**
* Get enable or disable IPv4 or IPv6 multicast loopback.
*
* @param socket the socket to check
* @param ipv6 true to set ipv6 loopback or false for ipv4
* @param is_enabled 1 for enabled or 0 for disabled
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_ip_multicast_loop(bh_socket_t socket, bool ipv6,
bool *is_enabled);
/**
* Add membership to a group
*
* @param socket the socket to add membership to
* @param imr_multiaddr the group multicast address (IPv4 or IPv6)
* @param imr_interface the interface to join on
* @param is_ipv6 whether the imr_multiaddr is IPv4 or IPv6 (true for IPv6)
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_ip_add_membership(bh_socket_t socket,
bh_ip_addr_buffer_t *imr_multiaddr,
uint32_t imr_interface, bool is_ipv6);
/**
* Drop membership of a group
*
* @param socket the socket to drop membership to
* @param imr_multiaddr the group multicast address (IPv4 or IPv6)
* @param imr_interface the interface to join on
* @param is_ipv6 whether the imr_multiaddr is IPv4 or IPv6 (true for IPv6)
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_ip_drop_membership(bh_socket_t socket,
bh_ip_addr_buffer_t *imr_multiaddr,
uint32_t imr_interface, bool is_ipv6);
/**
* Set the current time-to-live field that is
* used in every packet sent from this socket.
* @param socket the socket to set the flag
* @param ttl_s time to live (seconds)
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_ip_ttl(bh_socket_t socket, uint8_t ttl_s);
/**
* Retrieve the current time-to-live field that is
* used in every packet sent from this socket.
* @param socket the socket to set the flag
* @param ttl_s time to live (seconds)
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s);
/**
* Set the time-to-live value of outgoing multicast
* packets for this socket
* @param socket the socket to set the flag
* @param ttl_s time to live (seconds)
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_ip_multicast_ttl(bh_socket_t socket, uint8_t ttl_s);
/**
* Read the time-to-live value of outgoing multicast
* packets for this socket
* @param socket the socket to set the flag
* @param ttl_s time to live (seconds)
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s);
/**
* Restrict to sending and receiving IPv6 packets only
*
* @param socket the socket to set
* @param is_enabled 1 to enable or 0 to disable
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_ipv6_only(bh_socket_t socket, bool is_enabled);
/**
* Get whether only sending and receiving IPv6 packets
*
* @param socket the socket to check
* @param is_enabled 1 for enabled or 0 for disabled
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_ipv6_only(bh_socket_t socket, bool *is_enabled);
/**
* Set whether broadcast is enabled
* When enabled, datagram sockets are allowed
* to send packets to a broadcast address.
*
* @param socket the socket to set the flag
* @param is_enabled 1 to enable or 0 to disable
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_set_broadcast(bh_socket_t socket, bool is_enabled);
/**
* Get whether broadcast is enabled
* When enabled, datagram sockets are allowed
* to send packets to a broadcast address.
*
* @param socket the socket to check
* @param is_enabled 1 if enabled or 0 if disabled
*
* @return 0 if success, -1 otherwise
*/
int
os_socket_get_broadcast(bh_socket_t socket, bool *is_enabled);
#ifdef __cplusplus
}
#endif

View File

@ -760,4 +760,280 @@ os_socket_get_recv_timeout(bh_socket_t socket, uint64 *timeout_us)
return BHT_ERROR;
}
int
os_socket_set_send_buf_size(bh_socket_t socket, size_t bufsiz)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_send_buf_size(bh_socket_t socket, size_t *bufsiz)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_recv_buf_size(bh_socket_t socket, size_t bufsiz)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_recv_buf_size(bh_socket_t socket, size_t *bufsiz)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_keep_alive(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_keep_alive(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_reuse_addr(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_reuse_addr(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_reuse_port(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_reuse_port(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_linger(bh_socket_t socket, bool is_enabled, int linger_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_linger(bh_socket_t socket, bool *is_enabled, int *linger_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_no_delay(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_no_delay(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_quick_ack(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_quick_ack(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_keep_idle(bh_socket_t socket, uint32 time_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_keep_idle(bh_socket_t socket, uint32 *time_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_keep_intvl(bh_socket_t socket, uint32 time_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_keep_intvl(bh_socket_t socket, uint32 *time_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_fastopen_connect(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_fastopen_connect(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_add_membership(bh_socket_t socket,
bh_ip_addr_buffer_t *imr_multiaddr,
uint32_t imr_interface, bool is_ipv6)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_drop_membership(bh_socket_t socket,
bh_ip_addr_buffer_t *imr_multiaddr,
uint32_t imr_interface, bool is_ipv6)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_ttl(bh_socket_t socket, uint8_t ttl_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_multicast_ttl(bh_socket_t socket, uint8_t ttl_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ipv6_only(bh_socket_t socket, bool option)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_ipv6_only(bh_socket_t socket, bool *option)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_broadcast(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_broadcast(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
#endif

View File

@ -46,7 +46,7 @@ extern "C" {
#define SHUT_RDWR 2
/* Address families. */
#define AF_INET 2 /* IP protocol family. */
#define AF_INET 2 /* IP protocol family. */
#define AF_INET6 10 /* IP version 6. */
/* Standard well-defined IP protocols. */

View File

@ -263,4 +263,279 @@ os_socket_addr_remote(bh_socket_t socket, bh_sockaddr_t *sockaddr)
errno = ENOSYS;
return BHT_ERROR;
}
}
int
os_socket_set_send_buf_size(bh_socket_t socket, size_t bufsiz)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_send_buf_size(bh_socket_t socket, size_t *bufsiz)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_recv_buf_size(bh_socket_t socket, size_t bufsiz)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_recv_buf_size(bh_socket_t socket, size_t *bufsiz)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_keep_alive(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_keep_alive(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_reuse_addr(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_reuse_addr(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_reuse_port(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_reuse_port(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_linger(bh_socket_t socket, bool is_enabled, int linger_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_linger(bh_socket_t socket, bool *is_enabled, int *linger_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_no_delay(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_no_delay(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_quick_ack(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_quick_ack(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_keep_idle(bh_socket_t socket, uint32 time_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_keep_idle(bh_socket_t socket, uint32 *time_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_keep_intvl(bh_socket_t socket, uint32 time_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_keep_intvl(bh_socket_t socket, uint32 *time_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_tcp_fastopen_connect(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_tcp_fastopen_connect(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_ip_multicast_loop(bh_socket_t socket, bool ipv6, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_add_membership(bh_socket_t socket,
bh_ip_addr_buffer_t *imr_multiaddr,
uint32_t imr_interface, bool is_ipv6)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_drop_membership(bh_socket_t socket,
bh_ip_addr_buffer_t *imr_multiaddr,
uint32_t imr_interface, bool is_ipv6)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_ttl(bh_socket_t socket, uint8_t ttl_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_ip_ttl(bh_socket_t socket, uint8_t *ttl_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ip_multicast_ttl(bh_socket_t socket, uint8_t ttl_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_ip_multicast_ttl(bh_socket_t socket, uint8_t *ttl_s)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_ipv6_only(bh_socket_t socket, bool option)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_ipv6_only(bh_socket_t socket, bool *option)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_set_broadcast(bh_socket_t socket, bool is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}
int
os_socket_get_broadcast(bh_socket_t socket, bool *is_enabled)
{
errno = ENOSYS;
return BHT_ERROR;
}