summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2009-11-13 20:17:56 (GMT)
committerChristian Pointner <equinox@helsinki.at>2009-11-13 20:17:56 (GMT)
commit81cbbd9377012377b34475ba5b8a05fb9f692d69 (patch)
treebe2e907b93909e7c13991f4801e77762b71fc979 /utils.c
parent8fce4645f96514daeea47e361c881b8ba8c11439 (diff)
added connect code
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c22
1 files changed, 21 insertions, 1 deletions
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)