--- ./Makefile.orig Thu Aug 17 05:44:54 1995 +++ ./Makefile Wed Aug 4 21:09:21 1999 @@ -13,21 +13,27 @@ #LDLIBS= -lsocket -lnsl # To override default compiler flags : -#CFLAGS=-O2 -s +CFLAGS=-Wall -O2 -pipe -D_BSD_SOURCE # To change default compiler -#CC=gcc +CC=gcc RM = rm -f LDFLAGS= $(CFLAGS) -OBJECTS= recvping.o print.o err.o icmpinfo.o +OBJECTS= recvping.o print.o err.o icmpinfo.o pid.o TARGET = icmpinfo +all: $(TARGET) + $(TARGET): $(OBJECTS) $(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS) +install: $(TARGET) + install -s icmpinfo /usr/sbin + install -m 0644 icmpinfo.man /usr/man/man1/icmpinfo.1 + tgz: clean rm -f CHECKSUMS.asc md5sum * > ../CHECKSUMS @@ -38,4 +44,3 @@ clean: $(RM) $(OBJECTS) $(TARGET) core *~ - --- ./defs.h.orig Thu May 26 08:36:40 1994 +++ ./defs.h Wed Aug 4 21:09:21 1999 @@ -4,24 +4,17 @@ #include #include -extern int errno; +#include #include #include #include #include -/* On Linux you might also need to symlink /usr/include/netinet/in_system.h - to /usr/src/linux/include/linux/in_system.h */ #include #include #include -/* maybe change this when linux will include a complete include tree : */ -#ifdef linux -#include "linux_ip_icmp.h" -#else #include -#endif #include #include --- ./icmpinfo.c.orig Thu Aug 17 05:29:30 1995 +++ ./icmpinfo.c Wed Aug 4 21:09:21 1999 @@ -27,19 +27,25 @@ */ #ifndef lint -char copyright[] = +char const copyright[] = "@(#) Copyright (c) 1987 Regents of the University of California.\n\ All rights reserved.\n augmented 4/94 by dl\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)ping.c 4.10 (Berkeley) 10/10/88 - $Author: icmpinfo-1.11- Laurent Demailly $"; +static const char sccsid[] = "@(#)ping.c 4.10 (Berkeley) 10/10/88 - $Author: icmpinfo-1.11- Laurent Demailly $"; #endif /* not lint */ #define DCLARE /* def : */ #include "defs.h" +void pid_kill (void); +void pid_file (void); +int recv_ping (void); +int err_quit(char*); +int err_sys(char*); + /* * P I N G . C * @@ -60,7 +66,7 @@ * This program has to run SUID to ROOT to access the ICMP socket. */ -char usage[] = "Usage: icmpinfo [-v[v[v]]] [-s] [-n] [-p] [-l]\n -v : more and more info\n -s : show local interface address\n -n : no name query (dot ip only)\n -p : no port -> service name query\n -l : fork + syslog output\nv1.11 - 8/1995 - dl"; +char usage[] = "Usage: icmpinfo [-v[v[v]]] [-s] [-n] [-p] [-l] [-k]\n -v : more and more info\n -s : show local interface address\n -n : no name query (dot ip only)\n -p : no port -> service name query\n -l : fork + syslog output\n -k : kill background process\nv1.11 - 8/1995 - dl"; char *pname; int main(argc, argv) @@ -99,6 +105,10 @@ case 's': showsrcip++; break; + case 'k': + pid_kill(); + exit(0); + break; case 'h': default : err_quit(usage); @@ -128,6 +138,7 @@ openlog("icmpinfo",0,LOG_DAEMON); syslog(LOG_NOTICE,"started, PID=%d.",getpid()); setsid(); + pid_file(); close(0); close(1); close(2); --- ./icmpinfo.man.orig Thu Aug 17 05:25:11 1995 +++ ./icmpinfo.man Wed Aug 4 21:09:21 1999 @@ -6,7 +6,7 @@ .SH SYNOPSIS .B icmpinfo -[\-v[v[v]]] [\-n] [\-p] [\-s] [\-l] +[\-v[v[v]]] [\-n] [\-p] [\-s] [\-l] [\-k] .SH DESCRIPTION .BR Icmpinfo @@ -60,6 +60,13 @@ .I "\-l" Forks and use the syslog(3) facility to record events (recomended use). (root only option). + +.TP +.I "\-k" +Kills the background process started with the +.I "\-l" +option. + .SH WARNINGS The packet decoding is planned for ICMP Unreachable outputs and might not be significant for all other Icmp types. Output can be shorter --- ./pid.c.orig Wed Aug 4 21:09:21 1999 +++ ./pid.c Wed Aug 4 21:09:21 1999 @@ -0,0 +1,53 @@ +#include +#include +#include + +#define PIDFILE "/var/run/icmpinfo.pid" + +extern char *pname; + +void sig_handler(int); +void pid_file(void); +void pid_kill(void); + +void pid_file(void) +{ + FILE *fp; + + if ((fp = fopen(PIDFILE, "w")) != (FILE *)NULL) { + fprintf(fp, "%d\n", getpid()); + fclose(fp); + } + else + { + fprintf(stderr, "\n%s: Could not write PID file `%s', terminating.\n", + pname, PIDFILE); + exit(1); + } + signal(SIGHUP, sig_handler); + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); +} + +void sig_handler(int sig) +{ + unlink(PIDFILE); + exit(0); +} + +void pid_kill(void) +{ + FILE *fp; + int pid; + + if ((fp = fopen(PIDFILE, "r")) != (FILE *)NULL) + { + if (fscanf(fp, "%d", &pid) == 1) + { + kill(pid, SIGHUP); + sleep(1); + } + fclose(fp); + } +} + --- ./print.c.orig Fri Aug 25 08:37:53 1995 +++ ./print.c Wed Aug 4 21:09:21 1999 @@ -42,7 +42,7 @@ struct hostent *hostent=NULL; struct servent *servent=NULL; static char prbuf[1024]; /* provide enough room for even the longest hosts*/ - + /* * We have to look at the IP header, to get its length. * We also verify that what follows the IP header contains at @@ -64,14 +64,14 @@ cc -= iphdrlen; icp = (struct icmp *)(buf + iphdrlen); - switch (icp->icmp_type) + switch (icp->icmp_type) { case ICMP_ECHO : case ICMP_ECHOREPLY : doipdecoding=0; if (verbose<2) break; case ICMP_SOURCEQUENCH : - case ICMP_TIMXCEED : + case ICMP_TIMXCEED : case ICMP_REDIRECT : if (!verbose) break; default : @@ -92,10 +92,10 @@ inet_ntoa(from->sin_addr), hostent?hostent->h_name:NULL ); - if ( doipdecoding && + if ( doipdecoding && ( cc >= offsetof(struct icmp,icmp_ip.ip_src)+sizeof(icp->icmp_ip.ip_dst) ) ) { - if (showsrcip) + if (showsrcip) { /* icp->icmp_ip.ip_src.s_addr == local host, show it only if requested (might be usefull for host with several interfaces */ @@ -126,12 +126,12 @@ ntohs(tp->th_sport),ntohs(tp->th_dport), ntohl(tp->th_seq)); } else { - if ((servent=getservbyport(ntohs(tp->th_sport),NULL))) + if ((servent=getservbyport(ntohs(tp->th_sport),NULL))) sprintf(prbuf+strlen(prbuf)," sp=%d [%s]", ntohs(tp->th_sport),servent->s_name); else sprintf(prbuf+strlen(prbuf)," sp=%d",tp->th_sport); - if ((servent=getservbyport(ntohs(tp->th_dport),NULL))) + if ((servent=getservbyport(ntohs(tp->th_dport),NULL))) sprintf(prbuf+strlen(prbuf)," dp=%d [%s] seq=0x%8.8x", ntohs(tp->th_dport),servent->s_name, ntohl(tp->th_seq)); @@ -154,7 +154,7 @@ static char a[] = " "; int i,j,b,n, flagNEof; unsigned char *pbuf=(unsigned char *)buf; - + n = 0; flagNEof = 1; while (flagNEof) { @@ -249,7 +249,7 @@ "PrecdCut" }; static char buf[80]; - + if (t < 0 || t > 15) { sprintf(buf,"[OUT_OF_RANGE(%d)]",t); } else { @@ -257,4 +257,3 @@ } return(buf); } - --- ./recvping.c.orig Fri Jan 7 05:04:04 1994 +++ ./recvping.c Wed Aug 4 21:09:21 1999 @@ -6,6 +6,9 @@ #include "defs.h" +int err_ret(char *); +int pr_pack(char *, int, struct sockaddr_in *); + int recv_ping() { register int n;