pespin submitted this change.

View Change


Approvals: Jenkins Builder: Verified daniel: Looks good to me, approved fixeria: Looks good to me, but someone else must approve
socket: Introduce defines OSMO_SOCK_MULTIADDR_{PEER_STR,NAME}_MAXLEN

These values end up being used by API users of
osmo_sock_multiaddr_get_name_buf() and
osmo_multiaddr_ip_and_port_snprintf().

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

diff --git a/include/osmocom/core/socket.h b/include/osmocom/core/socket.h
index 0f4a8bd..ea73cda 100644
--- a/include/osmocom/core/socket.h
+++ b/include/osmocom/core/socket.h
@@ -16,9 +16,20 @@

#include <osmocom/core/defs.h>

+/*! maximum number of local or remote addresses supported by an osmo_sock instance */
+#define OSMO_SOCK_MAX_ADDRS 32
+
/*! 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)

+/*! maximum length of a multi-address socket peer (endpoint) name: (5.6.7.8|::9):987
+ * char '(' + OSMO_STREAM_MAX_ADDRS - 1 addr separators + chars "):" + port buffer + char '\0'
+ */
+#define OSMO_SOCK_MULTIADDR_PEER_STR_MAXLEN (INET6_ADDRSTRLEN * OSMO_SOCK_MAX_ADDRS + INET6_ADDRSTRLEN + 2 + 6 + 1)
+/*! maximum length of a multia-address socket name ("r=(::2|1.2.3.4):123<->l=(5.6.7.8|::9):987") */
+#define OSMO_SOCK_MULTIADDR_NAME_MAXLEN (OSMO_SOCK_MULTIADDR_PEER_STR_MAXLEN + 7)
+
+
struct sockaddr_in;
struct sockaddr;
struct osmo_fd;
@@ -108,9 +119,6 @@
#define GET_OSMO_SOCK_F_PRIO(f) (((f) >> 16) & 0xff)


-/*! maximum number of local or remote addresses supported by an osmo_sock instance */
-#define OSMO_SOCK_MAX_ADDRS 32
-
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/core/socket.c b/src/core/socket.c
index c497088..ce73cd8 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -2020,14 +2020,14 @@

/*! Format multiple IP addresses and/or port number into a combined string buffer
* \param[out] str Destination string buffer.
- * \param[in] str_len sizeof(str).
+ * \param[in] str_len sizeof(str), usually OSMO_SOCK_MULTIADDR_PEER_STR_MAXLEN.
* \param[out] ip Pointer to memory holding ip_cnt consecutive buffers of size ip_len.
* \param[out] ip_cnt length ip array pointer. on return it contains the number of addresses found.
* \param[in] ip_len length of each of the string buffer in the the ip array.
* \param[out] port number (will be printed in when not NULL).
* \return String length as returned by snprintf(), or negative on error.
*
- * This API expectes an ip array as the one filled in by
+ * This API expects an ip array as the one filled in by
* osmo_sock_multiaddr_get_ip_and_port(), and hence it's a good companion for
* that API.
*/
@@ -2065,7 +2065,7 @@
/*! Get address/port information on socket in provided string buffer, like "r=1.2.3.4:5<->l=6.7.8.9:10".
* This does not include braces like osmo_sock_get_name().
* \param[out] str Destination string buffer.
- * \param[in] str_len sizeof(str).
+ * \param[in] str_len sizeof(str), usually OSMO_SOCK_MULTIADDR_NAME_MAXLEN.
* \param[in] fd File descriptor of socket.
* \param[in] fd IPPROTO of the socket, eg: IPPROTO_SCTP.
* \return String length as returned by snprintf(), or negative on error.

To view, visit change 35330. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I18a0e1a652a3e8ef3e97154355eb1d07a14ef0bd
Gerrit-Change-Number: 35330
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann@sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy@sysmocom.de>
Gerrit-Reviewer: pespin <pespin@sysmocom.de>
Gerrit-MessageType: merged