121139Sdist /* 234772Sbostic * Copyright (c) 1983, 1988 Regents of the University of California. 333457Skarels * All rights reserved. 433457Skarels * 5*42798Sbostic * %sccs.include.redist.c% 621139Sdist */ 721139Sdist 89198Ssam #ifndef lint 921139Sdist char copyright[] = 1034772Sbostic "@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\ 1121139Sdist All rights reserved.\n"; 1234772Sbostic #endif /* not lint */ 136480Ssam 1421139Sdist #ifndef lint 15*42798Sbostic static char sccsid[] = "@(#)implogd.c 5.9 (Berkeley) 06/01/90"; 1634772Sbostic #endif /* not lint */ 1721139Sdist 1837279Sbostic #include <sys/param.h> 1913601Ssam #include <sys/time.h> 206480Ssam #include <sys/socket.h> 2129429Skarels #include <sys/syslog.h> 229251Ssam #include <sys/file.h> 236480Ssam 2433456Skarels #include <net/if.h> 2533456Skarels 269196Ssam #include <netinet/in.h> 279251Ssam #include <netimp/if_imp.h> 289196Ssam 2937279Sbostic #include <sgtty.h> 3037279Sbostic #include "pathnames.h" 316480Ssam 326480Ssam /* 336480Ssam * Socket address, internet style, with 346480Ssam * unused space taken by timestamp and packet 356480Ssam * size. 366480Ssam */ 376480Ssam struct sockstamp { 386480Ssam short sin_family; 396480Ssam u_short sin_port; 406480Ssam struct in_addr sin_addr; 416480Ssam time_t sin_time; 429196Ssam int sin_len; 436480Ssam }; 446480Ssam 4537279Sbostic main() 466480Ssam { 4737279Sbostic register int len, log, s; 489196Ssam struct sockstamp from; 4937279Sbostic int fromlen; 5037279Sbostic u_char request[1024]; 5137279Sbostic time_t time(); 526480Ssam 5337279Sbostic openlog("implogd", LOG_PID|LOG_ODELAY|LOG_PERROR, LOG_DAEMON); 5437279Sbostic log = open(_PATH_IMPLOG, O_CREAT|O_WRONLY|O_APPEND, 0644); 5527728Skarels if (log < 0) { 5637279Sbostic syslog(LOG_ERR, "%s: %m\n", _PATH_IMPLOG); 5727728Skarels exit(1); 5827728Skarels } 5937279Sbostic from.sin_time = time((time_t *)NULL); 6037279Sbostic from.sin_len = sizeof(time_t); 6137279Sbostic (void)write(log, (char *)&from, sizeof(from)); 6227728Skarels if ((s = socket(AF_IMPLINK, SOCK_RAW, 0)) < 0) { 6329429Skarels syslog(LOG_ERR, "socket: %m\n"); 6437279Sbostic exit(1); 6527728Skarels } 668457Ssam #ifndef DEBUG 6737279Sbostic { 6837279Sbostic register int i, tt; 6937279Sbostic 7037279Sbostic if (fork()) 7137279Sbostic exit(0); 7237279Sbostic for (i = 0; i < 10; i++) 7337279Sbostic if (i != log && i != s) 7437279Sbostic (void) close(i); 7537279Sbostic (void) open("/", O_RDONLY, 0); 7637279Sbostic (void) dup2(0, 1); 7737279Sbostic (void) dup2(0, 2); 7837965Sbostic tt = open(_PATH_TTY, O_RDWR, 0); 7937279Sbostic if (tt > 0) { 8037279Sbostic ioctl(tt, TIOCNOTTY, 0); 8137279Sbostic (void)close(tt); 8237279Sbostic } 836480Ssam } 848457Ssam #endif 8537279Sbostic for (fromlen = sizeof(from);;) { 8637279Sbostic len = recvfrom(s, request, sizeof(request), 0, 8737279Sbostic &from, &fromlen); 8812237Ssam if (len < 0) { 8929429Skarels syslog(LOG_ERR, "recvfrom: %m\n"); 906480Ssam continue; 919251Ssam } 9237279Sbostic if (len == 0 || len > IMPMTU) /* sanity */ 936480Ssam continue; 949196Ssam from.sin_len = len; 9537279Sbostic from.sin_time = time((time_t *)NULL); 9637279Sbostic (void)write(log, (char *)&from, sizeof(from)); 9737279Sbostic (void)write(log, request, len); 986480Ssam } 996480Ssam /*NOTREACHED*/ 1006480Ssam } 101