aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/nng/nng.h5
-rw-r--r--src/core/url.c8
2 files changed, 13 insertions, 0 deletions
diff --git a/include/nng/nng.h b/include/nng/nng.h
index 1061a00b..3397ca53 100644
--- a/include/nng/nng.h
+++ b/include/nng/nng.h
@@ -1100,6 +1100,11 @@ NNG_DECL const char *nng_url_scheme(const nng_url *);
// the scheme.
NNG_DECL uint32_t nng_url_port(const nng_url *);
+// Update a URL with a zero port to a non-zero port (useful
+// after a bind to port 0). Does nothing if the URL's port is not
+// zero to start with.
+NNG_DECL void nng_url_resolve_port(nng_url *url, uint32_t port);
+
// hostname part of URL, can be NULL if irerelvant to scheme
const char *nng_url_hostname(const nng_url *);
diff --git a/src/core/url.c b/src/core/url.c
index 530e299c..1b39f809 100644
--- a/src/core/url.c
+++ b/src/core/url.c
@@ -719,6 +719,14 @@ nng_url_port(const nng_url *url)
return (url->u_port);
}
+void
+nng_url_resolve_port(nng_url *url, uint32_t port)
+{
+ if (url->u_port == 0) {
+ url->u_port = port;
+ }
+}
+
const char *
nng_url_hostname(const nng_url *url)
{