* Added support for protocols over Unix domain sockets.
[citadel.git] / citadel / ipc_c_tcp.c
index d9545d75c28cfc1d92cafd3a991ed864a9c225a7..4be2202271da441e27ae7c4ab2365a6035cb18d7 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
+#include <sys/un.h>
 #include <netdb.h>
 #include <string.h>
 #include <pwd.h>
@@ -72,8 +73,34 @@ int connectsock(char *host, char *service, char *protocol)
        struct servent *pse;
        struct protoent *ppe;
        struct sockaddr_in sin;
+       struct sockaddr_un sun;
        int s, type;
 
+
+       if ( (!strcmp(protocol, "unix")) || (atoi(service)<0) ) {
+               memset(&sun, 0, sizeof(sun));
+               sun.sun_family = AF_UNIX;
+               sprintf(sun.sun_path, USOCKPATH, 0-atoi(service) );
+
+               s = socket(AF_UNIX, SOCK_STREAM, 0);
+               if (s < 0) {
+                       fprintf(stderr, "Can't create socket: %s\n",
+                               strerror(errno));
+                       logoff(3);
+               }
+
+               if (connect(s, (struct sockaddr *) &sun, sizeof(sun)) < 0) {
+                       fprintf(stderr, "can't connect: %s\n",
+                               strerror(errno));
+                       logoff(3);
+               }
+
+               return s;
+       }
+
+
+       /* otherwise it's a network connection */
+
        memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;