--- Makefile +++ Makefile 1996/08/15 09:34:54 @@ -13,7 +13,7 @@ #LDLIBS= -lsocket -lnsl # To override default compiler flags : -#CFLAGS=-g +CFLAGS=-O6 -fomit-frame-pointer -pipe -Wall # To change default compiler #CC=gcc @@ -22,11 +22,17 @@ 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 --- Makefile.Linux +++ Makefile.Linux 1996/08/15 09:35:08 @@ -0,0 +1,19 @@ +# +# +# Makefile.Linux to integrate package into source tree of S.u.S.E.-Linux +# +# Copyright (C) 1996 S.u.S.E. GmbH Fuerth, Germany. +# +# Please send bug-fixes or comments to feedback@suse.de. +# +# Author: Florian La Roche +# +# + +compile: + make + +install: + install -s icmpinfo /usr/sbin/ + install icmpinfo.man /usr/man/man1/icmpinfo.1 + --- icmpinfo.c +++ icmpinfo.c 1996/08/15 09:34:54 @@ -40,6 +40,12 @@ #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.10 - 8/1994 - 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.10 - 8/1994 - 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 +++ icmpinfo.man 1996/08/15 09:34:54 @@ -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 +++ pid.c 1996/08/15 09:34:54 @@ -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 +++ print.c 1996/08/15 09:34:54 @@ -122,7 +122,7 @@ if (cc>=offsetof(struct icmp,icmp_dun)+sizeof(struct ip)+offsetof(struct tcphdr,th_seq)+sizeof(tp->th_seq)) { if (noportquery) { - sprintf(prbuf+strlen(prbuf)," sp=%d dp=%d seq=0x%8.8x", + sprintf(prbuf+strlen(prbuf)," sp=%d dp=%d seq=0x%8.8lx", ntohs(tp->th_sport),ntohs(tp->th_dport), ntohl(tp->th_seq)); } else { @@ -132,11 +132,11 @@ else sprintf(prbuf+strlen(prbuf)," sp=%d",tp->th_sport); if ((servent=getservbyport(ntohs(tp->th_dport),NULL))) - sprintf(prbuf+strlen(prbuf)," dp=%d [%s] seq=0x%8.8x", + sprintf(prbuf+strlen(prbuf)," dp=%d [%s] seq=0x%8.8lx", ntohs(tp->th_dport),servent->s_name, ntohl(tp->th_seq)); else - sprintf(prbuf+strlen(prbuf)," dp=%d seq=0x%8.8x", + sprintf(prbuf+strlen(prbuf)," dp=%d seq=0x%8.8lx", ntohs(tp->th_dport),ntohl(tp->th_seq)); } } --- recvping.c +++ recvping.c 1996/08/15 09:34:54 @@ -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; --- defs.h.orig Tue Mar 25 13:57:05 1997 +++ defs.h Tue Mar 25 13:57:14 1997 @@ -15,7 +15,7 @@ to /usr/src/linux/include/linux/in_system.h */ #include #include -#include +/* #include */ /* maybe change this when linux will include a complete include tree : */ #ifdef linux #include "linux_ip_icmp.h"