summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/osmocom/core/socket.h2
-rw-r--r--src/socket.c6
2 files changed, 4 insertions, 4 deletions
diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 43604ec0..c1835326 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -28,6 +28,8 @@ struct osmo_fd;
#define OSMO_SOCK_F_NO_MCAST_ALL (1 << 4)
/*! use SO_REUSEADDR on UDP ports (required for multicast) */
#define OSMO_SOCK_F_UDP_REUSEADDR (1 << 5)
+/*! 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)
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 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;
}