Change in libosmocore[master]: socket: add define for socket name length

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/.

dexter gerrit-no-reply at lists.osmocom.org
Mon Jan 14 11:05:41 UTC 2019


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/12554


Change subject: socket: add define for socket name length
......................................................................

socket: add define for socket name length

The function osmo_sock_get_name_buf() can be used to write a string
representation to a user provided memory. Unfortunately the proper
length for the user provided memory is not obvious. To make using
osmo_sock_get_name_buf() more practical, add a define constant that
defines the length of the required memory. Also use this define in
socket.c.

Change-Id: If8be8c2c0d4935da17ab13b2c2127b719ceefbcc
---
M include/osmocom/core/socket.h
M src/socket.c
2 files changed, 4 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/54/12554/1

diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 43604ec..d480db7 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -29,6 +29,8 @@
 /*! use SO_REUSEADDR on UDP ports (required for multicast) */
 #define OSMO_SOCK_F_UDP_REUSEADDR (1 << 5)
 
+#define OSMO_SOCK_NAME_MAXlEN (2 + INET6_ADDRSTRLEN + 1 + 5 + 3 + 2 + INET6_ADDRSTRLEN + 1 + 5 + 1)
+
 int osmo_sock_init(uint16_t family, uint16_t type, uint8_t proto,
 		   const char *host, uint16_t port, unsigned int flags);
 
diff --git a/src/socket.c b/src/socket.c
index 4f3b1ca..ecbf59d 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -784,7 +784,7 @@
 char *osmo_sock_get_name(void *ctx, int fd)
 {
 	/* "r=1.2.3.4:123<->l=5.6.7.8:987" */
-	char str[2 + INET6_ADDRSTRLEN + 1 + 5 + 3 + 2 + INET6_ADDRSTRLEN + 1 + 5 + 1];
+	char str[OSMO_SOCK_NAME_MAXlEN];
 	int rc;
 	rc = osmo_sock_get_name_buf(str, sizeof(str), fd);
 	if (rc <= 0)
@@ -824,7 +824,7 @@
 const char *osmo_sock_get_name2(int fd)
 {
 	/* "r=1.2.3.4:123<->l=5.6.7.8:987" */
-	static char str[2 + INET6_ADDRSTRLEN + 1 + 5 + 3 + 2 + INET6_ADDRSTRLEN + 1 + 5 + 1];
+	static char str[OSMO_SOCK_NAME_MAXlEN];
 	osmo_sock_get_name_buf(str, sizeof(str), fd);
 	return str;
 }

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: If8be8c2c0d4935da17ab13b2c2127b719ceefbcc
Gerrit-Change-Number: 12554
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190114/239ea3d2/attachment.htm>


More information about the gerrit-log mailing list