aboutsummaryrefslogtreecommitdiff
path: root/src/util/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/connection.c')
-rw-r--r--src/util/connection.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/util/connection.c b/src/util/connection.c
index fdd454105..d218714c0 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -889,6 +889,72 @@ GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched,
889 889
890 890
891/** 891/**
892 * Create a socket handle by connecting to a UNIX domain service.
893 * This function returns immediately, even if the connection has not
894 * yet been established. This function only creates UNIX connections.
895 *
896 * @param sched scheduler to use
897 * @param cfg configuration to use
898 * @param unixpath path to connect to
899 * @param maxbuf maximum write buffer size for the socket (use
900 * 0 for sockets that need no write buffers, such as listen sockets)
901 * @return the socket handle, NULL on systems without UNIX support
902 */
903struct GNUNET_CONNECTION_Handle *
904GNUNET_CONNECTION_create_from_connect_to_unixpath (struct GNUNET_SCHEDULER_Handle *sched,
905 const struct
906 GNUNET_CONFIGURATION_Handle *cfg,
907 const char *unixpath,
908 size_t maxbuf)
909{
910#ifdef AF_UNIX
911 struct GNUNET_CONNECTION_Handle *ret;
912 struct sockaddr_un *un;
913 size_t slen;
914
915 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
916 un = GNUNET_malloc (sizeof (struct sockaddr_un));
917 un->sun_family = AF_UNIX;
918 slen = strlen (unixpath) + 1;
919 if (slen >= sizeof (un->sun_path))
920 slen = sizeof (un->sun_path) - 1;
921 memcpy (un->sun_path,
922 unixpath,
923 slen);
924 un->sun_path[slen] = '\0';
925 slen += sizeof (sa_family_t);
926#if LINUX
927 un->sun_path[0] = '\0';
928 slen = sizeof (struct sockaddr_un);
929#endif
930 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf);
931 ret->cfg = cfg;
932 ret->sched = sched;
933 ret->write_buffer = (char *) &ret[1];
934 ret->write_buffer_size = maxbuf;
935 ret->port = 0;
936 ret->hostname = NULL;
937 ret->addr = (struct sockaddr*) un;
938 ret->addrlen = slen;
939 ret->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
940 if (GNUNET_OK != GNUNET_NETWORK_socket_connect (ret->sock,
941 ret->addr,
942 ret->addrlen))
943 {
944 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret->sock));
945 GNUNET_free (ret->addr);
946 GNUNET_free (ret);
947 return NULL;
948 }
949 connect_success_continuation (ret);
950 return ret;
951#else
952 return NULL;
953#endif
954}
955
956
957/**
892 * Create a socket handle by (asynchronously) connecting to a host. 958 * Create a socket handle by (asynchronously) connecting to a host.
893 * This function returns immediately, even if the connection has not 959 * This function returns immediately, even if the connection has not
894 * yet been established. This function only creates TCP connections. 960 * yet been established. This function only creates TCP connections.