diff options
author | jkh <jkh@FreeBSD.org> | 1995-02-15 00:46:26 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1995-02-15 00:46:26 +0000 |
commit | 0cb129cc755064f31fb42abf2c721a8605381511 (patch) | |
tree | 87521af8f33d69817699aec072374bf2d3734e3e /gnu/usr.sbin/isdn/spy | |
download | FreeBSD-src-0cb129cc755064f31fb42abf2c721a8605381511.zip FreeBSD-src-0cb129cc755064f31fb42abf2c721a8605381511.tar.gz |
Import the ISDN userland utilities. Just about ready to start shaking
this baby out in earnest..
Diffstat (limited to 'gnu/usr.sbin/isdn/spy')
-rw-r--r-- | gnu/usr.sbin/isdn/spy/Makefile | 4 | ||||
-rw-r--r-- | gnu/usr.sbin/isdn/spy/spy.c | 108 |
2 files changed, 112 insertions, 0 deletions
diff --git a/gnu/usr.sbin/isdn/spy/Makefile b/gnu/usr.sbin/isdn/spy/Makefile new file mode 100644 index 0000000..2a9167c --- /dev/null +++ b/gnu/usr.sbin/isdn/spy/Makefile @@ -0,0 +1,4 @@ +PROG= spy +CFLAGS+= -DBSD -O + +.include <bsd.prog.mk> diff --git a/gnu/usr.sbin/isdn/spy/spy.c b/gnu/usr.sbin/isdn/spy/spy.c new file mode 100644 index 0000000..1f730c0 --- /dev/null +++ b/gnu/usr.sbin/isdn/spy/spy.c @@ -0,0 +1,108 @@ +static char rcsid[] = "@(#)$Id: spy.c,v 1.2 1995/01/25 13:41:44 jkr Exp jkr $"; +/******************************************************************************* + * II - Version 0.1 $Revision: 1.2 $ $State: Exp $ + * + * Copyright 1994 Dietmar Friede + ******************************************************************************* + * Bug reports, patches, comments, suggestions should be sent to: + * + * jkr@saarlink.de or jkrause@guug.de + * + ******************************************************************************* + * $Log: spy.c,v $ + * + ******************************************************************************/ + +#include <stdio.h> +#include <signal.h> +#include <fcntl.h> +#include <ctype.h> +#include <sys/time.h> + +#define BSIZE 1024+sizeof(struct timeval)+sizeof(unsigned long)+1 +unsigned char buf[BSIZE]; +FILE *Fout = NULL; + +static void +catchsig() +{ + printf("EXIT\n"); + exit(1); +} + +main(argc, argv) + int argc; + char **argv; +{ + int f, n; + struct timeval *t = (struct timeval *) & buf[sizeof(unsigned long) + 1]; + char *b = &buf[sizeof(struct timeval) + sizeof(unsigned long) + 1]; + struct tm *s; + + if ((f = open("/dev/ispy", O_RDONLY)) < 0) + { + perror(argv[1]); + exit(1); + } + argv++; + if (*argv) + Fout = fopen(*argv, "w"); + + (void) signal(SIGHUP, catchsig); + (void) signal(SIGTERM, catchsig); + (void) signal(SIGKILL, catchsig); + (void) signal(SIGINT, catchsig); + (void) signal(SIGQUIT, catchsig); + + for (;;) + { + n = read(f, buf, BSIZE); + n -= sizeof(struct timeval) + sizeof(unsigned long) + 1; + s = localtime(&t->tv_sec); + if (*buf) + printf("> "); + else + printf("< "); + printf("%.4d: %.2d:%.2d:%.2d.%.2d len %d:\n", *(unsigned long *) &buf[1], + s->tm_hour, s->tm_min, s->tm_sec, t->tv_usec / 10000, n); + if (Fout != NULL) + { + if (*buf) + fprintf(Fout, "> "); + else + fprintf(Fout, "< "); + fprintf(Fout, "%.4d: %.2d:%.2d:%.2d.%.2d len %d:\n", + *(unsigned long *) &buf[1], s->tm_hour, s->tm_min, + s->tm_sec, t->tv_usec / 10000, n); + } + if (n > 0) + { + dumpbuf(stdout, n, b); + if (Fout != NULL) + dumpbuf(Fout, n, b); + } + } +} + +dumpbuf(FILE * f, int n, unsigned char *buf) +{ + int i, j; + + for (i = 0; i < n; i += 16) + { + fprintf(f, "%.3x ", i); + for (j = 0; j < 16; j++) + if (i + j < n) + fprintf(f, "%02x ", buf[i + j]); + else + fprintf(f, " "); + fprintf(f, " "); + for (j = 0; j < 16 && i + j < n; j++) + if (isprint(buf[i + j])) + fprintf(f, "%c", buf[i + j]); + else + fputc('.', f); + fputc('\n', f); + } + fflush(f); +} |