From 34a0a81ed23d9bccf9efbe92c58c85426bf41dc8 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Tue, 8 Dec 2020 00:20:42 +0300 Subject: move test utilities to a separate directory --- test/testclient.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test/testclient.c (limited to 'test/testclient.c') diff --git a/test/testclient.c b/test/testclient.c new file mode 100644 index 0000000..19db1c1 --- /dev/null +++ b/test/testclient.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "utils.h" + +#define ERROR_EXIT(f_, ...) { \ + fprintf(stderr, (f_), ##__VA_ARGS__); \ + return 1; \ + } + +int main() +{ + struct sockaddr_un addr = {0}; + int sock; + + // Create and connect a unix domain socket + sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock == -1) + ERROR_EXIT("socket: %s\n", strerror(errno)); + + addr.sun_family = AF_UNIX; + strcpy(&addr.sun_path[1], "/tmp/voidnsrun-test.sock"); + + if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) + ERROR_EXIT("connect: %s\n", strerror(errno)); + + int fd = recv_fd(sock); + close(sock); + + assert(fd != 0); + + struct stat st; + if (fstat(fd, &st) == -1) + ERROR_EXIT("stat: %s\n", strerror(errno)); + + printf("st_ino: %lu\n", st.st_ino); + + return 0; +} \ No newline at end of file -- cgit v1.2.3