Description: convert direct changes in upstream code to quilt.
Author: Joao Eriberto Mota Filho <eriberto@debian.org>
Last-Update: 2015-09-07
Index: icmpinfo-1.11/Makefile
===================================================================
--- icmpinfo-1.11.orig/Makefile
+++ icmpinfo-1.11/Makefile
@@ -22,7 +22,7 @@ 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
 
 $(TARGET):  $(OBJECTS)
Index: icmpinfo-1.11/defs.h
===================================================================
--- icmpinfo-1.11.orig/defs.h
+++ icmpinfo-1.11/defs.h
@@ -1,12 +1,12 @@
 /*
  * Includes, defines and global variables used between functions.
  */
-
 #include <stdio.h>
+#include <stdlib.h>
 #include <errno.h>
 extern int	errno;
 
-#include <sys/time.h>
+#include <time.h>
 #include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/file.h>
@@ -24,7 +24,6 @@ extern int	errno;
 #endif
 #include <netinet/tcp.h>
 #include <netdb.h>
-
 #include <syslog.h>
 #include <unistd.h>
 
@@ -53,6 +52,14 @@ DCLARE int     showsrcip;    /*  flag fo
 DCLARE int     syslogdoutput; /* flag for stdoutput / syslogd output */
 DCLARE int     noportquery;   /* flag for query/noquery of port -> serv name */
 
+int err_ret(char *);
+int pr_pack(char *, int, struct sockaddr_in *);
+void pid_file(void);
+void pid_kill(void);
+int err_quit(char *);
+int err_sys(char *);
+void recv_ping(void);
+
 /* on some hosts (linux) netinet/ip_icmp.h is missing/empty : */
 #ifndef ICMP_MINLEN
 int bug=You_need_an_non_empty_netinet_ip_icmp_h;
Index: icmpinfo-1.11/err.c
===================================================================
--- icmpinfo-1.11.orig/err.c
+++ icmpinfo-1.11/err.c
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <stdlib.h>
 
 extern char *pname;
 
Index: icmpinfo-1.11/icmpinfo.c
===================================================================
--- icmpinfo-1.11.orig/icmpinfo.c
+++ icmpinfo-1.11/icmpinfo.c
@@ -62,7 +62,7 @@ static char sccsid[] = "@(#)ping.c	4.10
  *	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)
@@ -101,6 +101,11 @@ char	**argv;
 			case 's':
 				showsrcip++;
 				break;
+			case 'k':
+				pid_kill();
+				exit(0);
+				/*NOTREACHED*/
+				break;
 			case 'h':
 		        default :
 				err_quit(usage);
@@ -130,6 +135,7 @@ char	**argv;
 	  openlog("icmpinfo",0,LOG_DAEMON);
 	  syslog(LOG_NOTICE,"started, PID=%d.",getpid());
 	  setsid();
+	  pid_file();
 	  close(0);
 	  close(1);
 	  close(2);
Index: icmpinfo-1.11/icmpinfo.man
===================================================================
--- icmpinfo-1.11.orig/icmpinfo.man
+++ icmpinfo-1.11/icmpinfo.man
@@ -1,12 +1,10 @@
-.TH ICMPINFO 1 "V1.11 - 28 August 1995" "dl's free utilities"
+.TH ICMPINFO 8 "V1.11 - 28 August 1995" "dl's free utilities"
 .SH NAME
-
 icmpinfo \- interpret ICMP messages
-
 .SH SYNOPSIS
 
 .B icmpinfo
-[\-v[v[v]]] [\-n] [\-p] [\-s] [\-l]
+[\-v[v[v]]] [\-n] [\-p] [\-s] [\-l] [\-k]
 
 .SH DESCRIPTION
 .BR Icmpinfo
@@ -52,14 +50,21 @@ Avoid port number to service name decodi
 
 .TP
 .I "\-s"
-Show the interface ip that received the packet. Usefull only if your
+Show the interface ip that received the packet. Useful only if your
 host has several network interfaces. In this case an '- my_ip
 [my_name]' is added between the sender and unreach ip and name fields.
 
 .TP
 .I "\-l"
