From 855ccd6c97cc29efd494abe56608f44a7974d3fe Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 10 Sep 2010 10:30:53 +0200 Subject: send clients --- sircbot-send.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 sircbot-send.c (limited to 'sircbot-send.c') diff --git a/sircbot-send.c b/sircbot-send.c new file mode 100644 index 0000000..6f109d3 --- /dev/null +++ b/sircbot-send.c @@ -0,0 +1,40 @@ +#include +#include +#include + +#include +#include +#include + +int connect_channel(const char *channel_name) +{ + struct sockaddr_un sun; + int fd = socket(PF_UNIX, SOCK_STREAM, 0); + if (fd < 0) + return fd; + + sun.sun_family = AF_UNIX; + snprintf(sun.sun_path, sizeof(sun.sun_path), "/var/run/sircbot/%s", + channel_name); + if (connect(fd, (struct sockaddr *) &sun, sizeof(sun)) == 0) + return fd; + perror(sun.sun_path); + close(fd); + return -1; +} + +int main(int argc, char *argv[]) +{ + int i; + int fd = connect_channel(argv[1]); + char buf[2048]; + + if (fd < 0) + return 1; + + while (fgets(buf, sizeof(buf), stdin)) + if (write(fd, buf, strlen(buf)) < 0) + err(1, "write"); + return 0; +} + -- cgit v1.2.3