1*6480Ssam /* implogd.c 4.1 82/04/04 */ 2*6480Ssam 3*6480Ssam #include <time.h> 4*6480Ssam #include <sgtty.h> 5*6480Ssam #include <sys/types.h> 6*6480Ssam #include <sys/socket.h> 7*6480Ssam #include <net/in.h> 8*6480Ssam 9*6480Ssam #define LOGFILE "/usr/adm/implog" 10*6480Ssam #define IMPMTU ((8159 / 8) & ~01) 11*6480Ssam 12*6480Ssam u_char request[1024]; 13*6480Ssam int marktime(); 14*6480Ssam int options; 15*6480Ssam extern int errno; 16*6480Ssam int log; 17*6480Ssam 18*6480Ssam /* 19*6480Ssam * Socket address, internet style, with 20*6480Ssam * unused space taken by timestamp and packet 21*6480Ssam * size. 22*6480Ssam */ 23*6480Ssam struct sockstamp { 24*6480Ssam short sin_family; 25*6480Ssam u_short sin_port; 26*6480Ssam struct in_addr sin_addr; 27*6480Ssam time_t sin_time; 28*6480Ssam int sin_cc; 29*6480Ssam }; 30*6480Ssam 31*6480Ssam struct sockproto improto = { PF_IMPLINK, 0 }; 32*6480Ssam struct sockstamp from; 33*6480Ssam 34*6480Ssam main(argc, argv) 35*6480Ssam char *argv[]; 36*6480Ssam { 37*6480Ssam int s, cc; 38*6480Ssam time_t t; 39*6480Ssam 40*6480Ssam argc--, argv++; 41*6480Ssam if (argc > 0 && !strcmp(argv[0], "-d")) 42*6480Ssam options |= SO_DEBUG; 43*6480Ssam s = open("/dev/tty", 2); 44*6480Ssam if (s >= 0) { 45*6480Ssam ioctl(s, TIOCNOTTY, 0); 46*6480Ssam close(s); 47*6480Ssam } 48*6480Ssam log = open(LOGFILE, 1); 49*6480Ssam if (log < 0) 50*6480Ssam exit(1); 51*6480Ssam lseek(log, 0L, 2); 52*6480Ssam from.sin_time = time(0); 53*6480Ssam from.sin_cc = sizeof(time_t); 54*6480Ssam write(log, (char *)&from, sizeof(from)); 55*6480Ssam again: 56*6480Ssam errno = 0; 57*6480Ssam if ((s = socket(SOCK_RAW, &improto, 0, options)) < 0) { 58*6480Ssam perror("socket"); 59*6480Ssam sleep(5); 60*6480Ssam goto again; 61*6480Ssam } 62*6480Ssam for (;;) { 63*6480Ssam cc = receive(s, &from, request, sizeof(request)); 64*6480Ssam if (cc <= 0) 65*6480Ssam continue; 66*6480Ssam if (cc > IMPMTU) /* sanity */ 67*6480Ssam continue; 68*6480Ssam from.sin_cc = cc; 69*6480Ssam from.sin_time = time(0); 70*6480Ssam write(log, (char *)&from, sizeof(from)); 71*6480Ssam write(log, request, cc); 72*6480Ssam } 73*6480Ssam /*NOTREACHED*/ 74*6480Ssam } 75