+/**
+ * Pretty-print a host/port pair.
+ *
+ * \param url NULL, or any string accepted by \ref parse_url().
+ * \param default_port Applies if url has no port.
+ *
+ * If the url argument is NULL, the function returns the string
+ * 0.0.0.0:default_port. Otherwise it calls \ref parse_url() to check the
+ * syntax of the input string given by url. On errors the string "?" is
+ * returned. Otherwise, if url contains a port, a copy of url is returned. If
+ * no port was supplied, a colon and the default port are appended to url.
+ *
+ * \return In all cases the returned string is a allocated with malloc(3) and
+ * has to be freed by the caller.
+ */
+char *format_url(const char *url, int default_port)
+{
+ char host[MAX_HOSTLEN];
+ int url_port;
+
+ if (!url)
+ return make_message("0.0.0.0:%d", default_port);
+ if (!parse_url(url, host, sizeof(host), &url_port))
+ return make_message("?");
+ if (url_port < 0)
+ return make_message("%s:%d", url, default_port);
+ else
+ return para_strdup(url);
+}
+