aboutsummaryrefslogtreecommitdiff
path: root/lib/src/opensock.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-02-25 14:33:19 +0100
committerDavid Oberhollenzer <david.oberhollenzer@tele2.at>2018-03-24 17:04:20 +0100
commit9a88f7da453eadc72d8f333700dbd80777feecd1 (patch)
tree8a096e37123ece1d20bcb4d0ae8e064bdd39747a /lib/src/opensock.c
Initial commit
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
Diffstat (limited to 'lib/src/opensock.c')
-rw-r--r--lib/src/opensock.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/src/opensock.c b/lib/src/opensock.c
new file mode 100644
index 0000000..06101ef
--- /dev/null
+++ b/lib/src/opensock.c
@@ -0,0 +1,33 @@
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "telinit.h"
+
+int opensock(void)
+{
+ struct sockaddr_un un;
+ int fd;
+
+ fd = socket(AF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ perror("socket");
+ return -1;
+ }
+
+ memset(&un, 0, sizeof(un));
+ un.sun_family = AF_UNIX;
+
+ strcpy(un.sun_path, INITSOCK);
+
+ if (connect(fd, (struct sockaddr *)&un, sizeof(un))) {
+ perror("connect: " INITSOCK);
+ close(fd);
+ return -1;
+ }
+
+ return fd;
+}