util/sockroot

src/exec/sockclient.c in master
Repositories | Summary | Log | Files

sockclient.c (699B) download


 1#include <errno.h>
 2#include <signal.h>
 3#include <stdio.h>
 4#include <string.h>
 5#include <sys/socket.h>
 6#include <sys/un.h>
 7#include <unistd.h>
 8
 9#define SERVER_SOCK_FILE "sockroot.sock"
10
11
12int main(void) {
13	int client;
14
15	if ((client = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
16		fprintf(stderr, "error: cannot open socket: %s\n", strerror(errno));
17		return 1;
18	}
19
20	// bind socket to address
21	struct sockaddr_un addr = { 0 };
22	addr.sun_family         = AF_UNIX;
23	strncpy(addr.sun_path, SERVER_SOCK_FILE, sizeof(addr.sun_path));
24	if (connect(client, (struct sockaddr*) &addr, sizeof(addr)) == -1) {
25		fprintf(stderr, "error: cannot connect to socket: %s\n", strerror(errno));
26		return 1;
27	}
28
29
30	return 0;
31}