aboutsummaryrefslogtreecommitdiffstats
path: root/sircbot-send.c
diff options
context:
space:
mode:
Diffstat (limited to 'sircbot-send.c')
-rw-r--r--sircbot-send.c40
1 files changed, 40 insertions, 0 deletions
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 <sys/stat.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+
+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;
+}
+