From 9a88f7da453eadc72d8f333700dbd80777feecd1 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 25 Feb 2018 14:33:19 +0100 Subject: Initial commit Signed-off-by: David Oberhollenzer --- lib/src/opensock.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/src/opensock.c (limited to 'lib/src/opensock.c') 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 +#include +#include +#include +#include +#include + +#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; +} -- cgit v1.2.3