diff options
author | phoebos <phoebos@tilde.institute> | 2023-05-27 15:04:10 +0000 |
---|---|---|
committer | phoebos <phoebos@tilde.institute> | 2023-05-27 15:04:10 +0000 |
commit | 6139188d408ef5e107c1afaec1495c42d942d113 (patch) | |
tree | 0e0df4f6c04fce80db210d4e3922563da5696826 | |
parent | af1c0b7a5559456f8e431d1681416b897358605f (diff) | |
download | cbot-6139188d408ef5e107c1afaec1495c42d942d113.tar.gz |
test unix socket
-rw-r--r-- | client-test.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/client-test.c b/client-test.c new file mode 100644 index 0000000..1a8638d --- /dev/null +++ b/client-test.c @@ -0,0 +1,29 @@ +#include <err.h> +#include <errno.h> +#include <poll.h> +#include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <unistd.h> + +#define SOCK_PATH "/tmp/kissbot" + +int +main(void) { + struct sockaddr_un remote = {.sun_family = AF_UNIX}; + int s = socket(AF_UNIX, SOCK_STREAM, 0); + if (s == -1) + err(1, "socket"); + + strlcpy(remote.sun_path, SOCK_PATH, + sizeof(remote.sun_path)-1); + if (connect(s, (struct sockaddr *)&remote, + sizeof(SOCK_PATH) + sizeof(remote.sun_family)) == -1) + err(1, "connect"); + char msg[] = "Hi, test message 1!\n"; + if (send(s, msg, sizeof(msg), 0) == -1) + err(1, "send"); + close(s); + return 0; +} |