Change in libosmocore[master]: socket.h: introduce osmo_sockaddr to hold v4 and v6 endpoints

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Tue Aug 11 12:30:57 UTC 2020


lynxis lazus has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/19141 )

Change subject: socket.h: introduce osmo_sockaddr to hold v4 and v6 endpoints
......................................................................

socket.h: introduce osmo_sockaddr to hold v4 and v6 endpoints

When dealing with IPv4 and IPv6 address, the struct sockaddr
allows to hold IPv4 and IPv6.
However even when struct sockaddr is being used, a cast to the
IPv4 or IPv6 family must happen. To work around this additional code,
use a union for the most common types.

Change-Id: If80172373735193401af872b18e1ff00c93880e7
---
M include/osmocom/core/socket.h
1 file changed, 11 insertions(+), 2 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 129612c..9cb8d6b 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -2,6 +2,7 @@
  *  Osmocom socket convenience functions. */
 
 #pragma once
+#if (!EMBEDDED)
 
 /*! \defgroup socket Socket convenience functions
  *  @{
@@ -11,17 +12,24 @@
 #include <stdbool.h>
 #include <stddef.h>
 
-#if (!EMBEDDED)
 #include <arpa/inet.h>
 
 /*! maximum length of a socket name ("r=1.2.3.4:123<->l=5.6.7.8:987") */
 #define OSMO_SOCK_NAME_MAXLEN (2 + INET6_ADDRSTRLEN + 1 + 5 + 3 + 2 + INET6_ADDRSTRLEN + 1 + 5 + 1)
-#endif
 
 struct sockaddr_in;
 struct sockaddr;
 struct osmo_fd;
 
+struct osmo_sockaddr {
+	union {
+		struct sockaddr sa;
+		struct sockaddr_storage sas;
+		struct sockaddr_in sin;
+		struct sockaddr_in6 sin6;
+	} u;
+};
+
 /* flags for osmo_sock_init. */
 /*! connect the socket to a remote peer */
 #define OSMO_SOCK_F_CONNECT	(1 << 0)
@@ -92,4 +100,5 @@
 
 int osmo_sock_local_ip(char *local_ip, const char *remote_ip);
 
+#endif /* (!EMBEDDED) */
 /*! @} */

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19141
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If80172373735193401af872b18e1ff00c93880e7
Gerrit-Change-Number: 19141
Gerrit-PatchSet: 10
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
Gerrit-CC: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200811/be338ae8/attachment.htm>


More information about the gerrit-log mailing list