aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2019-02-04 14:55:37 +0100
committerMax <msuraev@sysmocom.de>2019-02-05 16:25:20 +0000
commit732652b5b7f4fe02ecfff5f33b67db6392b02617 (patch)
treed8ca95a8cdcb1aa538fe58d2b574fa4861fc4aad /src/stream.c
parenta93bb2ca34a0b201c35a67445bb5b254ce5a3c5a (diff)
Add socket name functions to stream client/server
Add functions to get the description of a server link or client connection which examine data on corresponding socket. Those functions use static buffers and intended for single use in log/printf statements as illustarted by corresponding example changes. Change-Id: If9a8e211da85956781479862a63c4fc6e53ed6be
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/stream.c b/src/stream.c
index f1d87d4..7cc77c9 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -405,6 +405,18 @@ void *osmo_stream_cli_get_data(struct osmo_stream_cli *cli)
return cli->data;
}
+/*! \brief Get the stream client socket description.
+ * \param[in] cli Stream Client to examine
+ * \returns Socket description or NULL in case of error */
+char *osmo_stream_cli_get_sockname(const struct osmo_stream_cli *cli)
+{
+ static char buf[OSMO_SOCK_NAME_MAXLEN];
+
+ osmo_sock_get_name_buf(buf, OSMO_SOCK_NAME_MAXLEN, cli->ofd.fd);
+
+ return buf;
+}
+
/*! \brief Get Osmocom File Descriptor of the stream client socket
* \param[in] cli Stream Client to modify
* \returns Pointer to \ref osmo_fd */
@@ -711,6 +723,25 @@ void *osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link)
return link->data;
}
+/*! \brief Get description of the stream server link e. g. 127.0.0.1:1234
+ * \param[in] link Stream Server Link to examine
+ * \returns Link description or NULL in case of error */
+char *osmo_stream_srv_link_get_sockname(const struct osmo_stream_srv_link *link)
+{
+ static char buf[INET6_ADDRSTRLEN + 6];
+ int rc = osmo_sock_get_local_ip(link->ofd.fd, buf, INET6_ADDRSTRLEN);
+ if (rc < 0)
+ return NULL;
+
+ buf[strnlen(buf, INET6_ADDRSTRLEN + 6)] = ':';
+
+ rc = osmo_sock_get_local_ip_port(link->ofd.fd, buf + strnlen(buf, INET6_ADDRSTRLEN + 6), 6);
+ if (rc < 0)
+ return NULL;
+
+ return buf;
+}
+
/*! \brief Get Osmocom File Descriptor of the stream server link
* \param[in] link Stream Server Link
* \returns Pointer to \ref osmo_fd */