Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 2 | /* |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 3 | * Mini ping implementation for busybox |
| 4 | * |
| 5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
| 6 | * |
Rob Landley | 42eddba | 2005-12-15 08:04:17 +0000 | [diff] [blame] | 7 | * Adapted from the ping in netkit-base 0.10: |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 8 | * Copyright (c) 1989 The Regents of the University of California. |
Denis Vlasenko | 35d4da0 | 2007-01-22 14:04:27 +0000 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * This code is derived from software contributed to Berkeley by |
| 12 | * Mike Muuss. |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 13 | * |
Rob Landley | 42eddba | 2005-12-15 08:04:17 +0000 | [diff] [blame] | 14 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 15 | */ |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 16 | /* from ping6.c: |
| 17 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
| 18 | * |
| 19 | * This version of ping is adapted from the ping in netkit-base 0.10, |
| 20 | * which is: |
| 21 | * |
| 22 | * Original copyright notice is retained at the end of this file. |
| 23 | * |
| 24 | * This version is an adaptation of ping.c from busybox. |
| 25 | * The code was modified by Bart Visscher <magick@linux-fan.com> |
| 26 | */ |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 27 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 28 | #include <net/if.h> |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 29 | #include <netinet/ip_icmp.h> |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 30 | #include "libbb.h" |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 31 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 32 | #if ENABLE_PING6 |
Denys Vlasenko | ad7d94b | 2009-11-20 18:12:12 +0100 | [diff] [blame] | 33 | # include <netinet/icmp6.h> |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 34 | /* I see RENUMBERED constants in bits/in.h - !!? |
| 35 | * What a fuck is going on with libc? Is it a glibc joke? */ |
Denys Vlasenko | ad7d94b | 2009-11-20 18:12:12 +0100 | [diff] [blame] | 36 | # ifdef IPV6_2292HOPLIMIT |
| 37 | # undef IPV6_HOPLIMIT |
| 38 | # define IPV6_HOPLIMIT IPV6_2292HOPLIMIT |
| 39 | # endif |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 40 | #endif |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 41 | |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 42 | enum { |
| 43 | DEFDATALEN = 56, |
| 44 | MAXIPLEN = 60, |
| 45 | MAXICMPLEN = 76, |
| 46 | MAXPACKET = 65468, |
| 47 | MAX_DUP_CHK = (8 * 128), |
| 48 | MAXWAIT = 10, |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 49 | PINGINTERVAL = 1, /* 1 second */ |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 50 | }; |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 51 | |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 52 | /* common routines */ |
Denis Vlasenko | 4a5cf16 | 2006-11-20 00:48:22 +0000 | [diff] [blame] | 53 | |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 54 | static int in_cksum(unsigned short *buf, int sz) |
| 55 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 56 | int nleft = sz; |
| 57 | int sum = 0; |
| 58 | unsigned short *w = buf; |
| 59 | unsigned short ans = 0; |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 60 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 61 | while (nleft > 1) { |
| 62 | sum += *w++; |
| 63 | nleft -= 2; |
| 64 | } |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 65 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 66 | if (nleft == 1) { |
| 67 | *(unsigned char *) (&ans) = *(unsigned char *) w; |
| 68 | sum += ans; |
| 69 | } |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 70 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 71 | sum = (sum >> 16) + (sum & 0xFFFF); |
| 72 | sum += (sum >> 16); |
| 73 | ans = ~sum; |
Denis Vlasenko | d9e15f2 | 2006-11-27 16:49:55 +0000 | [diff] [blame] | 74 | return ans; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 75 | } |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 76 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 77 | #if !ENABLE_FEATURE_FANCY_PING |
Denis Vlasenko | 4a5cf16 | 2006-11-20 00:48:22 +0000 | [diff] [blame] | 78 | |
| 79 | /* simple version */ |
| 80 | |
Denis Vlasenko | cb6874c | 2006-09-02 16:13:36 +0000 | [diff] [blame] | 81 | static char *hostname; |
| 82 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 83 | static void noresp(int ign UNUSED_PARAM) |
Eric Andersen | b5474c4 | 2002-03-20 11:59:28 +0000 | [diff] [blame] | 84 | { |
Eric Andersen | b888682 | 2002-03-21 14:04:43 +0000 | [diff] [blame] | 85 | printf("No response from %s\n", hostname); |
Eric Andersen | 4e486a5 | 2003-01-12 06:08:33 +0000 | [diff] [blame] | 86 | exit(EXIT_FAILURE); |
Eric Andersen | b5474c4 | 2002-03-20 11:59:28 +0000 | [diff] [blame] | 87 | } |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 88 | |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 89 | static void ping4(len_and_sockaddr *lsa) |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 90 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 91 | struct sockaddr_in pingaddr; |
| 92 | struct icmp *pkt; |
| 93 | int pingsock, c; |
| 94 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 95 | |
Matt Kraai | 06ef165 | 2001-07-13 20:56:27 +0000 | [diff] [blame] | 96 | pingsock = create_icmp_socket(); |
Paul Fox | 0b2b584 | 2008-02-01 23:25:32 +0000 | [diff] [blame] | 97 | pingaddr = lsa->u.sin; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 98 | |
| 99 | pkt = (struct icmp *) packet; |
| 100 | memset(pkt, 0, sizeof(packet)); |
| 101 | pkt->icmp_type = ICMP_ECHO; |
| 102 | pkt->icmp_cksum = in_cksum((unsigned short *) pkt, sizeof(packet)); |
| 103 | |
Bernhard Reutner-Fischer | b290889 | 2007-04-12 11:34:39 +0000 | [diff] [blame] | 104 | c = xsendto(pingsock, packet, DEFDATALEN + ICMP_MINLEN, |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 105 | (struct sockaddr *) &pingaddr, sizeof(pingaddr)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 106 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 107 | /* listen for replies */ |
| 108 | while (1) { |
| 109 | struct sockaddr_in from; |
Mike Frysinger | 03e827a | 2005-07-26 23:00:59 +0000 | [diff] [blame] | 110 | socklen_t fromlen = sizeof(from); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 111 | |
Denis Vlasenko | 806116b | 2006-12-31 12:14:16 +0000 | [diff] [blame] | 112 | c = recvfrom(pingsock, packet, sizeof(packet), 0, |
| 113 | (struct sockaddr *) &from, &fromlen); |
| 114 | if (c < 0) { |
Denis Vlasenko | 44c2eb2 | 2007-01-08 23:55:33 +0000 | [diff] [blame] | 115 | if (errno != EINTR) |
| 116 | bb_perror_msg("recvfrom"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 117 | continue; |
| 118 | } |
| 119 | if (c >= 76) { /* ip + icmp */ |
| 120 | struct iphdr *iphdr = (struct iphdr *) packet; |
| 121 | |
| 122 | pkt = (struct icmp *) (packet + (iphdr->ihl << 2)); /* skip ip hdr */ |
| 123 | if (pkt->icmp_type == ICMP_ECHOREPLY) |
| 124 | break; |
| 125 | } |
| 126 | } |
Denis Vlasenko | 9adc6ce | 2007-01-22 22:45:27 +0000 | [diff] [blame] | 127 | if (ENABLE_FEATURE_CLEAN_UP) |
| 128 | close(pingsock); |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 131 | #if ENABLE_PING6 |
| 132 | static void ping6(len_and_sockaddr *lsa) |
| 133 | { |
| 134 | struct sockaddr_in6 pingaddr; |
| 135 | struct icmp6_hdr *pkt; |
| 136 | int pingsock, c; |
| 137 | int sockopt; |
| 138 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
| 139 | |
| 140 | pingsock = create_icmp6_socket(); |
Paul Fox | 0b2b584 | 2008-02-01 23:25:32 +0000 | [diff] [blame] | 141 | pingaddr = lsa->u.sin6; |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 142 | |
| 143 | pkt = (struct icmp6_hdr *) packet; |
| 144 | memset(pkt, 0, sizeof(packet)); |
| 145 | pkt->icmp6_type = ICMP6_ECHO_REQUEST; |
| 146 | |
| 147 | sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); |
| 148 | setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt)); |
| 149 | |
Bernhard Reutner-Fischer | b290889 | 2007-04-12 11:34:39 +0000 | [diff] [blame] | 150 | c = xsendto(pingsock, packet, DEFDATALEN + sizeof (struct icmp6_hdr), |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 151 | (struct sockaddr *) &pingaddr, sizeof(pingaddr)); |
| 152 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 153 | /* listen for replies */ |
| 154 | while (1) { |
| 155 | struct sockaddr_in6 from; |
| 156 | socklen_t fromlen = sizeof(from); |
| 157 | |
| 158 | c = recvfrom(pingsock, packet, sizeof(packet), 0, |
| 159 | (struct sockaddr *) &from, &fromlen); |
| 160 | if (c < 0) { |
| 161 | if (errno != EINTR) |
| 162 | bb_perror_msg("recvfrom"); |
| 163 | continue; |
| 164 | } |
| 165 | if (c >= 8) { /* icmp6_hdr */ |
| 166 | pkt = (struct icmp6_hdr *) packet; |
| 167 | if (pkt->icmp6_type == ICMP6_ECHO_REPLY) |
| 168 | break; |
| 169 | } |
| 170 | } |
| 171 | if (ENABLE_FEATURE_CLEAN_UP) |
| 172 | close(pingsock); |
| 173 | } |
| 174 | #endif |
| 175 | |
Denys Vlasenko | ad7d94b | 2009-11-20 18:12:12 +0100 | [diff] [blame] | 176 | #if !ENABLE_PING6 |
| 177 | # define common_ping_main(af, argv) common_ping_main(argv) |
| 178 | #endif |
| 179 | static int common_ping_main(sa_family_t af, char **argv) |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 180 | { |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 181 | len_and_sockaddr *lsa; |
Denis Vlasenko | 3483e85 | 2007-07-02 15:47:52 +0000 | [diff] [blame] | 182 | |
Denys Vlasenko | ad7d94b | 2009-11-20 18:12:12 +0100 | [diff] [blame] | 183 | #if ENABLE_PING6 |
Denis Vlasenko | 3483e85 | 2007-07-02 15:47:52 +0000 | [diff] [blame] | 184 | while ((++argv)[0] && argv[0][0] == '-') { |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 185 | if (argv[0][1] == '4') { |
| 186 | af = AF_INET; |
| 187 | continue; |
| 188 | } |
| 189 | if (argv[0][1] == '6') { |
| 190 | af = AF_INET6; |
| 191 | continue; |
| 192 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 193 | bb_show_usage(); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 194 | } |
| 195 | #else |
| 196 | argv++; |
| 197 | #endif |
| 198 | |
| 199 | hostname = *argv; |
| 200 | if (!hostname) |
| 201 | bb_show_usage(); |
| 202 | |
| 203 | #if ENABLE_PING6 |
Denis Vlasenko | 42823d5 | 2007-02-04 02:39:08 +0000 | [diff] [blame] | 204 | lsa = xhost_and_af2sockaddr(hostname, 0, af); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 205 | #else |
Denis Vlasenko | 42823d5 | 2007-02-04 02:39:08 +0000 | [diff] [blame] | 206 | lsa = xhost_and_af2sockaddr(hostname, 0, AF_INET); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 207 | #endif |
| 208 | /* Set timer _after_ DNS resolution */ |
| 209 | signal(SIGALRM, noresp); |
| 210 | alarm(5); /* give the host 5000ms to respond */ |
| 211 | |
| 212 | #if ENABLE_PING6 |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 213 | if (lsa->u.sa.sa_family == AF_INET6) |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 214 | ping6(lsa); |
| 215 | else |
| 216 | #endif |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 217 | ping4(lsa); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 218 | printf("%s is alive!\n", hostname); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 219 | return EXIT_SUCCESS; |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 222 | |
| 223 | #else /* FEATURE_FANCY_PING */ |
| 224 | |
Denis Vlasenko | 4a5cf16 | 2006-11-20 00:48:22 +0000 | [diff] [blame] | 225 | |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 226 | /* full(er) version */ |
Denis Vlasenko | 4a5cf16 | 2006-11-20 00:48:22 +0000 | [diff] [blame] | 227 | |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 228 | #define OPT_STRING ("qvc:s:w:W:I:4" IF_PING6("6")) |
Denis Vlasenko | 4a5cf16 | 2006-11-20 00:48:22 +0000 | [diff] [blame] | 229 | enum { |
| 230 | OPT_QUIET = 1 << 0, |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 231 | OPT_VERBOSE = 1 << 1, |
| 232 | OPT_c = 1 << 2, |
| 233 | OPT_s = 1 << 3, |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 234 | OPT_w = 1 << 4, |
| 235 | OPT_W = 1 << 5, |
| 236 | OPT_I = 1 << 6, |
| 237 | OPT_IPV4 = 1 << 7, |
| 238 | OPT_IPV6 = (1 << 8) * ENABLE_PING6, |
Denis Vlasenko | 4a5cf16 | 2006-11-20 00:48:22 +0000 | [diff] [blame] | 239 | }; |
| 240 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 241 | |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 242 | struct globals { |
| 243 | int pingsock; |
Denis Vlasenko | 1a7afb4 | 2007-10-19 21:39:25 +0000 | [diff] [blame] | 244 | int if_index; |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 245 | char *str_I; |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 246 | len_and_sockaddr *source_lsa; |
| 247 | unsigned datalen; |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 248 | unsigned pingcount; /* must be int-sized */ |
| 249 | unsigned long ntransmitted, nreceived, nrepeats; |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 250 | uint16_t myid; |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 251 | unsigned tmin, tmax; /* in us */ |
| 252 | unsigned long long tsum; /* in us, sum of all times */ |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 253 | unsigned deadline; |
| 254 | unsigned timeout; |
| 255 | unsigned total_secs; |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 256 | const char *hostname; |
| 257 | const char *dotted; |
| 258 | union { |
| 259 | struct sockaddr sa; |
| 260 | struct sockaddr_in sin; |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 261 | #if ENABLE_PING6 |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 262 | struct sockaddr_in6 sin6; |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 263 | #endif |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 264 | } pingaddr; |
| 265 | char rcvd_tbl[MAX_DUP_CHK / 8]; |
| 266 | }; |
| 267 | #define G (*(struct globals*)&bb_common_bufsiz1) |
| 268 | #define pingsock (G.pingsock ) |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 269 | #define if_index (G.if_index ) |
Denis Vlasenko | 1a7afb4 | 2007-10-19 21:39:25 +0000 | [diff] [blame] | 270 | #define source_lsa (G.source_lsa ) |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 271 | #define str_I (G.str_I ) |
Denis Vlasenko | 1a7afb4 | 2007-10-19 21:39:25 +0000 | [diff] [blame] | 272 | #define datalen (G.datalen ) |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 273 | #define ntransmitted (G.ntransmitted) |
| 274 | #define nreceived (G.nreceived ) |
| 275 | #define nrepeats (G.nrepeats ) |
| 276 | #define pingcount (G.pingcount ) |
| 277 | #define myid (G.myid ) |
| 278 | #define tmin (G.tmin ) |
| 279 | #define tmax (G.tmax ) |
| 280 | #define tsum (G.tsum ) |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 281 | #define deadline (G.deadline ) |
| 282 | #define timeout (G.timeout ) |
| 283 | #define total_secs (G.total_secs ) |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 284 | #define hostname (G.hostname ) |
| 285 | #define dotted (G.dotted ) |
| 286 | #define pingaddr (G.pingaddr ) |
| 287 | #define rcvd_tbl (G.rcvd_tbl ) |
| 288 | void BUG_ping_globals_too_big(void); |
| 289 | #define INIT_G() do { \ |
Denis Vlasenko | 6b40443 | 2008-01-07 16:13:14 +0000 | [diff] [blame] | 290 | if (sizeof(G) > COMMON_BUFSIZE) \ |
| 291 | BUG_ping_globals_too_big(); \ |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 292 | pingsock = -1; \ |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 293 | datalen = DEFDATALEN; \ |
| 294 | timeout = MAXWAIT; \ |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 295 | tmin = UINT_MAX; \ |
| 296 | } while (0) |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 297 | |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 298 | |
Denis Vlasenko | 4a5cf16 | 2006-11-20 00:48:22 +0000 | [diff] [blame] | 299 | #define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */ |
| 300 | #define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */ |
| 301 | #define SET(bit) (A(bit) |= B(bit)) |
| 302 | #define CLR(bit) (A(bit) &= (~B(bit))) |
| 303 | #define TST(bit) (A(bit) & B(bit)) |
| 304 | |
Eric Andersen | 19db07b | 1999-12-11 08:41:28 +0000 | [diff] [blame] | 305 | /**************************************************************************/ |
| 306 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 307 | static void print_stats_and_exit(int junk) NORETURN; |
| 308 | static void print_stats_and_exit(int junk UNUSED_PARAM) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 309 | { |
| 310 | signal(SIGINT, SIG_IGN); |
| 311 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 312 | printf("\n--- %s ping statistics ---\n", hostname); |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 313 | printf("%lu packets transmitted, ", ntransmitted); |
| 314 | printf("%lu packets received, ", nreceived); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 315 | if (nrepeats) |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 316 | printf("%lu duplicates, ", nrepeats); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 317 | if (ntransmitted) |
Denis Vlasenko | aeb4bdd | 2007-01-25 00:00:02 +0000 | [diff] [blame] | 318 | ntransmitted = (ntransmitted - nreceived) * 100 / ntransmitted; |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 319 | printf("%lu%% packet loss\n", ntransmitted); |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 320 | if (tmin != UINT_MAX) { |
| 321 | unsigned tavg = tsum / (nreceived + nrepeats); |
| 322 | printf("round-trip min/avg/max = %u.%03u/%u.%03u/%u.%03u ms\n", |
| 323 | tmin / 1000, tmin % 1000, |
| 324 | tavg / 1000, tavg % 1000, |
| 325 | tmax / 1000, tmax % 1000); |
| 326 | } |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 327 | /* if condition is true, exit with 1 -- 'failure' */ |
| 328 | exit(nreceived == 0 || (deadline && nreceived < pingcount)); |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Denis Vlasenko | c8e9993 | 2007-02-09 18:14:42 +0000 | [diff] [blame] | 331 | static void sendping_tail(void (*sp)(int), const void *pkt, int size_pkt) |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 332 | { |
Denis Vlasenko | c8e9993 | 2007-02-09 18:14:42 +0000 | [diff] [blame] | 333 | int sz; |
| 334 | |
| 335 | CLR((uint16_t)ntransmitted % MAX_DUP_CHK); |
| 336 | ntransmitted++; |
| 337 | |
| 338 | /* sizeof(pingaddr) can be larger than real sa size, but I think |
| 339 | * it doesn't matter */ |
Bernhard Reutner-Fischer | b290889 | 2007-04-12 11:34:39 +0000 | [diff] [blame] | 340 | sz = xsendto(pingsock, pkt, size_pkt, &pingaddr.sa, sizeof(pingaddr)); |
Denis Vlasenko | c8e9993 | 2007-02-09 18:14:42 +0000 | [diff] [blame] | 341 | if (sz != size_pkt) |
Bernhard Reutner-Fischer | b290889 | 2007-04-12 11:34:39 +0000 | [diff] [blame] | 342 | bb_error_msg_and_die(bb_msg_write_error); |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 343 | |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 344 | if (pingcount == 0 || deadline || ntransmitted < pingcount) { |
| 345 | /* Didn't send all pings yet - schedule next in 1s */ |
| 346 | signal(SIGALRM, sp); |
| 347 | if (deadline) { |
| 348 | total_secs += PINGINTERVAL; |
| 349 | if (total_secs >= deadline) |
| 350 | signal(SIGALRM, print_stats_and_exit); |
| 351 | } |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 352 | alarm(PINGINTERVAL); |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 353 | } else { /* -c NN, and all NN are sent (and no deadline) */ |
| 354 | /* Wait for the last ping to come back. |
| 355 | * -W timeout: wait for a response in seconds. |
| 356 | * Affects only timeout in absense of any responses, |
| 357 | * otherwise ping waits for two RTTs. */ |
| 358 | unsigned expire = timeout; |
| 359 | |
| 360 | if (nreceived) { |
| 361 | /* approx. 2*tmax, in seconds (2 RTT) */ |
| 362 | expire = tmax / (512*1024); |
| 363 | if (expire == 0) |
| 364 | expire = 1; |
| 365 | } |
| 366 | signal(SIGALRM, print_stats_and_exit); |
| 367 | alarm(expire); |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 371 | static void sendping4(int junk UNUSED_PARAM) |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 372 | { |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 373 | /* +4 reserves a place for timestamp, which may end up sitting |
| 374 | * *after* packet. Saves one if() */ |
| 375 | struct icmp *pkt = alloca(datalen + ICMP_MINLEN + 4); |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 376 | |
Denis Vlasenko | b34266b | 2008-04-29 12:31:53 +0000 | [diff] [blame] | 377 | memset(pkt, 0, datalen + ICMP_MINLEN + 4); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 378 | pkt->icmp_type = ICMP_ECHO; |
Denis Vlasenko | b34266b | 2008-04-29 12:31:53 +0000 | [diff] [blame] | 379 | /*pkt->icmp_code = 0;*/ |
| 380 | /*pkt->icmp_cksum = 0;*/ |
Denis Vlasenko | 919c10d | 2007-01-03 22:14:18 +0000 | [diff] [blame] | 381 | pkt->icmp_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 382 | pkt->icmp_id = myid; |
Denis Vlasenko | 7b72fc1 | 2007-06-16 13:37:59 +0000 | [diff] [blame] | 383 | |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 384 | /* We don't do hton, because we will read it back on the same machine */ |
| 385 | /*if (datalen >= 4)*/ |
| 386 | *(uint32_t*)&pkt->icmp_dun = monotonic_us(); |
Denis Vlasenko | 7b72fc1 | 2007-06-16 13:37:59 +0000 | [diff] [blame] | 387 | |
Denis Vlasenko | c8e9993 | 2007-02-09 18:14:42 +0000 | [diff] [blame] | 388 | pkt->icmp_cksum = in_cksum((unsigned short *) pkt, datalen + ICMP_MINLEN); |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 389 | |
Denis Vlasenko | c8e9993 | 2007-02-09 18:14:42 +0000 | [diff] [blame] | 390 | sendping_tail(sendping4, pkt, datalen + ICMP_MINLEN); |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 391 | } |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 392 | #if ENABLE_PING6 |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 393 | static void sendping6(int junk UNUSED_PARAM) |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 394 | { |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 395 | struct icmp6_hdr *pkt = alloca(datalen + sizeof(struct icmp6_hdr) + 4); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 396 | |
Denis Vlasenko | b34266b | 2008-04-29 12:31:53 +0000 | [diff] [blame] | 397 | memset(pkt, 0, datalen + sizeof(struct icmp6_hdr) + 4); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 398 | pkt->icmp6_type = ICMP6_ECHO_REQUEST; |
Denis Vlasenko | b34266b | 2008-04-29 12:31:53 +0000 | [diff] [blame] | 399 | /*pkt->icmp6_code = 0;*/ |
| 400 | /*pkt->icmp6_cksum = 0;*/ |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 401 | pkt->icmp6_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */ |
| 402 | pkt->icmp6_id = myid; |
Denis Vlasenko | 7b72fc1 | 2007-06-16 13:37:59 +0000 | [diff] [blame] | 403 | |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 404 | /*if (datalen >= 4)*/ |
| 405 | *(uint32_t*)(&pkt->icmp6_data8[4]) = monotonic_us(); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 406 | |
Denis Vlasenko | c8e9993 | 2007-02-09 18:14:42 +0000 | [diff] [blame] | 407 | sendping_tail(sendping6, pkt, datalen + sizeof(struct icmp6_hdr)); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 408 | } |
| 409 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 410 | |
Denis Vlasenko | 89ef65f | 2007-01-29 23:43:18 +0000 | [diff] [blame] | 411 | static const char *icmp_type_name(int id) |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 412 | { |
| 413 | switch (id) { |
Denis Vlasenko | 35d4da0 | 2007-01-22 14:04:27 +0000 | [diff] [blame] | 414 | case ICMP_ECHOREPLY: return "Echo Reply"; |
| 415 | case ICMP_DEST_UNREACH: return "Destination Unreachable"; |
| 416 | case ICMP_SOURCE_QUENCH: return "Source Quench"; |
| 417 | case ICMP_REDIRECT: return "Redirect (change route)"; |
| 418 | case ICMP_ECHO: return "Echo Request"; |
| 419 | case ICMP_TIME_EXCEEDED: return "Time Exceeded"; |
| 420 | case ICMP_PARAMETERPROB: return "Parameter Problem"; |
| 421 | case ICMP_TIMESTAMP: return "Timestamp Request"; |
| 422 | case ICMP_TIMESTAMPREPLY: return "Timestamp Reply"; |
| 423 | case ICMP_INFO_REQUEST: return "Information Request"; |
| 424 | case ICMP_INFO_REPLY: return "Information Reply"; |
| 425 | case ICMP_ADDRESS: return "Address Mask Request"; |
| 426 | case ICMP_ADDRESSREPLY: return "Address Mask Reply"; |
| 427 | default: return "unknown ICMP type"; |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 428 | } |
| 429 | } |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 430 | #if ENABLE_PING6 |
| 431 | /* RFC3542 changed some definitions from RFC2292 for no good reason, whee! |
| 432 | * the newer 3542 uses a MLD_ prefix where as 2292 uses ICMP6_ prefix */ |
| 433 | #ifndef MLD_LISTENER_QUERY |
| 434 | # define MLD_LISTENER_QUERY ICMP6_MEMBERSHIP_QUERY |
| 435 | #endif |
| 436 | #ifndef MLD_LISTENER_REPORT |
| 437 | # define MLD_LISTENER_REPORT ICMP6_MEMBERSHIP_REPORT |
| 438 | #endif |
| 439 | #ifndef MLD_LISTENER_REDUCTION |
| 440 | # define MLD_LISTENER_REDUCTION ICMP6_MEMBERSHIP_REDUCTION |
| 441 | #endif |
Denis Vlasenko | 89ef65f | 2007-01-29 23:43:18 +0000 | [diff] [blame] | 442 | static const char *icmp6_type_name(int id) |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 443 | { |
| 444 | switch (id) { |
| 445 | case ICMP6_DST_UNREACH: return "Destination Unreachable"; |
| 446 | case ICMP6_PACKET_TOO_BIG: return "Packet too big"; |
| 447 | case ICMP6_TIME_EXCEEDED: return "Time Exceeded"; |
| 448 | case ICMP6_PARAM_PROB: return "Parameter Problem"; |
| 449 | case ICMP6_ECHO_REPLY: return "Echo Reply"; |
| 450 | case ICMP6_ECHO_REQUEST: return "Echo Request"; |
| 451 | case MLD_LISTENER_QUERY: return "Listener Query"; |
| 452 | case MLD_LISTENER_REPORT: return "Listener Report"; |
| 453 | case MLD_LISTENER_REDUCTION: return "Listener Reduction"; |
| 454 | default: return "unknown ICMP type"; |
| 455 | } |
| 456 | } |
| 457 | #endif |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 458 | |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 459 | static void unpack_tail(int sz, uint32_t *tp, |
Denis Vlasenko | 19c238b | 2007-03-03 00:36:35 +0000 | [diff] [blame] | 460 | const char *from_str, |
| 461 | uint16_t recv_seq, int ttl) |
| 462 | { |
| 463 | const char *dupmsg = " (DUP!)"; |
| 464 | unsigned triptime = triptime; /* for gcc */ |
| 465 | |
| 466 | ++nreceived; |
| 467 | |
| 468 | if (tp) { |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 469 | /* (int32_t) cast is for hypothetical 64-bit unsigned */ |
| 470 | /* (doesn't hurt 32-bit real-world anyway) */ |
| 471 | triptime = (int32_t) ((uint32_t)monotonic_us() - *tp); |
Denis Vlasenko | 19c238b | 2007-03-03 00:36:35 +0000 | [diff] [blame] | 472 | tsum += triptime; |
| 473 | if (triptime < tmin) |
| 474 | tmin = triptime; |
| 475 | if (triptime > tmax) |
| 476 | tmax = triptime; |
| 477 | } |
| 478 | |
| 479 | if (TST(recv_seq % MAX_DUP_CHK)) { |
| 480 | ++nrepeats; |
| 481 | --nreceived; |
| 482 | } else { |
| 483 | SET(recv_seq % MAX_DUP_CHK); |
| 484 | dupmsg += 7; |
| 485 | } |
| 486 | |
| 487 | if (option_mask32 & OPT_QUIET) |
| 488 | return; |
| 489 | |
| 490 | printf("%d bytes from %s: seq=%u ttl=%d", sz, |
| 491 | from_str, recv_seq, ttl); |
| 492 | if (tp) |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 493 | printf(" time=%u.%03u ms", triptime / 1000, triptime % 1000); |
Denis Vlasenko | 19c238b | 2007-03-03 00:36:35 +0000 | [diff] [blame] | 494 | puts(dupmsg); |
Denys Vlasenko | 8131eea | 2009-11-02 14:19:51 +0100 | [diff] [blame] | 495 | fflush_all(); |
Denis Vlasenko | 19c238b | 2007-03-03 00:36:35 +0000 | [diff] [blame] | 496 | } |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 497 | static void unpack4(char *buf, int sz, struct sockaddr_in *from) |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 498 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 499 | struct icmp *icmppkt; |
| 500 | struct iphdr *iphdr; |
Denis Vlasenko | 19c238b | 2007-03-03 00:36:35 +0000 | [diff] [blame] | 501 | int hlen; |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 502 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 503 | /* discard if too short */ |
Pavel Roskin | 0024abc | 2000-06-07 20:38:15 +0000 | [diff] [blame] | 504 | if (sz < (datalen + ICMP_MINLEN)) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 505 | return; |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 506 | |
Denis Vlasenko | 2cbe6e6 | 2006-09-02 16:17:30 +0000 | [diff] [blame] | 507 | /* check IP header */ |
| 508 | iphdr = (struct iphdr *) buf; |
| 509 | hlen = iphdr->ihl << 2; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 510 | sz -= hlen; |
| 511 | icmppkt = (struct icmp *) (buf + hlen); |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 512 | if (icmppkt->icmp_id != myid) |
Denis Vlasenko | cb6874c | 2006-09-02 16:13:36 +0000 | [diff] [blame] | 513 | return; /* not our ping */ |
Erik Andersen | 227a59b | 2000-04-25 23:24:55 +0000 | [diff] [blame] | 514 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 515 | if (icmppkt->icmp_type == ICMP_ECHOREPLY) { |
Denis Vlasenko | 35d4da0 | 2007-01-22 14:04:27 +0000 | [diff] [blame] | 516 | uint16_t recv_seq = ntohs(icmppkt->icmp_seq); |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 517 | uint32_t *tp = NULL; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 518 | |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 519 | if (sz >= ICMP_MINLEN + sizeof(uint32_t)) |
| 520 | tp = (uint32_t *) icmppkt->icmp_data; |
Denis Vlasenko | 19c238b | 2007-03-03 00:36:35 +0000 | [diff] [blame] | 521 | unpack_tail(sz, tp, |
| 522 | inet_ntoa(*(struct in_addr *) &from->sin_addr.s_addr), |
| 523 | recv_seq, iphdr->ttl); |
| 524 | } else if (icmppkt->icmp_type != ICMP_ECHO) { |
| 525 | bb_error_msg("warning: got ICMP %d (%s)", |
| 526 | icmppkt->icmp_type, |
| 527 | icmp_type_name(icmppkt->icmp_type)); |
Denis Vlasenko | 35d4da0 | 2007-01-22 14:04:27 +0000 | [diff] [blame] | 528 | } |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 529 | } |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 530 | #if ENABLE_PING6 |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 531 | static void unpack6(char *packet, int sz, /*struct sockaddr_in6 *from,*/ int hoplimit) |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 532 | { |
| 533 | struct icmp6_hdr *icmppkt; |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 534 | char buf[INET6_ADDRSTRLEN]; |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 535 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 536 | /* discard if too short */ |
| 537 | if (sz < (datalen + sizeof(struct icmp6_hdr))) |
| 538 | return; |
| 539 | |
| 540 | icmppkt = (struct icmp6_hdr *) packet; |
| 541 | if (icmppkt->icmp6_id != myid) |
| 542 | return; /* not our ping */ |
| 543 | |
| 544 | if (icmppkt->icmp6_type == ICMP6_ECHO_REPLY) { |
| 545 | uint16_t recv_seq = ntohs(icmppkt->icmp6_seq); |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 546 | uint32_t *tp = NULL; |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 547 | |
Denis Vlasenko | 7679145 | 2007-06-18 08:55:57 +0000 | [diff] [blame] | 548 | if (sz >= sizeof(struct icmp6_hdr) + sizeof(uint32_t)) |
| 549 | tp = (uint32_t *) &icmppkt->icmp6_data8[4]; |
Denis Vlasenko | 19c238b | 2007-03-03 00:36:35 +0000 | [diff] [blame] | 550 | unpack_tail(sz, tp, |
| 551 | inet_ntop(AF_INET6, &pingaddr.sin6.sin6_addr, |
| 552 | buf, sizeof(buf)), |
| 553 | recv_seq, hoplimit); |
| 554 | } else if (icmppkt->icmp6_type != ICMP6_ECHO_REQUEST) { |
| 555 | bb_error_msg("warning: got ICMP %d (%s)", |
| 556 | icmppkt->icmp6_type, |
| 557 | icmp6_type_name(icmppkt->icmp6_type)); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 558 | } |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 559 | } |
| 560 | #endif |
| 561 | |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 562 | static void ping4(len_and_sockaddr *lsa) |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 563 | { |
Pavel Roskin | 0024abc | 2000-06-07 20:38:15 +0000 | [diff] [blame] | 564 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 565 | int sockopt; |
| 566 | |
Matt Kraai | 06ef165 | 2001-07-13 20:56:27 +0000 | [diff] [blame] | 567 | pingsock = create_icmp_socket(); |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 568 | pingaddr.sin = lsa->u.sin; |
Denis Vlasenko | 5ad1048 | 2007-06-19 22:54:21 +0000 | [diff] [blame] | 569 | if (source_lsa) { |
| 570 | if (setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_IF, |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 571 | &source_lsa->u.sa, source_lsa->len)) |
Denis Vlasenko | 5ad1048 | 2007-06-19 22:54:21 +0000 | [diff] [blame] | 572 | bb_error_msg_and_die("can't set multicast source interface"); |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 573 | xbind(pingsock, &source_lsa->u.sa, source_lsa->len); |
Denis Vlasenko | 5ad1048 | 2007-06-19 22:54:21 +0000 | [diff] [blame] | 574 | } |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 575 | if (str_I) |
Denis Vlasenko | e537385 | 2008-12-10 11:12:16 +0000 | [diff] [blame] | 576 | setsockopt_bindtodevice(pingsock, str_I); |
Denis Vlasenko | 2cbe6e6 | 2006-09-02 16:17:30 +0000 | [diff] [blame] | 577 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 578 | /* enable broadcast pings */ |
Denis Vlasenko | 48237b0 | 2006-11-22 23:22:06 +0000 | [diff] [blame] | 579 | setsockopt_broadcast(pingsock); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 580 | |
Denis Vlasenko | 5770715 | 2008-08-24 00:02:18 +0000 | [diff] [blame] | 581 | /* set recv buf (needed if we can get lots of responses: flood ping, |
| 582 | * broadcast ping etc) */ |
| 583 | sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */ |
Denis Vlasenko | 703e202 | 2007-01-22 14:12:08 +0000 | [diff] [blame] | 584 | setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 585 | |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 586 | signal(SIGINT, print_stats_and_exit); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 587 | |
| 588 | /* start the ping's going ... */ |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 589 | sendping4(0); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 590 | |
| 591 | /* listen for replies */ |
| 592 | while (1) { |
| 593 | struct sockaddr_in from; |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 594 | socklen_t fromlen = (socklen_t) sizeof(from); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 595 | int c; |
| 596 | |
Denis Vlasenko | 44c2eb2 | 2007-01-08 23:55:33 +0000 | [diff] [blame] | 597 | c = recvfrom(pingsock, packet, sizeof(packet), 0, |
| 598 | (struct sockaddr *) &from, &fromlen); |
| 599 | if (c < 0) { |
| 600 | if (errno != EINTR) |
| 601 | bb_perror_msg("recvfrom"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 602 | continue; |
| 603 | } |
Denis Vlasenko | e935602 | 2007-01-29 18:03:54 +0000 | [diff] [blame] | 604 | unpack4(packet, c, &from); |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 605 | if (pingcount && nreceived >= pingcount) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 606 | break; |
| 607 | } |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 608 | } |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 609 | #if ENABLE_PING6 |
| 610 | extern int BUG_bad_offsetof_icmp6_cksum(void); |
| 611 | static void ping6(len_and_sockaddr *lsa) |
| 612 | { |
| 613 | char packet[datalen + MAXIPLEN + MAXICMPLEN]; |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 614 | int sockopt; |
| 615 | struct msghdr msg; |
| 616 | struct sockaddr_in6 from; |
| 617 | struct iovec iov; |
| 618 | char control_buf[CMSG_SPACE(36)]; |
| 619 | |
| 620 | pingsock = create_icmp6_socket(); |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 621 | pingaddr.sin6 = lsa->u.sin6; |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 622 | /* untested whether "-I addr" really works for IPv6: */ |
| 623 | if (source_lsa) |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 624 | xbind(pingsock, &source_lsa->u.sa, source_lsa->len); |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 625 | if (str_I) |
Denis Vlasenko | e537385 | 2008-12-10 11:12:16 +0000 | [diff] [blame] | 626 | setsockopt_bindtodevice(pingsock, str_I); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 627 | |
| 628 | #ifdef ICMP6_FILTER |
| 629 | { |
| 630 | struct icmp6_filter filt; |
| 631 | if (!(option_mask32 & OPT_VERBOSE)) { |
| 632 | ICMP6_FILTER_SETBLOCKALL(&filt); |
| 633 | ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filt); |
| 634 | } else { |
| 635 | ICMP6_FILTER_SETPASSALL(&filt); |
| 636 | } |
| 637 | if (setsockopt(pingsock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, |
| 638 | sizeof(filt)) < 0) |
| 639 | bb_error_msg_and_die("setsockopt(ICMP6_FILTER)"); |
| 640 | } |
| 641 | #endif /*ICMP6_FILTER*/ |
| 642 | |
| 643 | /* enable broadcast pings */ |
| 644 | setsockopt_broadcast(pingsock); |
| 645 | |
Denis Vlasenko | 5770715 | 2008-08-24 00:02:18 +0000 | [diff] [blame] | 646 | /* set recv buf (needed if we can get lots of responses: flood ping, |
| 647 | * broadcast ping etc) */ |
| 648 | sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */ |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 649 | setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt)); |
| 650 | |
| 651 | sockopt = offsetof(struct icmp6_hdr, icmp6_cksum); |
| 652 | if (offsetof(struct icmp6_hdr, icmp6_cksum) != 2) |
| 653 | BUG_bad_offsetof_icmp6_cksum(); |
| 654 | setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, &sockopt, sizeof(sockopt)); |
| 655 | |
| 656 | /* request ttl info to be returned in ancillary data */ |
| 657 | setsockopt(pingsock, SOL_IPV6, IPV6_HOPLIMIT, &const_int_1, sizeof(const_int_1)); |
| 658 | |
| 659 | if (if_index) |
Denis Vlasenko | aeb4bdd | 2007-01-25 00:00:02 +0000 | [diff] [blame] | 660 | pingaddr.sin6.sin6_scope_id = if_index; |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 661 | |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 662 | signal(SIGINT, print_stats_and_exit); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 663 | |
| 664 | /* start the ping's going ... */ |
| 665 | sendping6(0); |
| 666 | |
| 667 | /* listen for replies */ |
| 668 | msg.msg_name = &from; |
| 669 | msg.msg_namelen = sizeof(from); |
| 670 | msg.msg_iov = &iov; |
| 671 | msg.msg_iovlen = 1; |
| 672 | msg.msg_control = control_buf; |
| 673 | iov.iov_base = packet; |
| 674 | iov.iov_len = sizeof(packet); |
| 675 | while (1) { |
| 676 | int c; |
| 677 | struct cmsghdr *mp; |
| 678 | int hoplimit = -1; |
| 679 | msg.msg_controllen = sizeof(control_buf); |
| 680 | |
| 681 | c = recvmsg(pingsock, &msg, 0); |
| 682 | if (c < 0) { |
| 683 | if (errno != EINTR) |
| 684 | bb_perror_msg("recvfrom"); |
| 685 | continue; |
| 686 | } |
| 687 | for (mp = CMSG_FIRSTHDR(&msg); mp; mp = CMSG_NXTHDR(&msg, mp)) { |
| 688 | if (mp->cmsg_level == SOL_IPV6 |
| 689 | && mp->cmsg_type == IPV6_HOPLIMIT |
| 690 | /* don't check len - we trust the kernel: */ |
| 691 | /* && mp->cmsg_len >= CMSG_LEN(sizeof(int)) */ |
| 692 | ) { |
| 693 | hoplimit = *(int*)CMSG_DATA(mp); |
| 694 | } |
| 695 | } |
Denis Vlasenko | 68404f1 | 2008-03-17 09:00:54 +0000 | [diff] [blame] | 696 | unpack6(packet, c, /*&from,*/ hoplimit); |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 697 | if (pingcount && nreceived >= pingcount) |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 698 | break; |
| 699 | } |
| 700 | } |
| 701 | #endif |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 702 | |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 703 | static void ping(len_and_sockaddr *lsa) |
Denis Vlasenko | 2cbe6e6 | 2006-09-02 16:17:30 +0000 | [diff] [blame] | 704 | { |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 705 | printf("PING %s (%s)", hostname, dotted); |
| 706 | if (source_lsa) { |
| 707 | printf(" from %s", |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 708 | xmalloc_sockaddr2dotted_noport(&source_lsa->u.sa)); |
Denis Vlasenko | 2cbe6e6 | 2006-09-02 16:17:30 +0000 | [diff] [blame] | 709 | } |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 710 | printf(": %d data bytes\n", datalen); |
| 711 | |
| 712 | #if ENABLE_PING6 |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 713 | if (lsa->u.sa.sa_family == AF_INET6) |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 714 | ping6(lsa); |
| 715 | else |
| 716 | #endif |
| 717 | ping4(lsa); |
Denis Vlasenko | 2cbe6e6 | 2006-09-02 16:17:30 +0000 | [diff] [blame] | 718 | } |
| 719 | |
Denys Vlasenko | ad7d94b | 2009-11-20 18:12:12 +0100 | [diff] [blame] | 720 | static int common_ping_main(int opt, char **argv) |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 721 | { |
Denis Vlasenko | aeb4bdd | 2007-01-25 00:00:02 +0000 | [diff] [blame] | 722 | len_and_sockaddr *lsa; |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 723 | char *str_s; |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 724 | |
Denis Vlasenko | 821cc25 | 2007-06-04 10:33:48 +0000 | [diff] [blame] | 725 | INIT_G(); |
| 726 | |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 727 | /* exactly one argument needed; -v and -q don't mix; -c NUM, -w NUM, -W NUM */ |
| 728 | opt_complementary = "=1:q--v:v--q:c+:w+:W+"; |
Denys Vlasenko | 85164fa | 2009-11-21 15:44:56 +0100 | [diff] [blame^] | 729 | opt |= getopt32(argv, OPT_STRING, &pingcount, &str_s, &deadline, &timeout, &str_I); |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 730 | if (opt & OPT_s) |
| 731 | datalen = xatou16(str_s); // -s |
| 732 | if (opt & OPT_I) { // -I |
| 733 | if_index = if_nametoindex(str_I); |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 734 | if (!if_index) { |
| 735 | /* TODO: I'm not sure it takes IPv6 unless in [XX:XX..] format */ |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 736 | source_lsa = xdotted2sockaddr(str_I, 0); |
| 737 | str_I = NULL; /* don't try to bind to device later */ |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 738 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 739 | } |
Denis Vlasenko | 1c9ad62 | 2007-05-27 00:53:41 +0000 | [diff] [blame] | 740 | myid = (uint16_t) getpid(); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 741 | hostname = argv[optind]; |
| 742 | #if ENABLE_PING6 |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 743 | { |
| 744 | sa_family_t af = AF_UNSPEC; |
| 745 | if (opt & OPT_IPV4) |
| 746 | af = AF_INET; |
| 747 | if (opt & OPT_IPV6) |
| 748 | af = AF_INET6; |
| 749 | lsa = xhost_and_af2sockaddr(hostname, 0, af); |
| 750 | } |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 751 | #else |
Denis Vlasenko | 42823d5 | 2007-02-04 02:39:08 +0000 | [diff] [blame] | 752 | lsa = xhost_and_af2sockaddr(hostname, 0, AF_INET); |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 753 | #endif |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 754 | |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 755 | if (source_lsa && source_lsa->u.sa.sa_family != lsa->u.sa.sa_family) |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 756 | /* leaking it here... */ |
| 757 | source_lsa = NULL; |
| 758 | |
Bernhard Reutner-Fischer | 8c69afd | 2008-01-29 10:33:34 +0000 | [diff] [blame] | 759 | dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); |
Denis Vlasenko | 9ca26d3 | 2007-02-09 17:32:16 +0000 | [diff] [blame] | 760 | ping(lsa); |
Bernhard Reutner-Fischer | 636a1f8 | 2008-05-19 09:29:47 +0000 | [diff] [blame] | 761 | print_stats_and_exit(EXIT_SUCCESS); |
Denis Vlasenko | 90c31b3 | 2008-04-07 00:46:29 +0000 | [diff] [blame] | 762 | /*return EXIT_SUCCESS;*/ |
Eric Andersen | 485b955 | 1999-12-07 23:14:59 +0000 | [diff] [blame] | 763 | } |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 764 | #endif /* FEATURE_FANCY_PING */ |
| 765 | |
| 766 | |
Denys Vlasenko | ad7d94b | 2009-11-20 18:12:12 +0100 | [diff] [blame] | 767 | int ping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 768 | int ping_main(int argc UNUSED_PARAM, char **argv) |
| 769 | { |
| 770 | #if !ENABLE_FEATURE_FANCY_PING |
| 771 | return common_ping_main(AF_UNSPEC, argv); |
| 772 | #else |
| 773 | return common_ping_main(0, argv); |
| 774 | #endif |
| 775 | } |
| 776 | |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 777 | #if ENABLE_PING6 |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 778 | int ping6_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | 59f502b | 2008-10-27 11:54:45 +0000 | [diff] [blame] | 779 | int ping6_main(int argc UNUSED_PARAM, char **argv) |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 780 | { |
Denys Vlasenko | ad7d94b | 2009-11-20 18:12:12 +0100 | [diff] [blame] | 781 | # if !ENABLE_FEATURE_FANCY_PING |
| 782 | return common_ping_main(AF_INET6, argv); |
| 783 | # else |
| 784 | return common_ping_main(OPT_IPV6, argv); |
| 785 | # endif |
Denis Vlasenko | b9a279b | 2007-01-24 23:53:22 +0000 | [diff] [blame] | 786 | } |
| 787 | #endif |
| 788 | |
| 789 | /* from ping6.c: |
| 790 | * Copyright (c) 1989 The Regents of the University of California. |
| 791 | * All rights reserved. |
| 792 | * |
| 793 | * This code is derived from software contributed to Berkeley by |
| 794 | * Mike Muuss. |
| 795 | * |
| 796 | * Redistribution and use in source and binary forms, with or without |
| 797 | * modification, are permitted provided that the following conditions |
| 798 | * are met: |
| 799 | * 1. Redistributions of source code must retain the above copyright |
| 800 | * notice, this list of conditions and the following disclaimer. |
| 801 | * 2. Redistributions in binary form must reproduce the above copyright |
| 802 | * notice, this list of conditions and the following disclaimer in the |
| 803 | * documentation and/or other materials provided with the distribution. |
| 804 | * |
| 805 | * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change |
| 806 | * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> |
| 807 | * |
| 808 | * 4. Neither the name of the University nor the names of its contributors |
| 809 | * may be used to endorse or promote products derived from this software |
| 810 | * without specific prior written permission. |
| 811 | * |
| 812 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 813 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 814 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 815 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 816 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 817 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 818 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 819 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 820 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 821 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 822 | * SUCH DAMAGE. |
| 823 | */ |