]> git.pld-linux.org Git - packages/fping.git/blob - fping-ipv6.patch
ipv6 patch + ac fix (patch isnt mine)
[packages/fping.git] / fping-ipv6.patch
1 diff -Naur fping-2.4b2/ChangeLog fping-2.4b2_to-ipv6/ChangeLog
2 --- fping-2.4b2/ChangeLog       Thu Mar 15 03:09:39 2001
3 +++ fping-2.4b2_to-ipv6/ChangeLog       Mon Jan 21 02:15:04 2002
4 @@ -1,12 +1,23 @@
5 -Tue Mar 14 18:37:50 2001\r
6 -Jason Ewasiuk (ZeroHype Technologies Inc.) <noc@zerohype.com>\r
7 +Wed Jan 16 2002
8 +Jeroen Massar
9 +- Revision v2.4b2-to-IPv6
10 +   - Added IPv6 support.
11 +   - Added -I option for selecting source IPv4/IPv6 address.
12 +   - Makefile.in now generates a Makefile which will build both 
13 +     fping (IPv4) and fping6 (IPv6). Thus it makes an fping (IPv4 only)
14 +     and an fping6 (IPv6 only).
15 +   - num_unreachable was counted twice when a sendto() generated errors.
16 +   - See http://unfix.org/projects/ipv6/ 
17 +
18 +Tue Mar 14 2001\r
19 +Jason Ewasiuk <jasone@remote.net>\r
20  - Revision v2.4b1\r
21         - added -g option for generating IPs from a start to an end value\r
22                 - two available options, generate IPs from start IP to end IP\r
23                   or from a passed netmask, such as 192.168.1.0/24\r
24  \r
25 -Thu Feb 15 14:35:00 2001\r
26 -Jason Ewasiuk (ZeroHype Technologies Inc.) <noc@zerohype.com>\r
27 +Thu Feb 15 2001\r
28 +Jason Ewasiuk <jasone@remote.net>\r
29  - Revision v2.3b1\r
30         - formatting changes to code layout (fping.c)\r
31         NOTE:  Best viewed with a tab stop of 4\r
32 diff -Naur fping-2.4b2/Makefile.am fping-2.4b2_to-ipv6/Makefile.am
33 --- fping-2.4b2/Makefile.am     Thu Mar 15 03:07:52 2001
34 +++ fping-2.4b2_to-ipv6/Makefile.am     Wed Jan 16 01:52:18 2002
35 @@ -1,5 +1,5 @@
36 -
37  sbin_PROGRAMS = fping
38  fping_SOURCES = fping.c options.h linux.h
39  man_MANS = fping.8
40  AUTOMAKE_OPTIONS=foreign
41 +EXTRA_DIST = $(man_MANS)
42 diff -Naur fping-2.4b2/README fping-2.4b2_to-ipv6/README
43 --- fping-2.4b2/README  Wed Apr 25 20:29:10 2001
44 +++ fping-2.4b2_to-ipv6/README  Mon Jan 21 02:02:12 2002
45 @@ -1,9 +1,9 @@
46  fping README
47  ------------
48  
49 -Current maintainer and cool feature adder:
50 +Current maintainer:
51  
52 -ZeroHype Technologies Inc. (noc@zerohype.com) http://www.zerohype.com
53 +David Papp - david@remote.net 
54  
55  
56  fping website:  http://www.fping.com
57 @@ -11,6 +11,7 @@
58  
59  Original author:  Roland Schemers (schemers@stanford.edu)
60  Previous maintainer:  RL "Bob" Morgan (morgan@stanford.edu)
61 +IPv6 Support: Jeroen Massar (jeroen@unfix.org / jeroen@ipng.nl)
62  
63  
64  Suggestions and patches:
65 diff -Naur fping-2.4b2/acconfig.h fping-2.4b2_to-ipv6/acconfig.h
66 --- fping-2.4b2/acconfig.h      Thu Mar 15 03:07:52 2001
67 +++ fping-2.4b2_to-ipv6/acconfig.h      Sat Nov  3 16:23:40 2001
68 @@ -1,4 +1,18 @@
69 +#ifndef CONFIG_H
70 +#define CONFIG_H
71 +
72 +@TOP@
73  
74  /* VERSION (from configure.in) */
75  #undef VERSION
76  
77 +
78 +@BOTTOM@
79 +
80 +/* some OSes do not define this ... lets take a wild guess */
81 +
82 +#ifndef INADDR_NONE
83 +#  define INADDR_NONE 0xffffffffU
84 +#endif
85 +
86 +#endif /* CONFIG_H */
87 diff -Naur fping-2.4b2/aclocal.m4 fping-2.4b2_to-ipv6/aclocal.m4
88 --- fping-2.4b2/aclocal.m4      Thu Jan  1 01:00:00 1970
89 +++ fping-2.4b2_to-ipv6/aclocal.m4      Wed Jan 16 01:48:55 2002
90 @@ -0,0 +1,127 @@
91 +dnl aclocal.m4 generated automatically by aclocal 1.4
92 +
93 +dnl Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
94 +dnl This file is free software; the Free Software Foundation
95 +dnl gives unlimited permission to copy and/or distribute it,
96 +dnl with or without modifications, as long as this notice is preserved.
97 +
98 +dnl This program is distributed in the hope that it will be useful,
99 +dnl but WITHOUT ANY WARRANTY, to the extent permitted by law; without
100 +dnl even the implied warranty of MERCHANTABILITY or FITNESS FOR A
101 +dnl PARTICULAR PURPOSE.
102 +
103 +# Do all the work for Automake.  This macro actually does too much --
104 +# some checks are only needed if your package does certain things.
105 +# But this isn't really a big deal.
106 +
107 +# serial 1
108 +
109 +dnl Usage:
110 +dnl AM_INIT_AUTOMAKE(package,version, [no-define])
111 +
112 +AC_DEFUN(AM_INIT_AUTOMAKE,
113 +[AC_REQUIRE([AC_PROG_INSTALL])
114 +PACKAGE=[$1]
115 +AC_SUBST(PACKAGE)
116 +VERSION=[$2]
117 +AC_SUBST(VERSION)
118 +dnl test to see if srcdir already configured
119 +if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then
120 +  AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
121 +fi
122 +ifelse([$3],,
123 +AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
124 +AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package]))
125 +AC_REQUIRE([AM_SANITY_CHECK])
126 +AC_REQUIRE([AC_ARG_PROGRAM])
127 +dnl FIXME This is truly gross.
128 +missing_dir=`cd $ac_aux_dir && pwd`
129 +AM_MISSING_PROG(ACLOCAL, aclocal, $missing_dir)
130 +AM_MISSING_PROG(AUTOCONF, autoconf, $missing_dir)
131 +AM_MISSING_PROG(AUTOMAKE, automake, $missing_dir)
132 +AM_MISSING_PROG(AUTOHEADER, autoheader, $missing_dir)
133 +AM_MISSING_PROG(MAKEINFO, makeinfo, $missing_dir)
134 +AC_REQUIRE([AC_PROG_MAKE_SET])])
135 +
136 +#
137 +# Check to make sure that the build environment is sane.
138 +#
139 +
140 +AC_DEFUN(AM_SANITY_CHECK,
141 +[AC_MSG_CHECKING([whether build environment is sane])
142 +# Just in case
143 +sleep 1
144 +echo timestamp > conftestfile
145 +# Do `set' in a subshell so we don't clobber the current shell's
146 +# arguments.  Must try -L first in case configure is actually a
147 +# symlink; some systems play weird games with the mod time of symlinks
148 +# (eg FreeBSD returns the mod time of the symlink's containing
149 +# directory).
150 +if (
151 +   set X `ls -Lt $srcdir/configure conftestfile 2> /dev/null`
152 +   if test "[$]*" = "X"; then
153 +      # -L didn't work.
154 +      set X `ls -t $srcdir/configure conftestfile`
155 +   fi
156 +   if test "[$]*" != "X $srcdir/configure conftestfile" \
157 +      && test "[$]*" != "X conftestfile $srcdir/configure"; then
158 +
159 +      # If neither matched, then we have a broken ls.  This can happen
160 +      # if, for instance, CONFIG_SHELL is bash and it inherits a
161 +      # broken ls alias from the environment.  This has actually
162 +      # happened.  Such a system could not be considered "sane".
163 +      AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
164 +alias in your environment])
165 +   fi
166 +
167 +   test "[$]2" = conftestfile
168 +   )
169 +then
170 +   # Ok.
171 +   :
172 +else
173 +   AC_MSG_ERROR([newly created file is older than distributed files!
174 +Check your system clock])
175 +fi
176 +rm -f conftest*
177 +AC_MSG_RESULT(yes)])
178 +
179 +dnl AM_MISSING_PROG(NAME, PROGRAM, DIRECTORY)
180 +dnl The program must properly implement --version.
181 +AC_DEFUN(AM_MISSING_PROG,
182 +[AC_MSG_CHECKING(for working $2)
183 +# Run test in a subshell; some versions of sh will print an error if
184 +# an executable is not found, even if stderr is redirected.
185 +# Redirect stdin to placate older versions of autoconf.  Sigh.
186 +if ($2 --version) < /dev/null > /dev/null 2>&1; then
187 +   $1=$2
188 +   AC_MSG_RESULT(found)
189 +else
190 +   $1="$3/missing $2"
191 +   AC_MSG_RESULT(missing)
192 +fi
193 +AC_SUBST($1)])
194 +
195 +# Like AC_CONFIG_HEADER, but automatically create stamp file.
196 +
197 +AC_DEFUN(AM_CONFIG_HEADER,
198 +[AC_PREREQ([2.12])
199 +AC_CONFIG_HEADER([$1])
200 +dnl When config.status generates a header, we must update the stamp-h file.
201 +dnl This file resides in the same directory as the config header
202 +dnl that is generated.  We must strip everything past the first ":",
203 +dnl and everything past the last "/".
204 +AC_OUTPUT_COMMANDS(changequote(<<,>>)dnl
205 +ifelse(patsubst(<<$1>>, <<[^ ]>>, <<>>), <<>>,
206 +<<test -z "<<$>>CONFIG_HEADERS" || echo timestamp > patsubst(<<$1>>, <<^\([^:]*/\)?.*>>, <<\1>>)stamp-h<<>>dnl>>,
207 +<<am_indx=1
208 +for am_file in <<$1>>; do
209 +  case " <<$>>CONFIG_HEADERS " in
210 +  *" <<$>>am_file "*<<)>>
211 +    echo timestamp > `echo <<$>>am_file | sed -e 's%:.*%%' -e 's%[^/]*$%%'`stamp-h$am_indx
212 +    ;;
213 +  esac
214 +  am_indx=`expr "<<$>>am_indx" + 1`
215 +done<<>>dnl>>)
216 +changequote([,]))])
217 +
218 diff -Naur fping-2.4b2/config.h.in fping-2.4b2_to-ipv6/config.h.in
219 --- fping-2.4b2/config.h.in     Thu Mar 15 03:07:52 2001
220 +++ fping-2.4b2_to-ipv6/config.h.in     Wed Jan 16 01:49:45 2002
221 @@ -1,4 +1,7 @@
222  /* config.h.in.  Generated automatically from configure.in by autoheader.  */
223 +#ifndef CONFIG_H
224 +#define CONFIG_H
225 +
226  
227  /* VERSION (from configure.in) */
228  #undef VERSION
229 @@ -20,3 +23,18 @@
230  
231  /* Define if you have the socket library (-lsocket).  */
232  #undef HAVE_LIBSOCKET
233 +
234 +/* Name of package */
235 +#undef PACKAGE
236 +
237 +/* Version number of package */
238 +#undef VERSION
239 +
240 +
241 +/* some OSes do not define this ... lets take a wild guess */
242 +
243 +#ifndef INADDR_NONE
244 +#  define INADDR_NONE 0xffffffffU
245 +#endif
246 +
247 +#endif /* CONFIG_H */
248 diff -Naur fping-2.4b2/configure.in fping-2.4b2_to-ipv6/configure.in
249 --- fping-2.4b2/configure.in    Thu Nov  7 21:11:57 2002
250 +++ fping-2.4b2_to-ipv6/configure.in    Wed Jan 16 01:48:02 2002
251 @@ -1,18 +1,26 @@
252  dnl Process this file with autoconf to produce a configure script.
253  AC_INIT(fping.c)
254 -AM_INIT_AUTOMAKE(fping,fping)
255 +AM_INIT_AUTOMAKE(fping, 2.4b2_to_ipv6)
256 +
257  AM_CONFIG_HEADER(config.h)
258 +#VERSION=2.4b2
259 +#PACKAGE=fping
260 +AC_SUBST(PACKAGE)
261 +AC_SUBST(VERSION)
262 +AC_DEFINE_UNQUOTED(VERSION,"$VERSION")
263  
264  dnl Checks for programs.
265  
266 -AC_ARG_PROGRAM
267  AC_PROG_CC
268  AC_PROG_CPP
269  AC_PROG_INSTALL
270  
271  dnl Checks for libraries.
272  
273 -AC_CHECK_FUNC(gethostbyname, [] AC_CHECK_LIB(nsl, gethostbyname))
274 +AC_CHECK_FUNC(gethostbyname)
275 +if test $ac_cv_func_gethostbyname = no; then
276 +    AC_CHECK_LIB(nsl, gethostbyname)
277 +fi
278  AC_CHECK_FUNC(connect)
279  if test $ac_cv_func_connect = no; then
280      AC_CHECK_LIB(socket, connect)
281 @@ -21,4 +29,4 @@
282  dnl Checks for header files.
283  AC_CHECK_HEADERS(unistd.h sys/file.h stdlib.h sys/select.h)
284  
285 -AC_OUTPUT([Makefile])
286 +AC_OUTPUT(Makefile)
287 diff -Naur fping-2.4b2/fping.8 fping-2.4b2_to-ipv6/fping.8
288 --- fping-2.4b2/fping.8 Thu Mar 15 03:10:45 2001
289 +++ fping-2.4b2_to-ipv6/fping.8 Mon Jan 21 02:05:48 2002
290 @@ -192,7 +192,7 @@
291  .nf\r
292  Roland J. Schemers III, Stanford University, concept and versions 1.x\r
293  RL "Bob" Morgan, Stanford University, versions 2.x\r
294 -ZeroHype Technologies Inc. (http://www.zerohype.com), versions 2.3x and up,\r
295 +David Papp, versions 2.3x and up,\r
296  fping website:  http://www.fping.com\r
297  .ni\r
298  .SH DIAGNOSTICS\r
299 diff -Naur fping-2.4b2/fping.c fping-2.4b2_to-ipv6/fping.c
300 --- fping-2.4b2/fping.c Fri Jul 20 19:10:26 2001
301 +++ fping-2.4b2_to-ipv6/fping.c Mon Jan 21 02:06:30 2002
302 @@ -17,12 +17,13 @@
303   *
304   * Current maintainers of fping:
305   *
306 - * ZeroHype Technologies Inc. (http://www.zerohype.com)
307 - * Suggestions and patches, please email noc@zerohype.com
308 + * David Papp
309 + * Suggestions and patches, please email david@remote.net
310   *
311   *
312   *
313 - * Original author:  Roland Schemers  <schemers@stanford.edu> 
314 + * Original author:  Roland Schemers  <schemers@stanford.edu>
315 + * IPv6 Support:     Jeroen Massar    <jeroen@unfix.org / jeroen@ipng.nl>
316   *
317   *
318   *
319 @@ -41,6 +42,7 @@
320   * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
321   * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
322   */
323 +#define IPV6 1                                         /* This should be a compiler option, or even better be done from the Makefile... ;) */
324  
325  #ifndef _NO_PROTO
326  #if !__STDC__ && !defined( __cplusplus ) && !defined( FUNCPROTO ) \
327 @@ -65,13 +67,16 @@
328  
329  /*** autoconf includes ***/
330  
331 -#include <config.h>
332  
333  #include <stdio.h>
334  #include <errno.h>
335  #include <time.h>
336  #include <signal.h>
337  
338 +#include <netinet/in.h>
339 +
340 +#include "config.h"
341 +
342  #ifdef HAVE_UNISTD_H
343  #include <unistd.h>
344  #endif /* HAVE_UNISTD_H */
345 @@ -91,8 +96,10 @@
346  #include <sys/file.h>
347  #endif /* HAVE_SYS_FILE_H */
348  
349 +#ifdef IPV6
350 +#include <netinet/icmp6.h>
351 +#endif
352  #include <netinet/in_systm.h>
353 -#include <netinet/in.h>
354  
355  /* Linux has bizarre ip.h and ip_icmp.h */
356  #if defined( __linux__ )
357 @@ -126,8 +133,8 @@
358  
359  /*** Constants ***/
360  
361 -#define REV_DATE       "2001/01/25 11:25:04"
362 -#define EMAIL          "noc@zerohype.com"
363 +#define REV_DATE       "2002/01/16 00:33:42"
364 +#define EMAIL          "david@remote.net"
365  
366  /*** Ping packet defines ***/
367  
368 @@ -215,6 +222,13 @@
369  };
370  
371  #define        ICMP_UNREACH_MAXTYPE    15
372 +#ifndef IPV6
373 +#define        FPING_SOCKADDR struct sockaddr_in
374 +#define        FPING_ICMPHDR   struct icmp
375 +#else
376 +#define        FPING_SOCKADDR struct sockaddr_in6
377 +#define        FPING_ICMPHDR   struct icmp6_hdr
378 +#endif
379  
380  /* entry used to keep track of each host we are pinging */
381  
382 @@ -225,7 +239,7 @@
383       char                 *name;              /* name as given by user */
384       char                 *host;              /* text description of host */
385       char                 *pad;               /* pad to align print names */
386 -     struct sockaddr_in   saddr;              /* internet address */
387 +     FPING_SOCKADDR       saddr;              /* internet address */
388       int                  timeout;            /* time to wait for response */
389       u_char               running;            /* unset when through sending */
390       u_char               waiting;            /* waiting for response */
391 @@ -335,7 +349,11 @@
392  #else
393  
394  void add_name( char *name );
395 +#ifndef IPV6
396  void add_addr( char *name, char *host, struct in_addr ipaddr );
397 +#else
398 +void add_addr( char *name, char *host, FPING_SOCKADDR *ipaddr );
399 +#endif
400  char *na_cat( char *name, struct in_addr ipaddr );
401  char *cpystr( char *string );
402  void crash_and_burn( char *message );
403 @@ -343,7 +361,7 @@
404  char *get_host_by_address( struct in_addr in );
405  int in_cksum( u_short *p, int n );
406  void u_sleep( int u_sec );
407 -int recvfrom_wto ( int s, char *buf, int len, struct sockaddr *saddr, int timo );
408 +int recvfrom_wto ( int s, char *buf, int len, FPING_SOCKADDR *saddr, int timo );
409  void remove_job( HOST_ENTRY *h );
410  void send_ping( int s, HOST_ENTRY *h );
411  long timeval_diff( struct timeval *a, struct timeval *b );
412 @@ -353,7 +371,7 @@
413  void print_per_system_splits( void );
414  void print_global_stats( void );
415  void finish();
416 -int handle_random_icmp( struct icmp *p, int psize, struct sockaddr_in *addr );
417 +int handle_random_icmp( FPING_ICMPHDR *p, int psize, FPING_SOCKADDR *addr );
418  char *sprint_tm( int t );
419  
420  #endif /* _NO_PROTO */
421 @@ -382,12 +400,14 @@
422  #endif /* _NO_PROTO */
423  {
424         int c, i, n;
425 +#ifdef IPV6
426 +       int opton = 1;
427 +#endif
428         u_int lt, ht;
429         int advance;
430         struct protoent *proto;
431         char *buf;
432         uid_t uid;
433 -
434         /* check if we are root */
435  
436         if( geteuid() )
437 @@ -400,15 +420,62 @@
438         }/* IF */
439  
440         /* confirm that ICMP is available on this machine */
441 +#ifndef IPV6
442         if( ( proto = getprotobyname( "icmp" ) ) == NULL ) 
443 +#else
444 +       if( ( proto = getprotobyname( "ipv6-icmp" ) ) == NULL ) 
445 +#endif
446                 crash_and_burn( "icmp: unknown protocol" );
447  
448         /* create raw socket for ICMP calls (ping) */
449 +#ifndef IPV6
450         s = socket( AF_INET, SOCK_RAW, proto->p_proto );
451 +#else
452 +       s = socket( AF_INET6, SOCK_RAW, proto->p_proto );
453 +#endif
454  
455         if( s < 0 )
456                 errno_crash_and_burn( "can't create raw socket" );
457  
458 +#ifdef IPV6
459 +       /*
460 +        * let the kerel pass extension headers of incoming packets,
461 +        * for privileged socket options
462 +        */
463 +#ifdef IPV6_RECVHOPOPTS
464 +               if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPOPTS, &opton,
465 +                   sizeof(opton)))
466 +                       err(1, "setsockopt(IPV6_RECVHOPOPTS)");
467 +#else  /* old adv. API */
468 +               if (setsockopt(s, IPPROTO_IPV6, IPV6_HOPOPTS, &opton,
469 +                   sizeof(opton)))
470 +                       err(1, "setsockopt(IPV6_HOPOPTS)");
471 +#endif
472 +#ifdef IPV6_RECVDSTOPTS
473 +               if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVDSTOPTS, &opton,
474 +                   sizeof(opton)))
475 +                       err(1, "setsockopt(IPV6_RECVDSTOPTS)");
476 +#else  /* old adv. API */
477 +               if (setsockopt(s, IPPROTO_IPV6, IPV6_DSTOPTS, &opton,
478 +                   sizeof(opton)))
479 +                       err(1, "setsockopt(IPV6_DSTOPTS)");
480 +#endif
481 +#ifdef IPV6_RECVRTHDRDSTOPTS
482 +               if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVRTHDRDSTOPTS, &opton,
483 +                   sizeof(opton)))
484 +                       err(1, "setsockopt(IPV6_RECVRTHDRDSTOPTS)");
485 +#endif
486 +#ifdef IPV6_RECVRTHDR
487 +               if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVRTHDR, &opton,
488 +                   sizeof(opton)))
489 +                       err(1, "setsockopt(IPV6_RECVRTHDR)");
490 +#else  /* old adv. API */
491 +               if (setsockopt(s, IPPROTO_IPV6, IPV6_RTHDR, &opton,
492 +                   sizeof(opton)))
493 +                       err(1, "setsockopt(IPV6_RTHDR)");
494 +#endif
495 +#endif
496 +
497         if( ( uid = getuid() ) )
498         {
499                 seteuid( getuid() );
500 @@ -1425,7 +1492,7 @@
501  #endif /* _NO_PROTO */
502  {
503         char *buffer;
504 -       struct icmp *icp;
505 +       FPING_ICMPHDR *icp;
506         PING_DATA *pdp;
507         int n;
508  
509 @@ -1434,9 +1501,10 @@
510                 crash_and_burn( "can't malloc ping packet" );
511         
512         memset( buffer, 0, ping_pkt_size * sizeof( char ) );
513 -       icp = ( struct icmp* )buffer;
514 +       icp = ( FPING_ICMPHDR* )buffer;
515  
516         gettimeofday( &h->last_send_time, &tz );
517 +#ifndef IPV6
518         icp->icmp_type = ICMP_ECHO;
519         icp->icmp_code = 0;
520         icp->icmp_cksum = 0;
521 @@ -1448,14 +1516,25 @@
522         pdp->ping_count = h->num_sent;
523  
524         icp->icmp_cksum = in_cksum( ( u_short* )icp, ping_pkt_size );
525 +#else
526 +       icp->icmp6_type = ICMP6_ECHO_REQUEST;
527 +       icp->icmp6_code = 0;
528 +       icp->icmp6_seq = h->i;
529 +       icp->icmp6_id = ident;
530 +
531 +       pdp = ( PING_DATA* )( buffer + SIZE_ICMP_HDR );
532 +       pdp->ping_ts = h->last_send_time;
533 +       pdp->ping_count = h->num_sent;
534  
535 +       icp->icmp6_cksum = 0;   // The IPv6 stack calculates the checksum for us...
536 +#endif
537  #if defined(DEBUG) || defined(_DEBUG)
538         if( trace_flag )
539                 printf( "sending [%d] to %s\n", h->num_sent, h->host );
540  #endif /* DEBUG || _DEBUG */
541  
542         n = sendto( s, buffer, ping_pkt_size, 0,
543 -               ( struct sockaddr* )&h->saddr, sizeof( struct sockaddr_in ) );
544 +               ( struct sockaddr* )&h->saddr, sizeof( FPING_SOCKADDR ) );
545  
546         if( n < 0 || n != ping_pkt_size )
547         {
548 @@ -1520,18 +1599,17 @@
549  {
550         int result;
551         static char buffer[4096];
552 -       struct sockaddr_in response_addr;
553 +       FPING_SOCKADDR response_addr;
554         struct ip *ip;
555 -       int hlen;
556 -       struct icmp *icp;
557 +       int hlen = 0;
558 +       FPING_ICMPHDR *icp;
559         int n, avg;
560         HOST_ENTRY *h;
561         long this_reply;
562         int this_count;
563         struct timeval sent_time;
564  
565 -       result = recvfrom_wto( s, buffer, 4096,
566 -               ( struct sockaddr* )&response_addr, select_time );
567 +       result = recvfrom_wto( s, buffer, sizeof(buffer), &response_addr, select_time );
568  
569         if( result < 0 )
570                 return 0;       /* timeout */
571 @@ -1546,7 +1624,7 @@
572  #endif /* DEBUG || _DEBUG */
573  
574         ip = ( struct ip* )buffer;
575 -
576 +#ifndef IPV6
577  #if defined( __alpha__ ) && __STDC__ && !defined( __GLIBC__ )
578         /* The alpha headers are decidedly broken.
579          * Using an ANSI compiler, it provides ip_vhl instead of ip_hl and
580 @@ -1556,37 +1634,59 @@
581  #else
582         hlen = ip->ip_hl << 2;
583  #endif /* defined(__alpha__) && __STDC__ */
584 -
585         if( result < hlen + ICMP_MINLEN )
586 +#else
587 +       if( result < sizeof(FPING_ICMPHDR) )
588 +#endif
589         {
590                 if( verbose_flag )
591 +               {
592 +#ifndef IPV6
593                         printf( "received packet too short for ICMP (%d bytes from %s)\n", result,
594                                 inet_ntoa( response_addr.sin_addr ) );
595 -               
596 +#else                  
597 +                       char buf[INET6_ADDRSTRLEN];
598 +                       inet_ntop(response_addr.sin6_family, &response_addr.sin6_addr, buf, INET6_ADDRSTRLEN);
599 +                       printf( "received packet too short for ICMP (%d bytes from %s)\n", result, buf);
600 +#endif
601 +               }
602                 return( 1 ); /* too short */ 
603 -       
604         }/* IF */
605  
606 -       icp = ( struct icmp* )( buffer + hlen );
607 +       icp = ( FPING_ICMPHDR* )( buffer + hlen );
608 +#ifndef IPV6
609         if( icp->icmp_type != ICMP_ECHOREPLY )
610 +#else
611 +       if( icp->icmp6_type != ICMP6_ECHO_REPLY )
612 +#endif
613         {
614                 /* handle some problem */
615                 if( handle_random_icmp( icp, result, &response_addr ) )
616                         num_othericmprcvd++;
617 -               
618                 return 1;
619 -       
620         }/* IF */
621  
622 +#ifndef IPV6
623         if( icp->icmp_id != ident )
624 +#else
625 +       if( icp->icmp6_id != ident )
626 +#endif
627                 return 1; /* packet received, but not the one we are looking for! */
628  
629         num_pingreceived++;
630  
631 +#ifndef IPV6
632         if( icp->icmp_seq  >= ( n_short )num_hosts )
633 +#else
634 +       if( icp->icmp6_seq  >= ( n_short )num_hosts )
635 +#endif
636                 return( 1 ); /* packet received, don't worry about it anymore */
637  
638 +#ifndef IPV6
639         n = icp->icmp_seq;
640 +#else
641 +       n = icp->icmp6_seq;
642 +#endif
643         h = table[n];
644  
645         /* received ping is cool, so process it */
646 @@ -1595,9 +1695,14 @@
647         h->timeout = timeout;
648         h->num_recv++;
649         h->num_recv_i++;
650 -       
651 +
652 +#ifndef IPV6
653         memcpy( &sent_time, icp->icmp_data + offsetof( PING_DATA, ping_ts ), sizeof( sent_time ) );
654         memcpy( &this_count, icp->icmp_data, sizeof( this_count ) );
655 +#else
656 +       memcpy( &sent_time, ((char *)icp->icmp6_data32)+4+offsetof(PING_DATA, ping_ts), sizeof( sent_time ) );
657 +       memcpy( &this_count, ((char *)icp->icmp6_data32)+4, sizeof( this_count ) );
658 +#endif
659  
660  #if defined( DEBUG ) || defined( _DEBUG )
661         if( trace_flag ) 
662 @@ -1627,10 +1732,18 @@
663                                 {
664                                         fprintf( stderr, "%s : duplicate for [%d], %d bytes, %s ms",
665                                                 h->host, this_count, result, sprint_tm( this_reply ) );
666 -
667 +#ifndef IPV6
668                                         if( response_addr.sin_addr.s_addr != h->saddr.sin_addr.s_addr )
669                                                 fprintf( stderr, " [<- %s]", inet_ntoa( response_addr.sin_addr ) );
670 -         
671 +#else
672 +                                       if(memcmp(&response_addr.sin6_addr, &h->saddr.sin6_addr, sizeof(response_addr.sin6_addr)))
673 +                                       {
674 +                                               char buf[INET6_ADDRSTRLEN];
675 +                                               inet_ntop(response_addr.sin6_family, &response_addr.sin6_addr, buf, INET6_ADDRSTRLEN);
676 +
677 +                                               fprintf( stderr, " [<- %s]", buf);
678 +                                       }
679 +#endif   
680                                         fprintf( stderr, "\n" );
681         
682                                 }/* IF */
683 @@ -1660,10 +1773,17 @@
684  
685                         if( elapsed_flag )
686                                 printf( " (%s ms)", sprint_tm( this_reply ) );
687 -      
688 +#ifndef IPV6
689                         if( response_addr.sin_addr.s_addr != h->saddr.sin_addr.s_addr )
690                                 printf( " [<- %s]", inet_ntoa( response_addr.sin_addr ) );
691 -
692 +#else
693 +       if(memcmp(&response_addr.sin6_addr, &h->saddr.sin6_addr, sizeof(response_addr.sin6_addr)))
694 +                       {
695 +                               char buf[INET6_ADDRSTRLEN];
696 +                               inet_ntop(response_addr.sin6_family, &response_addr.sin6_addr, buf, INET6_ADDRSTRLEN);
697 +                               fprintf( stderr, " [<- %s]", buf);
698 +                       }
699 +#endif
700                         printf( "\n" );
701                 
702                 }/* IF */
703 @@ -1688,9 +1808,17 @@
704                                 ( h->num_recv * 100 ) / h->num_sent );
705                 
706                 }/* ELSE */
707 -
708 +#ifndef IPV6
709                 if( response_addr.sin_addr.s_addr != h->saddr.sin_addr.s_addr )
710                         printf( " [<- %s]", inet_ntoa( response_addr.sin_addr ) );
711 +#else
712 +       if(memcmp(&response_addr.sin6_addr, &h->saddr.sin6_addr, sizeof(response_addr.sin6_addr)))
713 +               {
714 +                       char buf[INET6_ADDRSTRLEN];
715 +                       inet_ntop(response_addr.sin6_family, &response_addr.sin6_addr, buf, INET6_ADDRSTRLEN);
716 +                       fprintf( stderr, " [<- %s]", buf);
717 +               }
718 +#endif
719                 
720                 printf( "\n" );
721         
722 @@ -1706,7 +1834,7 @@
723  
724  *************************************************************
725  
726 -  Inputs:  struct icmp *p, int psize, struct sockaddr_in *addr
727 +  Inputs:  FPING_ICMPHDR *p, int psize, FPING_SOCKADDR *addr
728  
729    Returns:  int
730  
731 @@ -1717,22 +1845,33 @@
732  
733  #ifdef _NO_PROTO
734  int handle_random_icmp( p, psize, addr )
735 -     struct icmp *p;
736 +     FPING_ICMPHDR *p;
737       int psize;
738 -     struct sockaddr_in *addr;
739 +     FPING_SOCKADDR *addr;
740  #else
741 -int handle_random_icmp( struct icmp *p, int psize, struct sockaddr_in *addr )
742 +int handle_random_icmp( FPING_ICMPHDR *p, int psize, FPING_SOCKADDR *addr )
743  #endif /* _NO_PROTO */
744  {
745 -       struct icmp *sent_icmp;
746 +       FPING_ICMPHDR *sent_icmp;
747         struct ip *sent_ip;
748         u_char *c;
749         HOST_ENTRY *h;
750 +#ifdef IPV6
751 +       char addr_ascii[INET6_ADDRSTRLEN];
752 +       inet_ntop(addr->sin6_family, &addr->sin6_addr, addr_ascii, INET6_ADDRSTRLEN);
753 +#endif
754  
755         c = ( u_char* )p;
756 +#ifndef IPV6
757         switch( p->icmp_type )
758 +#else
759 +       switch( p->icmp6_type )
760 +#endif
761         {
762         case ICMP_UNREACH:
763 +               sent_icmp = ( FPING_ICMPHDR* )( c + 28 );
764 +               
765 +#ifndef IPV6
766                 sent_icmp = ( struct icmp* )( c + 28 );
767                 
768                 if( ( sent_icmp->icmp_type == ICMP_ECHO ) &&
769 @@ -1747,16 +1886,37 @@
770                                 fprintf( stderr, "ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
771                                         inet_ntoa( addr->sin_addr ), h->host );
772  
773 +#else
774 +               if( ( sent_icmp->icmp6_type == ICMP_ECHO ) &&
775 +                       ( sent_icmp->icmp6_id == ident ) &&
776 +                       ( sent_icmp->icmp6_seq < ( n_short )num_hosts ) )
777 +               {
778 +                       /* this is a response to a ping we sent */
779 +                       h = table[sent_icmp->icmp6_seq];
780 +                       
781 +                       if( p->icmp6_code > ICMP_UNREACH_MAXTYPE )
782 +                       {
783 +                               fprintf( stderr, "ICMP Unreachable (Invalid Code) from %s for ICMP Echo sent to %s",
784 +                                       addr_ascii, h->host );
785 +#endif
786                         }/* IF */
787                         else
788                         {
789                                 fprintf( stderr, "%s from %s for ICMP Echo sent to %s",
790 +#ifndef IPV6
791                                         icmp_unreach_str[p->icmp_code], inet_ntoa( addr->sin_addr ), h->host );
792 +#else
793 +                                       icmp_unreach_str[p->icmp6_code], addr_ascii, h->host );
794 +#endif
795                         
796                         }/* ELSE */
797  
798                         if( inet_addr( h->host ) == -1 )
799 +#ifndef IPV6
800                                 fprintf( stderr, " (%s)", inet_ntoa( h->saddr.sin_addr ) );
801 +#else
802 +                               fprintf( stderr, " (%s)", addr_ascii);
803 +#endif
804                         
805                         fprintf( stderr, "\n" );
806                 
807 @@ -1768,7 +1928,8 @@
808         case ICMP_REDIRECT:
809         case ICMP_TIMXCEED:
810         case ICMP_PARAMPROB:
811 -               sent_icmp = ( struct icmp* )( c + 28 );
812 +               sent_icmp = ( FPING_ICMPHDR* )( c + 28 );
813 +#ifndef IPV6
814                 if( ( sent_icmp->icmp_type = ICMP_ECHO ) && 
815                         ( sent_icmp->icmp_id = ident ) &&
816                         ( sent_icmp->icmp_seq < ( n_short )num_hosts ) )
817 @@ -1780,6 +1941,19 @@
818        
819                         if( inet_addr( h->host ) == -1 )
820                                 fprintf( stderr, " (%s)", inet_ntoa( h->saddr.sin_addr ) );
821 +#else
822 +               if( ( sent_icmp->icmp6_type = ICMP_ECHO ) && 
823 +                       ( sent_icmp->icmp6_id = ident ) &&
824 +                       ( sent_icmp->icmp6_seq < ( n_short )num_hosts ) )
825 +               {
826 +                       /* this is a response to a ping we sent */
827 +                       h = table[sent_icmp->icmp6_seq];
828 +                       fprintf( stderr, "%s from %s for ICMP Echo sent to %s",
829 +                               icmp_type_str[p->icmp6_type], addr_ascii, h->host );
830 +      
831 +                       if( inet_addr( h->host ) == -1 )
832 +                               fprintf( stderr, " (%s)", addr_ascii );
833 +#endif
834  
835                         fprintf( stderr, "\n" );
836                 
837 @@ -1879,6 +2053,7 @@
838  void add_name( char *name )
839  #endif /* _NO_PROTO */
840  {
841 +#ifndef IPV6
842         struct hostent *host_ent;
843         u_int ipaddress;
844         struct in_addr *ipa = ( struct in_addr* )&ipaddress;
845 @@ -1985,7 +2160,27 @@
846  
847                 }/* WHILE */
848         }/* ELSE */
849 -
850 +#else
851 +       FPING_SOCKADDR  dst;
852 +       struct addrinfo         *res, hints;
853 +       int                                             ret_ga;
854 +       char                                            *hostname;
855 +
856 +       /* getaddrinfo */
857 +       bzero(&hints, sizeof(struct addrinfo));
858 +       hints.ai_flags = AI_CANONNAME;
859 +       hints.ai_family = AF_INET6;
860 +       hints.ai_socktype = SOCK_RAW;
861 +       hints.ai_protocol = IPPROTO_ICMPV6;
862 +
863 +       ret_ga = getaddrinfo(name, NULL, &hints, &res);
864 +       if (ret_ga) errx(1, "%s", gai_strerror(ret_ga));
865 +       if (res->ai_canonname) hostname = res->ai_canonname;
866 +       else hostname = name;
867 +       if (!res->ai_addr) errx(1, "getaddrinfo failed");
868 +       (void)memcpy(&dst, res->ai_addr, sizeof(FPING_SOCKADDR)); /*res->ai_addrlen);*/
869 +       add_addr(name, name, &dst);
870 +#endif
871  } /* add_name() */
872  
873  
874 @@ -2048,9 +2243,17 @@
875  void add_addr( name, host, ipaddr )
876  char *name;
877  char *host;
878 +#ifndef IPV6
879  struct in_addr ipaddr;
880  #else
881 +FPING_SOCKADDR *ipaddr;
882 +#endif
883 +#else
884 +#ifndef IPV6
885  void add_addr( char *name, char *host, struct in_addr ipaddr )
886 +#else
887 +void add_addr( char *name, char *host, FPING_SOCKADDR *ipaddr )
888 +#endif
889  #endif /* _NO_PROTO */
890  {
891         HOST_ENTRY *p;
892 @@ -2064,8 +2267,13 @@
893  
894         p->name = name;
895         p->host = host;
896 +#ifndef IPV6
897         p->saddr.sin_family = AF_INET;
898         p->saddr.sin_addr = ipaddr; 
899 +#else
900 +       p->saddr.sin6_family = AF_INET6;
901 +       (void)memcpy(&p->saddr, ipaddr, sizeof(FPING_SOCKADDR));
902 +#endif
903         p->timeout = timeout;
904         p->running = 1;
905         p->min_reply = 10000000;
906 @@ -2193,7 +2401,11 @@
907  #endif /* _NO_PROTO */
908  {
909         struct hostent *h;
910 +#ifndef IPV6
911         h = gethostbyaddr( ( char* )&in, sizeof( struct in_addr ),AF_INET );
912 +#else
913 +       h = gethostbyaddr( ( char* )&in, sizeof( FPING_SOCKADDR ),AF_INET6 );
914 +#endif
915         
916         if( h == NULL || h->h_name == NULL )
917                 return inet_ntoa( in );
918 @@ -2429,7 +2641,7 @@
919  
920  *************************************************************
921  
922 -  Inputs:  int s, char* buf, int len, struct sockaddr *saddr, int timo
923 +  Inputs:  int s, char* buf, int len, FPING_SOCKADDR *saddr, int timo
924  
925    Returns:  int
926  
927 @@ -2443,9 +2655,9 @@
928  
929  #ifdef _NO_PROTO
930  int recvfrom_wto( s, buf, len, saddr, timo )
931 -int s; char *buf; int len; struct sockaddr *saddr; int timo;
932 +int s; char *buf; int len; FPING_SOCKADDR *saddr; int timo;
933  #else
934 -int recvfrom_wto( int s, char *buf, int len, struct sockaddr *saddr, int timo )
935 +int recvfrom_wto( int s, char *buf, int len, FPING_SOCKADDR *saddr, int timo )
936  #endif /* _NO_PROTO */
937  {
938         int nfound, slen, n;
939 @@ -2465,8 +2677,12 @@
940         if( nfound == 0 )
941                 return -1;              /* timeout */
942  
943 +#ifndef IPV6
944         slen = sizeof( struct sockaddr );
945 -       n = recvfrom( s, buf, len, 0, saddr, &slen );
946 +#else
947 +       slen = sizeof( FPING_SOCKADDR );
948 +#endif
949 +       n = recvfrom( s, buf, len, 0, (struct sockaddr *)saddr, &slen );
950         if( n < 0 )
951                 errno_crash_and_burn( "recvfrom" );
952         
This page took 0.181269 seconds and 3 git commands to generate.