Change in libosmocore[master]: socket.c: fix osmo_sock_get_ip_and_port for IPv6

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
Sun Jul 5 10:45:01 UTC 2020


lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/19147 )


Change subject: socket.c: fix osmo_sock_get_ip_and_port for IPv6
......................................................................

socket.c: fix osmo_sock_get_ip_and_port for IPv6

The struct sockaddr is too small for IPv6. IPv6 has a 16 byte address, while
struct sockaddr is only 14 byte big (+ family).

Change-Id: I4e69d814367168c05f0da161ec9b705db36ad096
---
M src/socket.c
1 file changed, 3 insertions(+), 3 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/47/19147/1

diff --git a/src/socket.c b/src/socket.c
index e303906..4febbb6 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -1175,16 +1175,16 @@
  */
 int osmo_sock_get_ip_and_port(int fd, char *ip, size_t ip_len, char *port, size_t port_len, bool local)
 {
-	struct sockaddr sa;
+	struct osmo_sockaddr sa;
 	socklen_t len = sizeof(sa);
 	char ipbuf[INET6_ADDRSTRLEN], portbuf[6];
 	int rc;
 
-	rc = local ? getsockname(fd, &sa, &len) : getpeername(fd, &sa, &len);
+	rc = local ? getsockname(fd, &sa.u.sa, &len) : getpeername(fd, &sa.u.sa, &len);
 	if (rc < 0)
 		return rc;
 
-	rc = getnameinfo(&sa, len, ipbuf, sizeof(ipbuf),
+	rc = getnameinfo(&sa.u.sa, len, ipbuf, sizeof(ipbuf),
 			 portbuf, sizeof(portbuf),
 			 NI_NUMERICHOST | NI_NUMERICSERV);
 	if (rc < 0)

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I4e69d814367168c05f0da161ec9b705db36ad096
Gerrit-Change-Number: 19147
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200705/50a08d30/attachment.htm>


More information about the gerrit-log mailing list