X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=networking%2Fping6.c;h=767aafd2a91b76eb1b791d0e7def276e6005cc8d;hb=59fe8b90890a07c87ec9c2943bae515d5c6d959d;hp=72867f346a4e7fd022652ec2bbe082194ae14b41;hpb=c7bda1ce659294d6e22c06e087f6f265983c7578;p=oweals%2Fbusybox.git diff --git a/networking/ping6.c b/networking/ping6.c index 72867f346..767aafd2a 100644 --- a/networking/ping6.c +++ b/networking/ping6.c @@ -5,19 +5,7 @@ * * Copyright (C) 1999 by Randolph Chung * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. * * This version of ping is adapted from the ping in netkit-base 0.10, * which is: @@ -37,9 +25,8 @@ #include #include #include -#include #include -#include +#include #include #include @@ -56,13 +43,15 @@ #include /* offsetof */ #include "busybox.h" -static const int DEFDATALEN = 56; -static const int MAXIPLEN = 60; -static const int MAXICMPLEN = 76; -static const int MAXPACKET = 65468; -#define MAX_DUP_CHK (8 * 128) -static const int MAXWAIT = 10; -static const int PINGINTERVAL = 1; /* second */ +enum { + DEFDATALEN = 56, + MAXIPLEN = 60, + MAXICMPLEN = 76, + MAXPACKET = 65468, + MAX_DUP_CHK = (8 * 128), + MAXWAIT = 10, + PINGINTERVAL = 1 /* second */ +}; #define O_QUIET (1 << 0) #define O_VERBOSE (1 << 1) @@ -109,7 +98,7 @@ static void ping(const char *host) setsockopt(pingsock, SOL_RAW, IPV6_CHECKSUM, (char *) &sockopt, sizeof(sockopt)); - c = sendto(pingsock, packet, sizeof(packet), 0, + c = sendto(pingsock, packet, DEFDATALEN + sizeof (struct icmp6_hdr), 0, (struct sockaddr *) &pingaddr, sizeof(struct sockaddr_in6)); if (c < 0 || c != sizeof(packet)) @@ -139,7 +128,7 @@ static void ping(const char *host) return; } -extern int ping6_main(int argc, char **argv) +int ping6_main(int argc, char **argv) { argc--; argv++; @@ -202,7 +191,7 @@ static void sendping(int junk) { struct icmp6_hdr *pkt; int i; - char packet[datalen + 8]; + char packet[datalen + sizeof (struct icmp6_hdr)]; pkt = (struct icmp6_hdr *) packet; @@ -234,6 +223,17 @@ static void sendping(int junk) } } +/* RFC3542 changed some definitions from RFC2292 for no good reason, whee ! + * the newer 3542 uses a MLD_ prefix where as 2292 uses ICMP6_ prefix */ +#ifndef MLD_LISTENER_QUERY +# define MLD_LISTENER_QUERY ICMP6_MEMBERSHIP_QUERY +#endif +#ifndef MLD_LISTENER_REPORT +# define MLD_LISTENER_REPORT ICMP6_MEMBERSHIP_REPORT +#endif +#ifndef MLD_LISTENER_REDUCTION +# define MLD_LISTENER_REDUCTION ICMP6_MEMBERSHIP_REDUCTION +#endif static char *icmp6_type_name (int id) { switch (id) { @@ -243,10 +243,10 @@ static char *icmp6_type_name (int id) case ICMP6_PARAM_PROB: return "Parameter Problem"; case ICMP6_ECHO_REPLY: return "Echo Reply"; case ICMP6_ECHO_REQUEST: return "Echo Request"; - case ICMP6_MEMBERSHIP_QUERY: return "Membership Query"; - case ICMP6_MEMBERSHIP_REPORT: return "Membership Report"; - case ICMP6_MEMBERSHIP_REDUCTION: return "Membership Reduction"; - default: return "unknown ICMP type"; + case MLD_LISTENER_QUERY: return "Listener Query"; + case MLD_LISTENER_REPORT: return "Listener Report"; + case MLD_LISTENER_REDUCTION: return "Listener Reduction"; + default: return "unknown ICMP type"; } } @@ -299,7 +299,7 @@ static void unpack(char *packet, int sz, struct sockaddr_in6 *from, int hoplimit return; printf("%d bytes from %s: icmp6_seq=%u", sz, - inet_ntop(AF_INET6, (struct in_addr6 *) &pingaddr.sin6_addr, + inet_ntop(AF_INET6, &pingaddr.sin6_addr, buf, sizeof(buf)), icmppkt->icmp6_seq); printf(" ttl=%d time=%lu.%lu ms", hoplimit, @@ -339,12 +339,6 @@ static void ping(const char *host) struct icmp6_filter filt; if (!(options & O_VERBOSE)) { ICMP6_FILTER_SETBLOCKALL(&filt); -#if 0 - if ((options & F_FQDN) || (options & F_FQDNOLD) || - (options & F_NODEADDR) || (options & F_SUPTYPES)) - ICMP6_FILTER_SETPASS(ICMP6_NI_REPLY, &filt); - else -#endif ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filt); } else { ICMP6_FILTER_SETPASSALL(&filt); @@ -380,7 +374,7 @@ static void ping(const char *host) printf("PING %s (%s): %d data bytes\n", hostent->h_name, - inet_ntop(AF_INET6, (struct in_addr6 *) &pingaddr.sin6_addr, + inet_ntop(AF_INET6, &pingaddr.sin6_addr, buf, sizeof(buf)), datalen); @@ -423,7 +417,7 @@ static void ping(const char *host) pingstats(0); } -extern int ping6_main(int argc, char **argv) +int ping6_main(int argc, char **argv) { char *thisarg;