Timur Davydov has uploaded this change for review.

View Change

core: always build osmo_sock_multiaddr_* helpers

Always build the public osmo_sock_multiaddr_* helper functions,
independent of HAVE_LIBSCTP.

Move the HAVE_LIBSCTP checks inside the functions and limit them
to the SCTP-specific code paths: when IPPROTO_SCTP is requested
without libsctp support, return -ENOTSUP, while non-SCTP protocols
continue to work as before.

This fixes link failures in libosmo-netif when building with

Change-Id: I3e70b7cd6cb4d022252e6ddc70a42ca5eea72bb1
---
M src/core/socket.c
1 file changed, 6 insertions(+), 4 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/95/41895/1
diff --git a/src/core/socket.c b/src/core/socket.c
index 2de4bb3..6cd82f0 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -1895,7 +1895,6 @@
return 0;
}

-#ifdef HAVE_LIBSCTP
/*! Get multiple IP addresses and/or port number on socket in separate string buffers
* \param[in] fd file descriptor of socket.
* \param[out] ip_proto IPPROTO of the socket, eg: IPPROTO_SCTP.
@@ -1926,10 +1925,12 @@
int osmo_sock_multiaddr_get_ip_and_port(int fd, int ip_proto, char *ip, size_t *ip_cnt, size_t ip_len,
char *port, size_t port_len, bool local)
{
+#ifdef HAVE_LIBSCTP
struct sockaddr *addrs = NULL;
unsigned int n_addrs, i;
void *addr_buf;
int rc;
+#endif /* HAVE_LIBSCTP */

switch (ip_proto) {
case IPPROTO_SCTP:
@@ -1943,6 +1944,7 @@
return osmo_sock_get_ip_and_port(fd, ip, ip_len, port, port_len, local);
}

+#ifdef HAVE_LIBSCTP
rc = local ? sctp_getladdrs(fd, 0, &addrs) : sctp_getpaddrs(fd, 0, &addrs);
if (rc < 0)
return rc;
@@ -1983,8 +1985,10 @@
free_addrs_ret:
local ? sctp_freeladdrs(addrs) : sctp_freepaddrs(addrs);
return rc;
+#else
+ return -ENOTSUP;
+#endif /* HAVE_LIBSCTP */
}
-#endif

/*! Get local IP address on socket
* \param[in] fd file descriptor of socket
@@ -2047,7 +2051,6 @@
return talloc_asprintf(ctx, "(%s)", str);
}

-#ifdef HAVE_LIBSCTP
/*! 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), usually OSMO_SOCK_MULTIADDR_PEER_STR_MAXLEN.
@@ -2153,7 +2156,6 @@

return sb.chars_needed;
}
-#endif

/*! 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().

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

Gerrit-MessageType: newchange
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I3e70b7cd6cb4d022252e6ddc70a42ca5eea72bb1
Gerrit-Change-Number: 41895
Gerrit-PatchSet: 1
Gerrit-Owner: Timur Davydov <dtv.comp@gmail.com>