1: /*
2: * Copyright (c) 1983 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: */
6:
7: #ifndef lint
8: char copyright[] =
9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
10: All rights reserved.\n";
11: #endif not lint
12:
13: #ifndef lint
14: static char sccsid[] = "@(#)implogd.c 5.2 (Berkeley) 5/5/86";
15: #endif not lint
16:
17: #include <sgtty.h>
18:
19: #include <sys/time.h>
20: #include <sys/param.h>
21: #include <sys/socket.h>
22: #include <sys/file.h>
23:
24: #include <netinet/in.h>
25: #include <netimp/if_imp.h>
26:
27: #define LOGFILE "/usr/adm/implog"
28:
29: u_char request[1024];
30: int marktime();
31: int options;
32: extern int errno;
33: int log;
34:
35: /*
36: * Socket address, internet style, with
37: * unused space taken by timestamp and packet
38: * size.
39: */
40: struct sockstamp {
41: short sin_family;
42: u_short sin_port;
43: struct in_addr sin_addr;
44: time_t sin_time;
45: int sin_len;
46: };
47:
48: main(argc, argv)
49: char *argv[];
50: {
51: int s;
52: time_t t;
53: struct sockstamp from;
54:
55: argc--, argv++;
56: if (argc > 0 && !strcmp(argv[0], "-d"))
57: options |= SO_DEBUG;
58: log = open(LOGFILE, O_CREAT|O_WRONLY|O_APPEND, 0644);
59: if (log < 0) {
60: perror("implogd: open");
61: exit(1);
62: }
63: from.sin_time = time(0);
64: from.sin_len = sizeof (time_t);
65: write(log, (char *)&from, sizeof (from));
66: if ((s = socket(AF_IMPLINK, SOCK_RAW, 0)) < 0) {
67: perror("implogd: socket");
68: exit(5);
69: }
70: #ifndef DEBUG
71: if (fork())
72: exit(0);
73: for (s = 0; s < 10; s++)
74: (void) close(t);
75: (void) open("/", 0);
76: (void) dup2(0, 1);
77: (void) dup2(0, 2);
78: { int tt = open("/dev/tty", 2);
79: if (tt > 0) {
80: ioctl(tt, TIOCNOTTY, 0);
81: close(tt);
82: }
83: }
84: #endif
85: for (;;) {
86: int fromlen = sizeof (from), len;
87:
88: len = recvfrom(s, request, sizeof (request), 0,
89: &from, &fromlen);
90: if (len < 0) {
91: perror("implogd: recvfrom");
92: continue;
93: }
94: if (len == 0 || len > IMPMTU) /* sanity */
95: continue;
96: from.sin_len = len;
97: from.sin_time = time(0);
98: write(log, (char *)&from, sizeof (from));
99: write(log, request, len);
100: }
101: /*NOTREACHED*/
102: }
Defined functions
main
defined in line
48;
never used
Defined variables
log
defined in line
33; used 5 times
Defined struct's
Defined macros