daniel has uploaded this change for review.

View Change

Add osmo_sockaddr_size() to return the size of the variant used

Change-Id: I952b6bb752441fe019fc18f89bce4bbfbe58994a
---
M include/osmocom/core/socket.h
1 file changed, 17 insertions(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/72/31172/1
diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 3ed9cc6..427fa92 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -33,6 +33,23 @@
int osmo_sockaddr_is_local(struct sockaddr *addr, unsigned int addrlen);
int osmo_sockaddr_is_any(const struct osmo_sockaddr *addr);

+/*! Return the size of the variant used in the address
+ * \param[in] addr the osmo_sockaddr to get the size of
+ * \return the size of the struct variant being used. If the value in sa_family is unsupported it will return
+ * the size of struct osmo_sockaddr
+ */
+static inline socklen_t osmo_sockaddr_size(const struct osmo_sockaddr *addr)
+{
+ switch (addr->u.sa.sa_family) {
+ case AF_INET:
+ return sizeof(struct sockaddr_in);
+ case AF_INET6:
+ return sizeof(struct sockaddr_in6);
+ default:
+ return sizeof(struct osmo_sockaddr);
+ }
+}
+
unsigned int osmo_sockaddr_to_str_and_uint(char *addr, unsigned int addr_len, uint16_t *port,
const struct sockaddr *sa);
size_t osmo_sockaddr_in_to_str_and_uint(char *addr, unsigned int addr_len, uint16_t *port,

To view, visit change 31172. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I952b6bb752441fe019fc18f89bce4bbfbe58994a
Gerrit-Change-Number: 31172
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillmann@sysmocom.de>
Gerrit-MessageType: newchange