-
Notifications
You must be signed in to change notification settings - Fork 8
/
fifowrite.c
56 lines (48 loc) · 1 KB
/
fifowrite.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* fifowrite: write to the aprsdigi fifo */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <signal.h>
#include <errno.h>
int Verbose = 1;
static void die(char *s);
int
main(int argc, char **argv)
{
struct sockaddr_un mysun;
int sock;
u_char buf[1024];
int n;
if (argc != 2) {
fprintf(stderr,"Usage: %s file\n", argv[0]);
exit(1);
}
bzero(&mysun,sizeof(mysun));
mysun.sun_family = AF_UNIX;
strncpy(mysun.sun_path,argv[1],sizeof(mysun.sun_path));
if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
die("socket");
}
while (fgets(buf,sizeof(buf),stdin)) {
int sent;
if ((sent = sendto(sock,buf,strlen(buf),0,(struct sockaddr *)&mysun,
sizeof(mysun))) < 0)
die("sendto");
}
}
static void
die(char *s)
{
perror(s);
exit(1);
}