From 64b51eb68bd272b6b1f2cefa2b33e9dd74024d0c Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Mon, 14 Jan 2019 11:59:11 +0100 Subject: 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 --- src/socket.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/socket.c b/src/socket.c index 4f3b1cab..37fd5844 100644 --- a/src/socket.c +++ b/src/socket.c @@ -783,8 +783,7 @@ int osmo_sock_get_remote_ip_port(int fd, char *port, size_t len) */ 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) @@ -823,8 +822,7 @@ int osmo_sock_get_name_buf(char *str, size_t str_len, int fd) */ 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; } -- cgit v1.2.3