1 |
/* Copyright (C) 2001, 2002 Free Software Foundation, Inc. |
/* Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc. |
2 |
|
|
3 |
This file is part of GNU Inetutils. |
This file is part of GNU Inetutils. |
4 |
|
|
45 |
#include <errno.h> |
#include <errno.h> |
46 |
#include <limits.h> |
#include <limits.h> |
47 |
|
|
|
#include "getopt.h" |
|
48 |
#include <icmp.h> |
#include <icmp.h> |
49 |
#include <ping.h> |
#include <ping.h> |
50 |
#include <ping_impl.h> |
#include "ping_common.h" |
51 |
|
#include "ping_impl.h" |
52 |
|
|
53 |
#define NROUTES 9 /* number of record route slots */ |
#define NROUTES 9 /* number of record route slots */ |
54 |
#ifndef MAX_IPOPTLEN |
#ifndef MAX_IPOPTLEN |
55 |
# define MAX_IPOPTLEN 40 |
# define MAX_IPOPTLEN 40 |
56 |
#endif |
#endif |
57 |
|
|
58 |
extern char *xstrdup (const char *); |
#include <xalloc.h> |
|
extern char *xmalloc (size_t); |
|
59 |
|
|
60 |
static int handler (int code, void *closure, |
static int handler (int code, void *closure, |
61 |
struct sockaddr_in *dest, struct sockaddr_in *from, |
struct sockaddr_in *dest, struct sockaddr_in *from, |
69 |
struct ip *ip, icmphdr_t *icmp, int len); |
struct ip *ip, icmphdr_t *icmp, int len); |
70 |
static void print_ip_opt (struct ip *ip, int hlen); |
static void print_ip_opt (struct ip *ip, int hlen); |
71 |
|
|
|
static void tvsub (struct timeval *out, struct timeval *in); |
|
|
|
|
72 |
int |
int |
73 |
ping_echo (int argc, char **argv) |
ping_echo (int argc, char **argv) |
74 |
{ |
{ |
523 |
} |
} |
524 |
} |
} |
525 |
|
|
|
/* |
|
|
* tvsub -- |
|
|
* Subtract 2 timeval structs: out = out - in. Out is assumed to |
|
|
* be >= in. |
|
|
*/ |
|
|
static void |
|
|
tvsub (struct timeval *out, struct timeval *in) |
|
|
{ |
|
|
if ((out->tv_usec -= in->tv_usec) < 0) |
|
|
{ |
|
|
--out->tv_sec; |
|
|
out->tv_usec += 1000000; |
|
|
} |
|
|
out->tv_sec -= in->tv_sec; |
|
|
} |
|
|
|
|
|
double |
|
|
nabs (double a) |
|
|
{ |
|
|
return (a < 0) ? -a : a; |
|
|
} |
|
|
|
|
|
double |
|
|
nsqrt (double a, double prec) |
|
|
{ |
|
|
double x0, x1; |
|
|
|
|
|
if (a < 0) |
|
|
return 0; |
|
|
if (a < prec) |
|
|
return 0; |
|
|
x1 = a/2; |
|
|
do |
|
|
{ |
|
|
x0 = x1; |
|
|
x1 = (x0 + a/x0) / 2; |
|
|
} |
|
|
while (nabs (x1 - x0) > prec); |
|
|
|
|
|
return x1; |
|
|
} |
|
|
|
|
526 |
int |
int |
527 |
echo_finish () |
echo_finish () |
528 |
{ |
{ |