aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libjaylink/libjaylink-internal.h2
-rw-r--r--libjaylink/socket.c20
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.