diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2020-12-08 00:20:42 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2020-12-08 00:20:42 +0300 |
commit | 34a0a81ed23d9bccf9efbe92c58c85426bf41dc8 (patch) | |
tree | 545e67b745231ee3fe3cbfd39b72e6a04e1cd362 /test/testclient.c | |
parent | bb2b4ac72e099367fad6e9368844ec1d05361704 (diff) |
move test utilities to a separate directory
Diffstat (limited to 'test/testclient.c')
-rw-r--r-- | test/testclient.c | 44 |
1 files changed, 44 insertions, 0 deletions
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 <stdio.h> +#include <errno.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/stat.h> +#include <string.h> +#include <unistd.h> +#include <assert.h> +#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 |