traceroute.c revision eff627200981c7d4a5e26ed5da7e3e99db1624ef
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University nor the names of its contributors may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
*
* @(#)$Header: traceroute.c,v 1.49 97/06/13 02:30:23 leres Exp $ (LBL)
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/sysmacros.h>
#include <netinet/in_systm.h>
#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <memory.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <libintl.h>
#include <locale.h>
#include <signal.h>
#include <setjmp.h>
#include <limits.h>
#include <zone.h>
#include <priv_utils.h>
#include <libinetutil.h>
#include "traceroute.h"
#define STR_LEN 30
/* store the information about a host */
struct hostinfo {
char *name; /* hostname */
int family; /* address family of the IP addresses */
int num_addr; /* number of IP addresses */
};
/* used to store a bunch of protocol specific values */
struct pr_set {
int family; /* AF_INET or AF_INET6 */
int icmp_minlen;
int addr_len;
int ip_hdr_len;
int packlen;
int sock_size; /* size of sockaddr_in or sockaddr_in6 */
void *from_sin_addr;
union any_in_addr *gwIPlist;
struct ip *(*set_buffers_fn) (int);
};
/*
* LBNL bug fixed: in LBNL traceroute 'uchar_t packet[512];'
* Not sufficient to hold the complete packet for ECHO REPLY of a big probe.
* Packet size is reported incorrectly in such a case.
* Also this buffer needs to be 32 bit aligned. In the future the alignment
* requirement will be increased to 64 bit. So, let's use 64 bit alignment now.
*/
/* Used to store the ancillary data that comes with the received packets */
/* first get the gw names, later you'll resolve them based on the family */
static int rcvsock4; /* receive (icmp) socket file descriptor */
static int rcvsock6; /* receive (icmp6) socket file descriptor */
int gw_count = 0; /* number of gateways */
static struct sockaddr_in6 whereto6;
static struct sockaddr_in6 wherefrom6;
static int packlen_input = 0; /* user input for packlen */
char *prog;
char *hostname;
static int num_v4 = 0; /* count of IPv4 addresses */
static int num_v6 = 0; /* count of IPv6 addresses */
static int num_ifs4 = 0; /* count of local IPv4 interfaces */
static int num_ifs6 = 0; /* count of local IPv6 interfaces */
ushort_t ident; /* used to authenticate replies */
static int options = 0; /* socket options */
/*
* flow and class are specific to IPv6, tos and off are specific to IPv4.
* Each protocol uses the ones that are specific to itself, and ignores
* others.
*/
/* Forwards */
struct pr_set *);
extern void *find_ancillary_data(struct msghdr *, int, int);
union any_in_addr *, int);
static void get_gwaddrs(char **, int, union any_in_addr *,
union any_in_addr *, int *, int *);
static void get_hostinfo(char *, int, struct addrinfo **);
char *inet_name(union any_in_addr *, int);
static void print_stats(int, int, double, double, double, double);
static void print_unknown_host_msg(const char *, const char *);
static void record_stats(double, int *, double *, double *, double *, double *);
static void resolve_nodes(int *, struct addrinfo **);
struct timeval *, int);
struct timeval *, int);
uint_t);
extern struct ip *set_buffers(int);
extern struct ip *set_buffers6(int);
extern void set_IPv4opt_sourcerouting(int, union any_in_addr *,
union any_in_addr *);
static void setup_protocol(struct pr_set *, int);
static void setup_socket(struct pr_set *, int);
static void sig_handler(int);
static int str2int(const char *, const char *, int, int);
static double str2dbl(const char *, const char *, double, double);
int, struct ifaddrlist *);
static void usage(void);
static double xsqrt(double);
/*
* main
*/
int
{
/*
* "probing_successful" indicates if we could successfully send probes,
* not necessarily received reply from the target (this behavior is from
* the original traceroute). It's _B_FALSE if packlen is invalid, or no
* interfaces found.
*/
int longjmp_return; /* return value from longjump */
int i = 0;
char *cp;
int op;
char *ep;
double pause;
/*
* A raw socket will be used for IPv4 if there is sufficient
* privilege.
*/
/*
* We'll need the privilege only when we open the sockets; that's
* when we'll fail if the program has insufficient privileges.
*/
(void) setlinebuf(stdout);
else
opterr = 0;
"t:w:")) != EOF) {
switch (op) {
case 'A':
} else {
"%s: unknown address family %s\n",
}
break;
case 'a':
break;
case 'c':
break;
case 'd':
break;
case 'f':
break;
case 'F':
break;
case 'g':
if (!raw_req) {
"%s: privilege to specify a loose source "
"route gateway is unavailable\n",
prog);
}
if (gw_count >= MAXMAX_GWS) {
"%s: Too many gateways\n", prog);
}
}
++gw_count;
break;
case 'l':
break;
case 'i':
/* this can be IF name or IF index */
/* convert IF index <--> IF name */
/*
* In case it fails, check to see if the problem
* is other than "IF not found".
*/
}
} else {
}
/*
* The problem was other than "index
* not found".
*/
}
}
"doesn't match any actual interfaces\n",
}
break;
case 'I':
break;
case 'L':
break;
case 'm':
MAXTTL);
break;
case 'n':
break;
case 'P':
1000000);
break;
case 'p':
break;
case 'Q':
break;
case 'q':
break;
case 'r':
options |= SO_DONTROUTE;
break;
case 'S':
break;
case 's':
/*
* set the ip source address of the outbound
* probe (e.g., on a multi-homed host).
*/
break;
case 't':
break;
case 'v':
break;
case 'x':
break;
case 'w':
break;
default:
usage();
break;
}
}
/*
* If it's probe_all, SIGQUIT makes traceroute exit(). But we set the
* address to jump back to in traceroute(). Until then, we'll need to
* temporarily specify one.
*/
if (probe_all) {
if (longjmp_return == SIGQUIT) {
Printf("(exiting)\n");
} else { /* should never happen */
}
}
}
" cannot be specified when probe packets are sent"
" directly to a host on an attached network (-r)\n",
prog);
}
if (i == 1 || i == 2) {
if (i == 2) {
/* accept any length now, we'll check it later */
"packet length", 0, -1);
}
} else {
usage();
}
"%s: first ttl(hop limit) (%d) may not be greater"
" than max ttl(hop limit) (%d)\n",
}
/* resolve hostnames */
}
/*
* If it's probe_all, SIGINT makes traceroute skip to probing next IP
* address of the target. The new interrupt handler is assigned in
* traceroute() function. Until then let's ignore the signal.
*/
if (probe_all)
/*
* We KNOW that probe_all == TRUE if family is AF_UNSPEC,
* since family is set to the specific AF found unless it's
* probe_all. So if family == AF_UNSPEC, we need to init pr4 and pr6.
*/
switch (family_input) {
case AF_UNSPEC:
}
}
break;
case AF_INET6:
}
break;
case AF_INET:
}
break;
default:
}
"%s: Warning: %s has multiple addresses;"
/* LINTED E_BAD_PTR_CAST_ALIGN */
(void *)&((struct sockaddr_in *)
} else {
"%s: Warning: %s has multiple addresses;"
/* LINTED E_BAD_PTR_CAST_ALIGN */
(void *)&((struct sockaddr_in6 *)
}
}
}
/*
* if we could probe any of the IP addresses of the target, that means
* this was a successful operation
*/
if (probing_successful)
return (EXIT_SUCCESS);
else
return (EXIT_FAILURE);
}
/*
* print "unknown host" message
*/
static void
{
}
/*
* resolve destination host and gateways
*/
static void
{
int num_resolved_gw = 0;
int num_resolved_gw6 = 0;
}
/* Get a count of the v4 & v6 addresses */
case AF_INET:
num_v4++;
break;
case AF_INET6:
num_v6++;
break;
}
}
}
/* resolve gateways */
if (gw_count > 0) {
/* we couldn't resolve a gateway as an IPv6 host */
print_unknown_host_msg(" IPv6",
num_v6 = 0;
}
/* we couldn't resolve a gateway as an IPv4 host */
print_unknown_host_msg(" IPv4",
num_v4 = 0;
}
}
}
/*
* Given IP address or hostname, return v4 and v6 hostinfo lists.
* Assumes that hostinfo ** ptrs are non-null.
*/
static void
{
int rc;
/*
* Take care of v4-mapped addresses. It should run same as v4, after
* chopping off the prefix, leaving the IPv4 address
*/
/* peel off the "mapping" stuff, leaving 32 bit IPv4 address */
/* convert it back to a string */
sizeof (temp_buf));
/* now the host is an IPv4 address */
/*
* If it's a mapped address, we convert it into IPv4
* address because traceroute will send and receive IPv4
* packets for that address. Therefore, it's a failure case to
* ask get_hostinfo() to treat a mapped address as an IPv6
* address.
*/
return;
}
}
if (rc != 0) {
if (rc != EAI_NONAME)
gai_strerror(rc));
return;
}
}
/*
* Calculate the packet length to be used, and check against the valid range.
* Returns -1 if range check fails.
*/
static uint_t
{
int minpacket; /* min ip packet size */
int optlen; /* length of ip options */
int plen;
/*
* LBNL bug fixed: miscalculation of optlen
*/
if (gw_count > 0) {
/*
* IPv4:
* ----
* 5 (NO OPs) + 3 (code, len, ptr) + gateways
* IP options field can hold up to 9 gateways. But the API
* allows you to specify only 8, because the last one is the
* destination host. When this packet is sent, on the wire
* you see one gateway replaced by 4 NO OPs. The other 1 NO
* OP is for alignment
*
* IPv6:
* ----
* Well, formula is different, but the result is same.
* 8 byte fixed part for Type 0 Routing header, followed by
* gateway addresses
*/
} else {
optlen = 0;
}
/* take care of the packet length calculations and checks */
if (useicmp)
else
plen = plen_input;
if (plen == 0) {
return (0);
}
return (plen);
}
/*
* Sets the source address by resolving -i and -s arguments, or if -i and -s
* don't dictate any, it sets the pick_src to make sure traceroute uses the
* kernel's pick of the source address.
* Returns number of interfaces configured on the source host, 0 on error or
* there's no interface which is up amd not a loopback.
*/
static int
{
union any_in_addr *ap;
/* LINTED E_BAD_PTR_CAST_ALIGN */
/* LINTED E_BAD_PTR_CAST_ALIGN */
char errbuf[ERRBUFSIZE];
int num_ifs; /* all the interfaces */
int num_src_ifs; /* exclude loopback and down */
int i;
/* get the interface address list */
if (num_ifs < 0) {
}
num_src_ifs = 0;
for (i = 0; i < num_ifs; i++) {
num_src_ifs++;
}
if (num_src_ifs == 0) {
return (0);
}
/* verify the device */
return (0);
}
}
/* verify the source address */
"%s: %s is an invalid %s source address\n",
return (0);
}
ap = (union any_in_addr *)
/* LINTED E_BAD_PTR_CAST_ALIGN */
&((struct sockaddr_in *)
else
ap = (union any_in_addr *)
/* LINTED E_BAD_PTR_CAST_ALIGN */
&((struct sockaddr_in6 *)
/*
* LBNL bug fixed: used to accept any src address
*/
"%s: %s is not a local %s address\n",
return (0);
}
}
} else { /* -i used, no -s used */
/*
* -i used, but not -s, and it's IPv4: set the source
* address to whatever the interface has configured on
* it.
*/
else
}
} else { /* -s used */
"%s: Warning: %s has multiple "
"addresses; using %s\n",
(const void *)pr->from_sin_addr,
}
} else { /* -i and -s used */
/*
* Make sure the source specified matches the
* interface address. You only care about this for IPv4
* IPv6 can handle IF not matching src address
*/
"%s: %s is not on interface %s\n",
}
/*
* make sure we use the one matching the
* interface's address
*/
}
}
}
/*
* Binding at this point will set the source address to be used
* for both IPv4 (when raw IP datagrams are not required) and
* IPv6. If the address being bound to is zero, then the kernel
* will end up choosing the source address when the datagram is
* sent.
*
* For raw IPv4 datagrams, the source address is initialized
* within traceroute() along with the outbound destination
* address.
*/
sizeof (struct sockaddr_in)) < 0) {
}
sizeof (struct sockaddr_in6)) < 0) {
}
}
return (num_ifs);
}
/*
* Returns the complete ifaddrlist structure matching the desired interface
* address. Ignores interfaces which are either down or loopback.
*/
static struct ifaddrlist *
int family)
{
int i;
sizeof (struct in6_addr);
break;
}
if (i < len) {
return (tmp_al);
} else {
return (NULL);
}
}
/*
* Returns the complete ifaddrlist structure matching the desired interface name
* Ignores interfaces which are either down or loopback.
*/
static struct ifaddrlist *
{
int i;
break;
}
if (i < len) {
return (tmp_al);
} else {
return (NULL);
}
}
/*
* returns _B_TRUE if given hostinfo contains the given address
*/
static boolean_t
{
union any_in_addr *ap;
continue;
ap = (union any_in_addr *)
/* LINTED E_BAD_PTR_CAST_ALIGN */
break;
}
return (_B_TRUE);
} else {
return (_B_FALSE);
}
}
/*
* Resolve the gateway names, splitting results into v4 and v6 lists.
* Gateway addresses are added to the appropriate passed-in array; the
* number of resolved gateways for each af is returned in resolved[6].
* Assumes that passed-in arrays are large enough for MAX_GWS[6] addrs
* and resolved[6] ptrs are non-null; ignores array and counter if the
* address family param makes them irrelevant.
*/
static void
{
int i;
switch (family) {
case AF_UNSPEC:
break;
case AF_INET:
break;
case AF_INET6:
break;
default:
return;
}
num_v4 = 0;
}
num_v6 = 0;
}
for (i = 0; i < gw_count; i++) {
return;
return;
/* LINTED E_BAD_PTR_CAST_ALIGN */
bcopy(&((struct sockaddr_in *)
aip->ai_addrlen);
(*resolved)++;
break;
}
}
} else if (check_v4) {
}
/* LINTED E_BAD_PTR_CAST_ALIGN */
bcopy(&((struct sockaddr_in6 *)
aip->ai_addrlen);
(*resolved6)++;
break;
}
}
} else if (check_v6) {
}
}
}
/*
* set protocol specific values here
*/
static void
{
/*
* Set the global variables for each AF. This is going to save us lots
* of "if (family == AF_INET)... else .."
*/
if (!docksum) {
"%s: Warning: checksums disabled\n", prog);
}
} else {
}
}
/*
* setup the sockets for the given protocol's address family
*/
static void
{
int on = 1;
int type;
int proto;
int int_op;
int rsock;
int ssock;
}
/* privilege bracketing */
(void) __priv_bracket(PRIV_ON);
}
sizeof (on)) < 0) {
}
}
if (options & SO_DONTROUTE) {
sizeof (on)) < 0) {
}
}
/* Enable receipt of destination address info */
}
/* Enable receipt of hoplimit info */
}
}
/*
* Initialize the socket type and protocol based on the address
* family, whether or not a raw IP socket is required (for IPv4)
* or whether ICMP will be used instead of UDP.
*
* For historical reasons, the datagrams sent out by
* traceroute(1M) do not have the "don't fragment" flag set. For
* this reason as well as the ability to set the Loose Source and
* Record Route (LSRR) option, a raw IP socket will be used for
* IPv4 when run in the global zone. Otherwise, the actual
* datagram that will be sent will be a regular UDP or ICMP echo
* request packet. However for convenience and for future options
* when other IP header information may be specified using
* traceroute, the buffer including the raw IP and UDP or ICMP
* header is always filled in. When the probe is actually sent,
* the size of the request and the start of the packet is set
* according to the type of datagram to send.
*/
proto = IPPROTO_RAW;
} else if (useicmp) {
else
} else {
type = SOCK_DGRAM;
proto = IPPROTO_UDP;
}
if (ssock < 0) {
if (proto == IPPROTO_RAW) {
} else if (proto == IPPROTO_UDP) {
} else {
}
}
sizeof (packet_len)) < 0) {
}
sizeof (on)) < 0) {
}
}
sizeof (on)) < 0) {
}
}
if (options & SO_DONTROUTE) {
}
}
/*
* If a raw IPv4 packet is going to be sent, the Type of Service
* field in the packet will be initialized in set_buffers().
* Otherwise, it is initialized here using the IPPROTO_IP level
* socket option.
*/
sizeof (int_op)) < 0) {
}
}
} else {
}
/* Revert to non-privileged user after configuring sockets */
(void) __priv_bracket(PRIV_OFF);
}
/*
* If we are "probing all", this function calls traceroute() for each IP address
* of the target, otherwise calls only once. Returns _B_FALSE if traceroute()
* fails.
*/
static void
{
int num_dst_IPaddrs;
int i;
if (!probe_all)
num_dst_IPaddrs = 1;
else
/*
* Initialize the msg6 structure using the hoplimit for the first
* probe packet, gateway addresses and the outgoing interface index.
*/
msg6.msg_controllen = 0;
if_index);
}
/* run traceroute for all the IP addresses of the multihomed dest */
union any_in_addr *addrp;
addrp = (union any_in_addr *)
/* LINTED E_BAD_PTR_CAST_ALIGN */
&((struct sockaddr_in *)
} else {
addrp = (union any_in_addr *)
/* LINTED E_BAD_PTR_CAST_ALIGN */
&((struct sockaddr_in6 *)
}
if (i < (num_dst_IPaddrs - 1))
(void) putchar('\n');
}
}
/*
* set the IP address in a sockaddr struct
*/
static void
{
/* LINTED E_BAD_PTR_CAST_ALIGN */
else
/* LINTED E_BAD_PTR_CAST_ALIGN */
}
/*
* returns the IF name on which the given IP address is configured
*/
static char *
{
int i;
struct ifaddrlist *tmp_al;
}
}
return (NULL);
}
/*
* Trace the route to the host with given IP address.
*/
static void
{
int ttl;
int probe;
int reply;
int seq = 0;
int longjmp_return; /* return value from longjump */
int hoplimit; /* hoplimit for IPv6 packets */
int num_src_ifs; /* excludes down and loopback */
int *intp;
int sndsock;
int rcvsock;
/* carry out the source address selection */
if (pick_src) {
union any_in_addr src_addr;
char *dev_name;
int i;
/*
* If there's a gateway, a routing header as a consequence, our
* kernel picks the source address based on the first hop
* address, rather than final destination address.
*/
if (gw_count > 0) {
} else {
}
/* filter out down and loopback interfaces */
num_src_ifs = 0;
for (i = 0; i < num_ifs; i++) {
num_src_ifs++;
}
if (num_src_ifs > 1) {
dev_name = "?";
"%s: Warning: Multiple interfaces found;"
" using %s @ %s\n",
(const void *)pr->from_sin_addr,
dev_name);
}
}
}
/*
* If the hostname is an IPv6 literal address, let's not print it twice.
*/
} else {
sizeof (temp_buf)));
}
if (source)
/*
* Setup the source routing for IPv4. For IPv6, we did the required
* setup in the caller function, trace_it(), because it's independent
* from the IP address of target.
*/
if (probe_all) {
/* interrupt handler sig_handler() jumps back to here */
switch (longjmp_return) {
case SIGINT:
Printf("(skipping)\n");
return;
case SIGQUIT:
Printf("(exiting)\n");
default: /* should never happen */
}
}
}
union any_in_addr lastaddr;
int timeouts = 0;
double rtt; /* for statistics */
int nreceived = 0;
int unreachable;
unreachable = 0;
/*
* The following line clears both IPv4 and IPv6 address stored
* in the union.
*/
"%s: host %s is not on a directly-attached"
break;
}
++probe) {
int cc;
/*
* Put a delay before sending this probe packet. Don't
* delay it if it's the very first packet.
*/
if (!first_pkt) {
} else {
}
} else {
}
/* prepare msghdr for recvmsg() */
&t1)) != 0) {
sizeof (ancillary_data);
/* Skip short packet */
if (reply == REPLY_SHORT_PKT) {
continue;
}
timeouts = 0;
/*
* if reply comes from a different host, print
* the hostname
*/
/* store the address response */
}
if (collect_stat) {
} else {
}
intp =
(int *)find_ancillary_data(&in_msg,
"%s: can't find "
"IPV6_HOPLIMIT ancillary "
"data\n", prog);
}
}
if (reply == REPLY_GOT_TARGET) {
(hoplimit <= 1)))
Printf(" !");
}
if (!collect_stat && showttl) {
Printf(" (ttl=%d)",
} else if (hoplimit != -1) {
Printf(" (hop limit=%d)",
hoplimit);
}
}
if (reply == REPLY_GOT_OTHER) {
if ((*pr->print_icmp_other_fn)
unreachable++;
}
}
/* special case */
type == ICMP_UNREACH &&
break;
}
if (cc == 0) {
Printf(" *");
timeouts++;
}
}
if (collect_stat) {
rttssq);
}
(void) putchar('\n');
/* either we hit the target or received too many unreachables */
if (got_there ||
break;
}
/* Ignore the SIGINT between traceroute() runs */
if (probe_all)
}
/*
* for a given destination address and address family, it finds out what
* source address kernel is going to pick
*/
static void
int family)
{
int tmp_fd;
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
}
/* LINTED E_BAD_PTR_CAST_ALIGN */
sock_len = sizeof (struct sockaddr_in);
} else {
/* LINTED E_BAD_PTR_CAST_ALIGN */
sock_len = sizeof (struct sockaddr_in6);
}
/* open a UDP socket */
}
/* connect it */
/*
* If there's no route to the destination, this connect() call
* fails. We just return all-zero (wildcard) as the source
* address, so that user can get to see "no route to dest"
* message, as it'll try to send the probe packet out and will
* receive ICMP unreachable.
*/
else
return;
}
/* get the local sock info */
}
/* LINTED E_BAD_PTR_CAST_ALIGN */
} else {
/* LINTED E_BAD_PTR_CAST_ALIGN */
}
}
/*
* Checksum routine for Internet Protocol family headers (C Version)
*/
{
int sum = 0;
/*
* Our algorithm is simple, using a 32 bit accumulator (sum),
* we add sequential 16 bit words to it, and at the end, fold
* back all the carry bits from the top 16 bits into the lower
* 16 bits.
*/
while (nleft > 1) {
sum += *w++;
nleft -= 2;
}
/* mop up an odd byte, if necessary */
if (nleft == 1)
/* add back carry outs from top 16 bits to low 16 bits */
return (answer);
}
/*
* Wait until a reply arrives or timeout occurs. If packet arrived, read it
* return the size of the packet read.
*/
static int
{
int cc = 0;
int result;
return (0);
if (result == -1) {
}
} else if (result > 0)
return (cc);
}
/*
* Construct an Internet address representation. If the nflag has been supplied,
* give numeric value, otherwise try for symbolic name.
*/
char *
{
char *cp;
/* (NI_MAXHOST + 1) >= INET6_ADDRSTRLEN */
char hbuf[NI_MAXHOST];
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
int flags;
switch (family) {
case AF_INET:
slen = sizeof (struct sockaddr_in);
break;
case AF_INET6:
slen = sizeof (struct sockaddr_in6);
sin6.sin6_scope_id = 0;
break;
default:
"<invalid address family>");
return (line);
}
/* find out the domain name */
} else {
domain[0] = '\0';
}
}
hbuf[0] = 0;
*cp = '\0';
}
return (line);
}
/*
* return the difference (in msec) between two time values
*/
static double
{
double dt;
return (dt);
}
/*
* Subtract 2 timeval structs: out = out - in.
* Out is assumed to be >= in.
*/
static void
{
}
}
/*
* record statistics
*/
static void
{
if (*nreceived == 0) {
} else {
}
(*nreceived)++;
}
/*
* display statistics
*/
static void
{
double rttavg; /* average round-trip time */
double rttstd; /* rtt standard deviation */
if (nreceived > 0) {
}
if (nreceived == 0)
Printf(" (100%% loss)");
else
}
}
/*
* square root function
*/
double
xsqrt(double y)
{
double t, x;
if (y <= 0) {
return (0.0);
}
x = (y < 1.0) ? 1.0 : y;
do {
t = x;
x = (t + (y/t))/2.0;
} while (0 < x && x < t);
return (x);
}
/*
* String to double with optional min and max.
*/
static double
{
double val;
char *ep;
errno = 0;
}
}
}
return (val);
}
/*
* String to int with optional min and max. Handles decimal and hex.
*/
static int
{
const char *cp;
int val;
char *ep;
errno = 0;
} else {
}
}
if (mi == 0) {
} else {
}
}
}
return (val);
}
/*
* This is the interrupt handler for SIGINT and SIGQUIT. It's completely handled
* where it jumps to.
*/
static void
sig_handler(int sig)
{
}
/*
* display the usage of traceroute
*/
static void
usage(void)
{
"[-c traffic_class] \n"
"\t[-f first_hop] [-g gateway [-g gateway ...]| -r] [-i iface]\n"
"\t[-L flow_label] [-m max_hop] [-P pause_sec] [-p port] [-Q max_timeout]\n"
"\t[-q nqueries] [-s src_addr] [-t tos] [-w wait_time] host [packetlen]\n",
prog);
}