Package: icmpinfo / 1.11-12

direct-changes-to-quilt Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
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 ( ; ; ) {