file reorg, pathnames.h, paths.h
[unix-history] / usr / src / old / implogd / implogd.c
CommitLineData
19538291 1/*
b8c620d6 2 * Copyright (c) 1983, 1988 Regents of the University of California.
df2b70fd
MK
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
b8c620d6
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19538291
DF
16 */
17
18#ifndef lint
19char copyright[] =
b8c620d6 20"@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\
19538291 21 All rights reserved.\n";
b8c620d6 22#endif /* not lint */
19538291 23
28b5b7e7 24#ifndef lint
7abf8d65 25static char sccsid[] = "@(#)implogd.c 5.8 (Berkeley) %G%";
b8c620d6 26#endif /* not lint */
6046cba1 27
fdaa1466 28#include <sys/param.h>
ac4316d8 29#include <sys/time.h>
6046cba1 30#include <sys/socket.h>
18148cbb 31#include <sys/syslog.h>
fdaa1466 32#include <sys/file.h>
56013160 33
ae92ba7a
MK
34#include <net/if.h>
35
56013160 36#include <netinet/in.h>
fdaa1466 37#include <netimp/if_imp.h>
6046cba1 38
ac4316d8
KB
39#include <sgtty.h>
40#include "pathnames.h"
6046cba1
SL
41
42/*
43 * Socket address, internet style, with
44 * unused space taken by timestamp and packet
45 * size.
46 */
47struct sockstamp {
48 short sin_family;
49 u_short sin_port;
50 struct in_addr sin_addr;
51 time_t sin_time;
56013160 52 int sin_len;
6046cba1
SL
53};
54
ac4316d8 55main()
6046cba1 56{
ac4316d8 57 register int len, log, s;
56013160 58 struct sockstamp from;
ac4316d8
KB
59 int fromlen;
60 u_char request[1024];
61 time_t time();
6046cba1 62
ac4316d8
KB
63 openlog("implogd", LOG_PID|LOG_ODELAY|LOG_PERROR, LOG_DAEMON);
64 log = open(_PATH_IMPLOG, O_CREAT|O_WRONLY|O_APPEND, 0644);
28026947 65 if (log < 0) {
ac4316d8 66 syslog(LOG_ERR, "%s: %m\n", _PATH_IMPLOG);
28026947
MK
67 exit(1);
68 }
ac4316d8
KB
69 from.sin_time = time((time_t *)NULL);
70 from.sin_len = sizeof(time_t);
71 (void)write(log, (char *)&from, sizeof(from));
28026947 72 if ((s = socket(AF_IMPLINK, SOCK_RAW, 0)) < 0) {
18148cbb 73 syslog(LOG_ERR, "socket: %m\n");
ac4316d8 74 exit(1);
28026947 75 }
16f092bf 76#ifndef DEBUG
ac4316d8
KB
77 {
78 register int i, tt;
79
80 if (fork())
81 exit(0);
82 for (i = 0; i < 10; i++)
83 if (i != log && i != s)
84 (void) close(i);
85 (void) open("/", O_RDONLY, 0);
86 (void) dup2(0, 1);
87 (void) dup2(0, 2);
7abf8d65 88 tt = open(_PATH_TTY, O_RDWR, 0);
ac4316d8
KB
89 if (tt > 0) {
90 ioctl(tt, TIOCNOTTY, 0);
91 (void)close(tt);
92 }
6046cba1 93 }
16f092bf 94#endif
ac4316d8
KB
95 for (fromlen = sizeof(from);;) {
96 len = recvfrom(s, request, sizeof(request), 0,
97 &from, &fromlen);
fecd8ea3 98 if (len < 0) {
18148cbb 99 syslog(LOG_ERR, "recvfrom: %m\n");
6046cba1 100 continue;
fdaa1466 101 }
ac4316d8 102 if (len == 0 || len > IMPMTU) /* sanity */
6046cba1 103 continue;
56013160 104 from.sin_len = len;
ac4316d8
KB
105 from.sin_time = time((time_t *)NULL);
106 (void)write(log, (char *)&from, sizeof(from));
107 (void)write(log, request, len);
6046cba1
SL
108 }
109 /*NOTREACHED*/
110}