diff options
author | Christian Pointner <equinox@helsinki.at> | 2009-11-13 20:17:56 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2009-11-13 20:17:56 (GMT) |
commit | 81cbbd9377012377b34475ba5b8a05fb9f692d69 (patch) | |
tree | be2e907b93909e7c13991f4801e77762b71fc979 /utils.c | |
parent | 8fce4645f96514daeea47e361c881b8ba8c11439 (diff) |
added connect code
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -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) |