05_dccp-supported-ccid-lookup.diff
[paraslash.git] / net.c
diff --git a/net.c b/net.c
index 6ab96215df880dc04eea0f6f90c48fd385720816..b83ab8c61d34c3a52f8e0f35dfa63d05c3584f21 100644 (file)
--- a/net.c
+++ b/net.c
@@ -661,6 +661,33 @@ int para_accept(int fd, void *addr, socklen_t size)
        return new_fd < 0? -ERRNO_TO_PARA_ERROR(errno) : new_fd;
 }
 
        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.
  *
 /**
  * Prepare a structure for \p AF_UNIX socket addresses.
  *