diff options
author | Marc Schink <dev@zapb.de> | 2020-08-12 01:32:57 +0200 |
---|---|---|
committer | Marc Schink <dev@zapb.de> | 2021-01-19 11:59:17 +0100 |
commit | 3b2c07359c8e5b30ec8a11c7b076c63c9d8be92b (patch) | |
tree | 3a833891093d83841acf9b3948b2aa42da554d92 | |
parent | 11fb2f4bca89c05d0b9c9525c0d82847a6dcf4af (diff) | |
download | libjaylink-3b2c07359c8e5b30ec8a11c7b076c63c9d8be92b.zip libjaylink-3b2c07359c8e5b30ec8a11c7b076c63c9d8be92b.tar.gz libjaylink-3b2c07359c8e5b30ec8a11c7b076c63c9d8be92b.tar.bz2 |
socket: Add function to get an option value
Signed-off-by: Marc Schink <dev@zapb.de>
-rw-r--r-- | libjaylink/libjaylink-internal.h | 2 | ||||
-rw-r--r-- | libjaylink/socket.c | 20 |
2 files changed, 22 insertions, 0 deletions
diff --git a/libjaylink/libjaylink-internal.h b/libjaylink/libjaylink-internal.h index 106bf46..2a053f0 100644 --- a/libjaylink/libjaylink-internal.h +++ b/libjaylink/libjaylink-internal.h @@ -267,6 +267,8 @@ JAYLINK_PRIV bool socket_sendto(int sock, const void *buffer, size_t *length, size_t address_length); JAYLINK_PRIV bool socket_recvfrom(int sock, void *buffer, size_t *length, int flags, struct sockaddr *address, size_t *address_length); +JAYLINK_PRIV bool socket_get_option(int sock, int level, int option, + void *value, size_t *length); JAYLINK_PRIV bool socket_set_option(int sock, int level, int option, const void *value, size_t length); diff --git a/libjaylink/socket.c b/libjaylink/socket.c index f2a6588..f40390e 100644 --- a/libjaylink/socket.c +++ b/libjaylink/socket.c @@ -237,6 +237,26 @@ JAYLINK_PRIV bool socket_recvfrom(int sock, void *buffer, size_t *length, } /** + * Get the value of a socket option. + * + * @param[in] sock Socket descriptor. + * @param[in] level Level at which the option is defined. + * @param[in] option Option to get the value for. + * @param[in] value Buffer to store the value. + * @param[in] length Length of the value buffer in bytes. + * + * @return Whether the option value was retrieved successfully. + */ +JAYLINK_PRIV bool socket_get_option(int sock, int level, int option, + void *value, size_t *length) +{ + if (!getsockopt(sock, level, option, value, (socklen_t *)length)) + return true; + + return false; +} + +/** * Set an option on a socket. * * @param[in] sock Socket descriptor. |