121139Sdist /* 234772Sbostic * Copyright (c) 1983, 1988 Regents of the University of California. 333457Skarels * All rights reserved. 433457Skarels * 533457Skarels * Redistribution and use in source and binary forms are permitted 634772Sbostic * provided that the above copyright notice and this paragraph are 734772Sbostic * duplicated in all such forms and that any documentation, 834772Sbostic * advertising materials, and other materials related to such 934772Sbostic * distribution and use acknowledge that the software was developed 1034772Sbostic * by the University of California, Berkeley. The name of the 1134772Sbostic * University may not be used to endorse or promote products derived 1234772Sbostic * from this software without specific prior written permission. 1334772Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1434772Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1534772Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1621139Sdist */ 1721139Sdist 189198Ssam #ifndef lint 1921139Sdist char copyright[] = 2034772Sbostic "@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\ 2121139Sdist All rights reserved.\n"; 2234772Sbostic #endif /* not lint */ 236480Ssam 2421139Sdist #ifndef lint 25*37279Sbostic static char sccsid[] = "@(#)implogd.c 5.7 (Berkeley) 04/02/89"; 2634772Sbostic #endif /* not lint */ 2721139Sdist 28*37279Sbostic #include <sys/param.h> 2913601Ssam #include <sys/time.h> 306480Ssam #include <sys/socket.h> 3129429Skarels #include <sys/syslog.h> 329251Ssam #include <sys/file.h> 336480Ssam 3433456Skarels #include <net/if.h> 3533456Skarels 369196Ssam #include <netinet/in.h> 379251Ssam #include <netimp/if_imp.h> 389196Ssam 39*37279Sbostic #include <sgtty.h> 40*37279Sbostic #include "pathnames.h" 416480Ssam 426480Ssam /* 436480Ssam * Socket address, internet style, with 446480Ssam * unused space taken by timestamp and packet 456480Ssam * size. 466480Ssam */ 476480Ssam struct sockstamp { 486480Ssam short sin_family; 496480Ssam u_short sin_port; 506480Ssam struct in_addr sin_addr; 516480Ssam time_t sin_time; 529196Ssam int sin_len; 536480Ssam }; 546480Ssam 55*37279Sbostic main() 566480Ssam { 57*37279Sbostic register int len, log, s; 589196Ssam struct sockstamp from; 59*37279Sbostic int fromlen; 60*37279Sbostic u_char request[1024]; 61*37279Sbostic time_t time(); 626480Ssam 63*37279Sbostic openlog("implogd", LOG_PID|LOG_ODELAY|LOG_PERROR, LOG_DAEMON); 64*37279Sbostic log = open(_PATH_IMPLOG, O_CREAT|O_WRONLY|O_APPEND, 0644); 6527728Skarels if (log < 0) { 66*37279Sbostic syslog(LOG_ERR, "%s: %m\n", _PATH_IMPLOG); 6727728Skarels exit(1); 6827728Skarels } 69*37279Sbostic from.sin_time = time((time_t *)NULL); 70*37279Sbostic from.sin_len = sizeof(time_t); 71*37279Sbostic (void)write(log, (char *)&from, sizeof(from)); 7227728Skarels if ((s = socket(AF_IMPLINK, SOCK_RAW, 0)) < 0) { 7329429Skarels syslog(LOG_ERR, "socket: %m\n"); 74*37279Sbostic exit(1); 7527728Skarels } 768457Ssam #ifndef DEBUG 77*37279Sbostic { 78*37279Sbostic register int i, tt; 79*37279Sbostic 80*37279Sbostic if (fork()) 81*37279Sbostic exit(0); 82*37279Sbostic for (i = 0; i < 10; i++) 83*37279Sbostic if (i != log && i != s) 84*37279Sbostic (void) close(i); 85*37279Sbostic (void) open("/", O_RDONLY, 0); 86*37279Sbostic (void) dup2(0, 1); 87*37279Sbostic (void) dup2(0, 2); 88*37279Sbostic tt = open("/dev/tty", O_RDWR, 0); 89*37279Sbostic if (tt > 0) { 90*37279Sbostic ioctl(tt, TIOCNOTTY, 0); 91*37279Sbostic (void)close(tt); 92*37279Sbostic } 936480Ssam } 948457Ssam #endif 95*37279Sbostic for (fromlen = sizeof(from);;) { 96*37279Sbostic len = recvfrom(s, request, sizeof(request), 0, 97*37279Sbostic &from, &fromlen); 9812237Ssam if (len < 0) { 9929429Skarels syslog(LOG_ERR, "recvfrom: %m\n"); 1006480Ssam continue; 1019251Ssam } 102*37279Sbostic if (len == 0 || len > IMPMTU) /* sanity */ 1036480Ssam continue; 1049196Ssam from.sin_len = len; 105*37279Sbostic from.sin_time = time((time_t *)NULL); 106*37279Sbostic (void)write(log, (char *)&from, sizeof(from)); 107*37279Sbostic (void)write(log, request, len); 1086480Ssam } 1096480Ssam /*NOTREACHED*/ 1106480Ssam } 111