+/**
+ * Try connecting to the server using UNIX domain sockets.
+ *
+ * @param service_name name of service to connect to
+ * @param cfg configuration to use
+ * @return NULL on error, connection to UNIX otherwise
+ */
+static struct GNUNET_CONNECTION_Handle *
+try_unixpath (const char *service_name,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+#if AF_UNIX
+ struct GNUNET_CONNECTION_Handle *connection;
+ char *unixpath;
+ struct sockaddr_un s_un;
+
+ unixpath = NULL;
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH", &unixpath)) &&
+ (0 < strlen (unixpath)))
+ {
+ /* We have a non-NULL unixpath, need to validate it */
+ if (strlen (unixpath) >= sizeof (s_un.sun_path))
+ {
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath,
+ (unsigned long long) sizeof (s_un.sun_path));
+ unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath);
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("Using `%s' instead\n"), unixpath);
+ if (NULL == unixpath)
+ return NULL;
+ }
+ connection = GNUNET_CONNECTION_create_from_connect_to_unixpath (cfg, unixpath);
+ if (NULL != connection)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Connected to unixpath `%s'!\n",
+ unixpath);
+ GNUNET_free (unixpath);
+ return connection;
+ }
+ }
+ GNUNET_free_non_null (unixpath);
+#endif
+ return NULL;
+}
+
+
+/**
+ * Test whether the configuration has proper values for connection
+ * (UNIXPATH || (PORT && HOSTNAME)).
+ *
+ * @param service_name name of service to connect to
+ * @param cfg configuration to use
+ * @return #GNUNET_OK if the configuration is valid, #GNUNET_SYSERR if not
+ */
+static int
+test_service_configuration (const char *service_name,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ int ret = GNUNET_SYSERR;
+ char *hostname = NULL;
+ unsigned long long port;
+#if AF_UNIX
+ char *unixpath = NULL;
+
+ if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH", &unixpath)) &&
+ (0 < strlen (unixpath)))
+ ret = GNUNET_OK;
+ GNUNET_free_non_null (unixpath);
+#endif
+
+ if ( (GNUNET_YES ==
+ GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) &&
+ (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_number (cfg, service_name, "PORT", &port)) &&
+ (port <= 65535) && (0 != port) &&
+ (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, service_name, "HOSTNAME",
+ &hostname)) &&
+ (0 != strlen (hostname)) )
+ ret = GNUNET_OK;
+ GNUNET_free_non_null (hostname);
+ return ret;
+}
+
+