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 {
return new_fd < 0? -ERRNO_TO_PARA_ERROR(errno) : new_fd;
}
+/**
+ * Probe the list of DCCP CCIDs supported locally by the host.
+ * \param ccids Array to be filled in.
+ * \param nccids Length of \a ccids.
+ * \return Pointer to \a ccids, NULL on failure.
+ *
+ * NB: This feature is only available on Linux > 2.6.30; on older kernels
+ * ENOPROTOOPT ("Protocol not available") will be returned.
+ */
+const uint8_t *dccp_available_ccids(uint8_t *ccids, uint8_t *nccids)
+{
+ int fd = makesock(AF_UNSPEC, IPPROTO_DCCP, 0, NULL, 0);
+
+ if (fd < 0)
+ return NULL;
+
+ if (getsockopt(fd, SOL_DCCP, DCCP_SOCKOPT_AVAILABLE_CCIDS,
+ ccids, (socklen_t *)nccids) < 0) {
+ PARA_ERROR_LOG("No DCCP_SOCKOPT_AVAILABLE_CCIDS: %s\n",
+ strerror(errno));
+ *nccids = 0;
+ }
+ close(fd);
+
+ return *nccids ? ccids : NULL;
+}
+
/**
* Prepare a structure for \p AF_UNIX socket addresses.
*