File icmpinfo-1.11.dif of Package icmpinfo

--- Makefile
+++ Makefile
@@ -13,21 +13,32 @@
 #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
 
+DESTDIR=
+MANDIR=/usr/share/man
+
+all:	$(TARGET)
+
 $(TARGET):  $(OBJECTS)
 	$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LDLIBS)
 
+install: $(TARGET)
+	install -d -m 755 $(DESTDIR)/usr/sbin
+	install -d -m 755 $(DESTDIR)/$(MANDIR)/man1
+	install icmpinfo $(DESTDIR)/usr/sbin
+	install -m 0644 icmpinfo.man $(DESTDIR)/$(MANDIR)/man1/icmpinfo.1
+
 tgz: clean
 	rm -f CHECKSUMS.asc
 	md5sum * > ../CHECKSUMS
@@ -38,4 +49,3 @@
 
 clean:
 	$(RM) $(OBJECTS) $(TARGET) core *~
-
--- defs.h
+++ defs.h
@@ -4,24 +4,17 @@
 
 #include <stdio.h>
 #include <errno.h>
-extern int	errno;
+#include <string.h>
 
 #include <sys/time.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/file.h>
 
-/* On Linux you might also need to symlink /usr/include/netinet/in_system.h
-   to /usr/src/linux/include/linux/in_system.h */
 #include <netinet/in_systm.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
-/* maybe change this when linux will include a complete include tree : */
-#ifdef linux
-#include "linux_ip_icmp.h"
-#else
 #include <netinet/ip_icmp.h>
-#endif
 #include <netinet/tcp.h>
 #include <netdb.h>
 
--- icmpinfo.c
+++ icmpinfo.c
@@ -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 <dl@hplyot.obspm.fr>$";
+static const char sccsid[] = "@(#)ping.c	4.10 (Berkeley) 10/10/88 - $Author: icmpinfo-1.11- Laurent Demailly <dl@hplyot.obspm.fr>$";
 #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
+++ icmpinfo.man
@@ -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
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <signal.h>
+#include <unistd.h>
+
+#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
@@ -15,6 +15,7 @@
  */
 
 #include	"defs.h"
+#include <time.h>
 
 #ifndef ANSI_OFFSETOF
 #ifndef offsetof
@@ -42,7 +43,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 +65,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 +93,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 +127,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 +155,7 @@
 	    static char	a[] = "                ";
 	    int	i,j,b,n, flagNEof;
 	    unsigned char	*pbuf=(unsigned char *)buf;
-	
+
 	    n = 0;
 	    flagNEof = 1;
 	    while (flagNEof) {
@@ -249,7 +250,7 @@
 	  "PrecdCut"
 	  };
 	static char buf[80];
-	
+
 	if (t < 0 || t > 15) {
 	  sprintf(buf,"[OUT_OF_RANGE(%d)]",t);
 	} else {
@@ -257,4 +258,3 @@
         }
 	return(buf);
 }
-
--- recvping.c
+++ recvping.c
@@ -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;
openSUSE Build Service is sponsored by