-Forks and use the syslog(3) facility to record events (recomended use).
+Forks and use the syslog(3) facility to record events (recommended 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
Index: icmpinfo-1.11/linux_ip_icmp.h
===================================================================
--- icmpinfo-1.11.orig/linux_ip_icmp.h
+++ icmpinfo-1.11/linux_ip_icmp.h
@@ -3,6 +3,8 @@
 #ifndef _netinet_ip_icmp_h
 #define _netinet_ip_icmp_h
 
+#include <netinet/ip.h>
+
 struct icmp {
 	u_char	icmp_type;		/* type of message, see below */
 	u_char	icmp_code;		/* type sub code */
@@ -22,6 +24,7 @@ struct icmp {
 #define	icmp_seq	icmp_hun.ih_idseq.icd_seq
 #define	icmp_void	icmp_hun.ih_void
 
+#if 0
 struct ip {
         u_char  ip_hl:4,                /* header length */
         ip_v:4;                 /* version */
@@ -36,6 +39,7 @@ struct ip {
         u_short ip_sum;                 /* checksum */
         struct  in_addr ip_src,ip_dst;  /* source and dest address */
       };
+#endif
 
 
 	union {
Index: icmpinfo-1.11/pid.c
===================================================================
--- /dev/null
+++ icmpinfo-1.11/pid.c
@@ -0,0 +1,52 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+
+#define PIDFILE                 "/var/run/icmpinfo.pid"
+
+extern char *pname;
+
+void sig_handler(int);
+
+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);
+    }
+}
+ 
Index: icmpinfo-1.11/print.c
===================================================================
--- icmpinfo-1.11.orig/print.c
+++ icmpinfo-1.11/print.c
@@ -8,8 +8,11 @@
 /* note : the original bsd code was *very* buggy !!!
           it should be ok, now */
 
+#include <string.h>
+#include <stddef.h>
 #include	"defs.h"
 
+
 #ifndef ANSI_OFFSETOF
 #ifndef offsetof
 #        define offsetof(t,m)  (int)((&((t *)0L)->m))
@@ -28,6 +31,7 @@ int			cc;	/* total size of received pack
 struct sockaddr_in	*from;	/* address of sender */
 {
   int			iphdrlen,doipdecoding=1;
+  int                  iplen;
   struct ip		*ip;	/* ptr to IP header */
   register struct icmp	*icp;	/* ptr to ICMP header */
   struct tcphdr 	*tp;    /* ptr to TCP header */
@@ -35,7 +39,7 @@ struct sockaddr_in	*from;	/* address of
   char			*pr_type(),*pr_subtype(),*strtime;
   struct hostent	*hostent=NULL;
   struct servent	*servent=NULL;
-  static char prbuf[1024];	/* provide enough room for even the longest hosts*/
+  static char prbuf[1024]={'\0'};	/* provide enough room for even the longest hosts*/
 	
   /*
    * We have to look at the IP header, to get its length.
@@ -44,17 +48,18 @@ struct sockaddr_in	*from;	/* address of
    */
   ip = (struct ip *) buf;
   iphdrlen = ip->ip_hl << 2;	/* convert # 16-bit words to #bytes */
-  if (cc < iphdrlen + ICMP_MINLEN) {
+  if (cc < (iphdrlen + ICMP_MINLEN)) {
     sprintf(prbuf,"packet too short (%d bytes) from %s", cc,
 	    inet_ntoa(from->sin_addr));
     if (syslogdoutput) {
       syslog(LOG_WARNING,"%s",prbuf);
-      } else {
-	puts(prbuf);
-	fflush(stdout);
-      }
+    } else {
+      puts(prbuf);
+      fflush(stdout);
+    }
     return -1;
   }
+  iplen = cc;
   cc -= iphdrlen;
 
   icp = (struct icmp *)(buf + iphdrlen);
@@ -113,6 +118,29 @@ struct sockaddr_in	*from;	/* address of
 		      inet_ntoa(icp->icmp_ip.ip_dst),
 		      hostent?hostent->h_name:NULL);
 	      tp = (struct tcphdr *)((char *)&(icp->icmp_dun)+sizeof(struct ip)) ;
+#if defined(__GLIBC__) && (__GLIBC__ >= 2)
+	      if (cc>=offsetof(struct icmp,icmp_dun)+sizeof(struct ip)+offsetof(struct tcphdr,seq)+sizeof(tp->seq))
+		{
+		  if (noportquery) {
+		      sprintf(prbuf+strlen(prbuf)," sp=%d dp=%d seq=0x%8.8x",
+			  ntohs(tp->source),ntohs(tp->dest),
+                          ntohl(tp->seq));
+		  } else {
+		    if ((servent=getservbyport(ntohs(tp->source),NULL))) 
+		      sprintf(prbuf+strlen(prbuf)," sp=%d [%s]",
+			      ntohs(tp->source),servent->s_name);
+		    else
+		      sprintf(prbuf+strlen(prbuf)," sp=%d",tp->source);
+		    if ((servent=getservbyport(ntohs(tp->dest),NULL))) 
+		      sprintf(prbuf+strlen(prbuf)," dp=%d [%s] seq=0x%8.8x",
+			      ntohs(tp->dest),servent->s_name,
+			      ntohl(tp->seq));
+		    else
+		      sprintf(prbuf+strlen(prbuf)," dp=%d seq=0x%8.8x",
+			      ntohs(tp->dest),ntohl(tp->seq));
+		  }
+		}
+#else
 	      if (cc>=offsetof(struct icmp,icmp_dun)+sizeof(struct ip)+offsetof(struct tcphdr,th_seq)+sizeof(tp->th_seq))
 		{
 		  if (noportquery) {
@@ -134,6 +162,7 @@ struct sockaddr_in	*from;	/* address of
 			      ntohs(tp->th_dport),ntohl(tp->th_seq));
 		  }
 		}
+#endif
 	    }
 	}
       sprintf(prbuf+strlen(prbuf)," sz=%d(+%d)",cc,iphdrlen);
@@ -153,7 +182,7 @@ struct sockaddr_in	*from;	/* address of
 	    flagNEof = 1;
 	    while (flagNEof) {
 	      i = j = 0;
-	      while (i < 16 && (flagNEof = cc--)) {
+	      while (i < 16 && (flagNEof = iplen--)) {
 		b= (int)(*(pbuf++));
 		h[j++] = to_hex(b >> 4);
 		h[j++] = to_hex(b & 0x0F);
@@ -193,7 +222,7 @@ register int t;
 		"Dest_Unreachable",
 		"Source_Quench",
 		"Redirect",
-		"6",
+		"Alternate Host Address",
 		"7",
 		"Echo",
 		"RouterAdvert",
@@ -205,7 +234,22 @@ register int t;
 		"Info_Request",
 		"Info_Reply",
 		"Mask_Request",
-		"Mask_Reply"
+		"Mask_Reply",
+		"19 (Reserved for Security)",
+		/* 20-29: reserved for robustness experiment */
+		"20","21","22","23","24","25","26","27","28","29",
+		"Traceroute",
+		"Datagram Convers. Err.",
+		"Mobile Host Redir",
+		"IPv6 Where-Are-You",
+		"IPv6 I-Am-Here",
+		"Mobile Registration Request",
+		"Mobile Registration Reply",
+		"Domain Name Req",
+		"Domain Name Reply",
+		"SKIP",
+		"Photuris",
+		"41 (ICMP messages utilized by experimental mobility protocols such as Seamoby)"
 	};
 
 	if (t < 0 || t > 18) {
Index: icmpinfo-1.11/recvping.c
===================================================================
--- icmpinfo-1.11.orig/recvping.c
+++ icmpinfo-1.11/recvping.c
@@ -6,10 +6,14 @@
 
 #include	"defs.h"
 
-int recv_ping()
+void recv_ping()
 {
 	register int		n;
+#if !defined(__GLIBC__)
 	int			fromlen;
+#else /* __GLIBC__ */
+	socklen_t		fromlen;
+#endif /* __GLIBC__ */
 	struct sockaddr_in	from;
 
 	for ( ; ; ) {
