blob: 80a79af7034683e550d9d05ff99fbae0b754721a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <err.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 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;
}
|