return NULL;
}
+/**
+ * Stringify port number, resolve into service name where defined.
+ * \param port 2-byte port number, in host-byte-order.
+ * \param transport Transport protocol name (e.g. "udp", "tcp"), or NULL.
+ * \return Pointer to static result buffer.
+ *
+ * \sa getservent(3), services(5), nsswitch.conf(5)
+ */
+const char *stringify_port(int port, const char *transport)
+{
+ static char service[NI_MAXSERV];
+
+ if (port < 0 || port > 0xFFFF) {
+ snprintf(service, sizeof(service), "undefined (%d)", port);
+ } else {
+ struct servent *se = getservbyport(htons(port), transport);
+
+ if (se == NULL)
+ snprintf(service, sizeof(service), "%u", port);
+ else
+ snprintf(service, sizeof(service), "%s", se->s_name);
+ }
+ return service;
+}
+
/**
* Determine the socket type for a given layer-4 protocol.
*
*
* \param sa The IPv4/IPv6 socket address to use.
*
- * \sa getnameinfo(3).
+ * \sa getnameinfo(3), services(5), nsswitch.conf(5)
*/
static char *host_and_port(const struct sockaddr_storage *ss)
{
ret = getnameinfo(sa, salen(sa),
hbuf, sizeof(hbuf),
sbuf, sizeof(sbuf),
- NI_NUMERICHOST | NI_NUMERICSERV);
+ NI_NUMERICHOST);
if (ret == 0) {
snprintf(output, sizeof(output), "%s#%s", hbuf, sbuf);
} else {
char *addr, ssize_t addrlen, int32_t *netmask);
extern char *parse_url(const char *url,
char *host, ssize_t hostlen, int32_t *port);
+extern const char *stringify_port(int port, const char *transport);
/**
* Ensure that string conforms to the IPv4 address format.
*
ret = make_message(
"%s sender:\n"
"\tstatus: %s\n"
- "\tport: %d\n"
+ "\tport: %s\n"
"\tnumber of connected clients: %d\n"
"\tmaximal number of clients: %d%s\n"
"\tconnected clients: %s\n"
"\taccess %s list: %s\n",
name,
(ss->listen_fd >= 0)? "on" : "off",
- ss->port,
+ stringify_port(ss->port, strcmp(name, "http") ? "dccp" : "tcp"),
ss->num_clients,
ss->max_clients,
ss->max_clients > 0? "" : " (unlimited)",