From 81cbbd9377012377b34475ba5b8a05fb9f692d69 Mon Sep 17 00:00:00 2001
From: Christian Pointner <equinox@helsinki.at>
Date: Fri, 13 Nov 2009 20:17:56 +0000
Subject: added connect code


diff --git a/utils.c b/utils.c
index f2ca2a7..6178d3b 100644
--- a/utils.c
+++ b/utils.c
@@ -66,7 +66,27 @@ int init_command_socket(const char* path)
 
 int connect_command_socket(const char* path)
 {
-  return -1;
+  int fd = socket(AF_UNIX, SOCK_STREAM, 0);
+  if(fd < 0) {
+    log_printf(ERROR, "unable to open socket: %s", strerror(errno));
+    return -1;
+  }
+
+  struct sockaddr_un remote;
+  remote.sun_family = AF_UNIX;
+  if(sizeof(remote.sun_path) <= strlen(path)) {
+    log_printf(ERROR, "socket path is to long (max %d)", sizeof(remote.sun_path)-1);
+    return -1;
+  }
+  strcpy(remote.sun_path, path);
+  int len = SUN_LEN(&remote);
+  int ret = connect(fd, (struct sockaddr*)&remote, len);
+  if(ret) {
+    log_printf(ERROR, "unable to connect to '%s': %s", remote.sun_path, strerror(errno));
+    return -1;
+  }
+
+  return fd;
 }
 
 int send_string(int fd, const char* string)
-- 
cgit v0.10.2