19198Ssam #ifndef lint 2*13601Ssam static char sccsid[] = "@(#)implogd.c 4.8 (Berkeley) 07/01/83"; 39198Ssam #endif 46480Ssam 56480Ssam #include <sgtty.h> 69196Ssam 7*13601Ssam #include <sys/time.h> 89251Ssam #include <sys/param.h> 96480Ssam #include <sys/socket.h> 109251Ssam #include <sys/file.h> 116480Ssam 129196Ssam #include <netinet/in.h> 139251Ssam #include <netimp/if_imp.h> 149196Ssam 156480Ssam #define LOGFILE "/usr/adm/implog" 166480Ssam 176480Ssam u_char request[1024]; 186480Ssam int marktime(); 196480Ssam int options; 206480Ssam extern int errno; 216480Ssam int log; 226480Ssam 236480Ssam /* 246480Ssam * Socket address, internet style, with 256480Ssam * unused space taken by timestamp and packet 266480Ssam * size. 276480Ssam */ 286480Ssam struct sockstamp { 296480Ssam short sin_family; 306480Ssam u_short sin_port; 316480Ssam struct in_addr sin_addr; 326480Ssam time_t sin_time; 339196Ssam int sin_len; 346480Ssam }; 356480Ssam 366480Ssam main(argc, argv) 376480Ssam char *argv[]; 386480Ssam { 399196Ssam int s; 406480Ssam time_t t; 419196Ssam struct sockstamp from; 426480Ssam 436480Ssam argc--, argv++; 446480Ssam if (argc > 0 && !strcmp(argv[0], "-d")) 456480Ssam options |= SO_DEBUG; 468457Ssam #ifndef DEBUG 478457Ssam if (fork()) 488457Ssam exit(0); 498457Ssam for (s = 0; s < 10; s++) 508457Ssam (void) close(t); 518457Ssam (void) open("/", 0); 528457Ssam (void) dup2(0, 1); 538457Ssam (void) dup2(0, 2); 548457Ssam { int tt = open("/dev/tty", 2); 558457Ssam if (tt > 0) { 568457Ssam ioctl(tt, TIOCNOTTY, 0); 578457Ssam close(tt); 588457Ssam } 596480Ssam } 608457Ssam #endif 6113037Ssam log = open(LOGFILE, O_CREAT|O_WRONLY|O_APPEND, 0644); 629251Ssam if (log < 0) { 639251Ssam perror("implogd: open"); 646480Ssam exit(1); 659251Ssam } 666480Ssam from.sin_time = time(0); 679196Ssam from.sin_len = sizeof (time_t); 689196Ssam write(log, (char *)&from, sizeof (from)); 699251Ssam while ((s = socket(AF_IMPLINK, SOCK_RAW, 0, 0)) < 0) { 709251Ssam perror("implogd: socket"); 716480Ssam sleep(5); 726480Ssam } 736480Ssam for (;;) { 7412237Ssam int fromlen = sizeof (from), len; 759196Ssam 7612237Ssam len = recvfrom(s, request, sizeof (request), 0, 7712237Ssam &from, &fromlen); 7812237Ssam if (len < 0) { 799251Ssam perror("implogd: recvfrom"); 806480Ssam continue; 819251Ssam } 8212237Ssam if (len == 0 || len > IMPMTU) /* sanity */ 836480Ssam continue; 849196Ssam from.sin_len = len; 856480Ssam from.sin_time = time(0); 869196Ssam write(log, (char *)&from, sizeof (from)); 879196Ssam write(log, request, len); 886480Ssam } 896480Ssam /*NOTREACHED*/ 906480Ssam } 91