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 56 57 58 59 60
|
/* fiforead: read from 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);
main(int argc, char **argv)
{
struct sockaddr_un mysun,remsun;
int size;
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 (Verbose)
fprintf(stderr,"opening unix socket on %s\n", mysun.sun_path);
if ((sock = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
die("socket");
}
if (bind(sock, (struct sockaddr *)&mysun, sizeof(mysun)) < 0
&& errno != EADDRINUSE) {
die(mysun.sun_path);
}
size = sizeof(remsun);
while ((n = recvfrom(sock,buf,sizeof(buf),0,(struct sockaddr *)&remsun,&size)) >= 0) {
printf("read %d: %*.*s\n",n,n,n,buf);
size = sizeof(remsun);
}
}
static void
die(char *s)
{
perror(s);
exit(1);
}
|