diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-11-06 16:20:21 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2013-11-11 10:08:08 +0100 |
commit | 66659ff1ad6831b0ea7425fa6ecd8a8687523658 (patch) | |
tree | 48e22b475fa8854128e0861a33fed6f78c8094b5 /freebsd/sbin/ping6/ping6.c | |
parent | Define __GLOBL1() and __GLOBL() (diff) | |
download | rtems-libbsd-66659ff1ad6831b0ea7425fa6ecd8a8687523658.tar.bz2 |
Update to FreeBSD 9.2
Diffstat (limited to 'freebsd/sbin/ping6/ping6.c')
-rw-r--r-- | freebsd/sbin/ping6/ping6.c | 184 |
1 files changed, 92 insertions, 92 deletions
diff --git a/freebsd/sbin/ping6/ping6.c b/freebsd/sbin/ping6/ping6.c index b927f110..b2ad6336 100644 --- a/freebsd/sbin/ping6/ping6.c +++ b/freebsd/sbin/ping6/ping6.c @@ -48,10 +48,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. * 4. 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. @@ -79,10 +75,11 @@ static const char copyright[] = #if 0 static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93"; #endif -static const char rcsid[] = - "$FreeBSD$"; #endif /* not lint */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + /* * Using the InterNet Control Message Protocol (ICMP) "ECHO" facility, * measure round-trip-delays and packet loss across network paths. @@ -235,6 +232,13 @@ static char *hostname; static int ident; /* process id to identify our packets */ static u_int8_t nonce[8]; /* nonce field for node information */ static int hoplimit; /* hoplimit */ +static u_char *packet; +#ifdef HAVE_POLL_H +static struct pollfd fdmaskp[1]; +#else +static fd_set *fdmaskp = NULL; +static int fdmasks; +#endif /* counters */ static long nmissedmax; /* max value of ntransmitted - nreceived - 1 */ @@ -265,8 +269,8 @@ static volatile sig_atomic_t seenint; static volatile sig_atomic_t seeninfo; #endif -static u_char *packet; -static struct cmsghdr *cm; +/* For control (ancillary) data received from recvmsg() */ +static struct cmsghdr cm[CONTROLLEN]; static int main(int, char *[]); static void fill(char *, char *); @@ -300,7 +304,7 @@ static void tvsub(struct timeval *, struct timeval *); static int setpolicy(int, char *); #endif #endif -static char *nigroup(char *); +static char *nigroup(char *, int); static void usage(void); #ifdef __rtems__ @@ -336,9 +340,7 @@ int rtems_bsd_command_ping6(int argc, char **argv) #ifdef SIGINFO seeninfo = 0; #endif - packet = NULL; - cm = NULL; exit_code = rtems_bsd_program_call_main("ping6", main, argc, argv); @@ -352,15 +354,11 @@ int rtems_bsd_command_ping6(int argc, char **argv) freeaddrinfo(res); } - free(cm); - return exit_code; } #endif /* __rtems__ */ int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { struct itimerval itimer; struct sockaddr_in6 from; @@ -373,14 +371,9 @@ main(argc, argv) struct timeval timeout, *tv; #endif struct addrinfo hints; -#ifdef HAVE_POLL_H - struct pollfd fdmaskp[1]; -#else - fd_set *fdmaskp; - int fdmasks; -#endif int cc, i; int ch, hold, packlen, preload, optval, ret_ga; + int nig_oldmcprefix = -1; u_char *datap; char *e, *target, *ifname = NULL, *gateway = NULL; int ip6optlen = 0; @@ -572,6 +565,7 @@ main(argc, argv) break; case 'N': options |= F_NIGROUP; + nig_oldmcprefix++; break; case 'o': options |= F_ONCE; @@ -687,7 +681,7 @@ main(argc, argv) } if (options & F_NIGROUP) { - target = nigroup(argv[argc - 1]); + target = nigroup(argv[argc - 1], nig_oldmcprefix); if (target == NULL) { usage(); /*NOTREACHED*/ @@ -1164,11 +1158,6 @@ main(argc, argv) seeninfo = 0; #endif - /* For control (ancillary) data received from recvmsg() */ - cm = (struct cmsghdr *)malloc(CONTROLLEN); - if (cm == NULL) - err(1, "malloc"); - for (;;) { struct msghdr m; struct iovec iov[2]; @@ -1282,12 +1271,27 @@ main(argc, argv) } } summary(); + + if (res != NULL) { + freeaddrinfo(res); + res = NULL; + } + + if(packet != NULL) { + free(packet); + packet = NULL; + } + +#ifndef HAVE_POLL_H + if(fdmaskp != NULL) + free(fdmaskp); +#endif + exit(nreceived == 0 ? 2 : 0); } void -onsignal(sig) - int sig; +onsignal(int sig) { switch (sig) { @@ -1310,7 +1314,7 @@ onsignal(sig) * This routine transmits another ping6. */ void -retransmit() +retransmit(void) { struct itimerval itimer; @@ -1346,7 +1350,7 @@ retransmit() * byte-order, to compute the round-trip time. */ size_t -pingerlen() +pingerlen(void) { size_t l; @@ -1365,7 +1369,7 @@ pingerlen() } int -pinger() +pinger(void) { struct icmp6_hdr *icp; struct iovec iov[2]; @@ -1480,8 +1484,7 @@ pinger() } int -myechoreply(icp) - const struct icmp6_hdr *icp; +myechoreply(const struct icmp6_hdr *icp) { if (ntohs(icp->icmp6_id) == ident) return 1; @@ -1490,8 +1493,7 @@ myechoreply(icp) } int -mynireply(nip) - const struct icmp6_nodeinfo *nip; +mynireply(const struct icmp6_nodeinfo *nip) { if (memcmp(nip->icmp6_ni_nonce + sizeof(u_int16_t), nonce + sizeof(u_int16_t), @@ -1502,12 +1504,9 @@ mynireply(nip) } char * -dnsdecode(sp, ep, base, buf, bufsiz) - const u_char **sp; - const u_char *ep; - const u_char *base; /*base for compressed name*/ - char *buf; - size_t bufsiz; +dnsdecode(const u_char **sp, const u_char *ep, const u_char *base, char *buf, + size_t bufsiz) + /*base for compressed name*/ { int i; const u_char *cp; @@ -1572,10 +1571,7 @@ dnsdecode(sp, ep, base, buf, bufsiz) * program to be run without having intermingled output (or statistics!). */ void -pr_pack(buf, cc, mhdr) - u_char *buf; - int cc; - struct msghdr *mhdr; +pr_pack(u_char *buf, int cc, struct msghdr *mhdr) { #define safeputc(c) printf((isprint((c)) ? "%c" : "\\%03o"), c) struct icmp6_hdr *icp; @@ -1856,8 +1852,7 @@ pr_pack(buf, cc, mhdr) } void -pr_exthdrs(mhdr) - struct msghdr *mhdr; +pr_exthdrs(struct msghdr *mhdr) { ssize_t bufsize; void *bufp; @@ -2032,10 +2027,7 @@ pr_rthdr(void *extbuf, size_t bufsize __unused) #endif /* USE_RFC2292BIS */ int -pr_bitrange(v, soff, ii) - u_int32_t v; - int soff; - int ii; +pr_bitrange(u_int32_t v, int soff, int ii) { int off; int i; @@ -2081,9 +2073,8 @@ pr_bitrange(v, soff, ii) } void -pr_suptypes(ni, nilen) - struct icmp6_nodeinfo *ni; /* ni->qtype must be SUPTYPES */ - size_t nilen; +pr_suptypes(struct icmp6_nodeinfo *ni, size_t nilen) + /* ni->qtype must be SUPTYPES */ { size_t clen; u_int32_t v; @@ -2148,9 +2139,8 @@ pr_suptypes(ni, nilen) } void -pr_nodeaddr(ni, nilen) - struct icmp6_nodeinfo *ni; /* ni->qtype must be NODEADDR */ - int nilen; +pr_nodeaddr(struct icmp6_nodeinfo *ni, int nilen) + /* ni->qtype must be NODEADDR */ { u_char *cp = (u_char *)(ni + 1); char ntop_buf[INET6_ADDRSTRLEN]; @@ -2215,8 +2205,7 @@ pr_nodeaddr(ni, nilen) } int -get_hoplim(mhdr) - struct msghdr *mhdr; +get_hoplim(struct msghdr *mhdr) { struct cmsghdr *cm; @@ -2235,8 +2224,7 @@ get_hoplim(mhdr) } struct in6_pktinfo * -get_rcvpktinfo(mhdr) - struct msghdr *mhdr; +get_rcvpktinfo(struct msghdr *mhdr) { struct cmsghdr *cm; @@ -2255,8 +2243,7 @@ get_rcvpktinfo(mhdr) } int -get_pathmtu(mhdr) - struct msghdr *mhdr; +get_pathmtu(struct msghdr *mhdr) { #ifdef IPV6_RECVPATHMTU struct cmsghdr *cm; @@ -2316,8 +2303,7 @@ get_pathmtu(mhdr) * be >= in. */ void -tvsub(out, in) - struct timeval *out, *in; +tvsub(struct timeval *out, struct timeval *in) { if ((out->tv_usec -= in->tv_usec) < 0) { --out->tv_sec; @@ -2332,11 +2318,21 @@ tvsub(out, in) */ /* ARGSUSED */ void -onint(notused) - int notused; +onint(int notused __unused) { summary(); + if (res != NULL) + freeaddrinfo(res); + + if(packet != NULL) + free(packet); + +#ifndef HAVE_POLL_H + if(fdmaskp != NULL) + free(fdmaskp); +#endif + (void)signal(SIGINT, SIG_DFL); (void)kill(getpid(), SIGINT); @@ -2349,7 +2345,7 @@ onint(notused) * Print out statistics. */ void -summary() +summary(void) { (void)printf("\n--- %s ping6 statistics ---\n", hostname); @@ -2397,9 +2393,7 @@ static const char *nircode[] = { * Print a descriptive string about an ICMP header. */ void -pr_icmph(icp, end) - struct icmp6_hdr *icp; - u_char *end; +pr_icmph(struct icmp6_hdr *icp, u_char *end) { char ntop_buf[INET6_ADDRSTRLEN]; struct nd_redirect *red; @@ -2629,8 +2623,7 @@ pr_icmph(icp, end) * Print an IP6 header. */ void -pr_iph(ip6) - struct ip6_hdr *ip6; +pr_iph(struct ip6_hdr *ip6) { u_int32_t flow = ip6->ip6_flow & IPV6_FLOWLABEL_MASK; u_int8_t tc; @@ -2658,9 +2651,7 @@ pr_iph(ip6) * a hostname. */ const char * -pr_addr(addr, addrlen) - struct sockaddr *addr; - int addrlen; +pr_addr(struct sockaddr *addr, int addrlen) { static char buf[NI_MAXHOST]; int flag = 0; @@ -2679,9 +2670,7 @@ pr_addr(addr, addrlen) * Dump some info on a returned (via ICMPv6) IPv6 packet. */ void -pr_retip(ip6, end) - struct ip6_hdr *ip6; - u_char *end; +pr_retip(struct ip6_hdr *ip6, u_char *end) { u_char *cp = (u_char *)ip6, nh; int hlen; @@ -2761,8 +2750,7 @@ pr_retip(ip6, end) } void -fill(bp, patp) - char *bp, *patp; +fill(char *bp, char *patp) { int ii, jj, kk; int pat[16]; @@ -2795,9 +2783,7 @@ fill(bp, patp) #ifdef IPSEC #ifdef IPSEC_POLICY_IPSEC int -setpolicy(so, policy) - int so; - char *policy; +setpolicy(int so __unused, char *policy) { char *buf; @@ -2818,8 +2804,7 @@ setpolicy(so, policy) #endif char * -nigroup(name) - char *name; +nigroup(char *name, int nig_oldmcprefix) { char *p; char *q; @@ -2829,6 +2814,7 @@ nigroup(name) size_t l; char hbuf[NI_MAXHOST]; struct in6_addr in6; + int valid; p = strchr(name, '.'); if (!p) @@ -2844,7 +2830,7 @@ nigroup(name) *q = tolower(*(unsigned char *)q); } - /* generate 8 bytes of pseudo-random value. */ + /* generate 16 bytes of pseudo-random value. */ memset(&ctxt, 0, sizeof(ctxt)); MD5Init(&ctxt); c = l & 0xff; @@ -2852,9 +2838,23 @@ nigroup(name) MD5Update(&ctxt, (unsigned char *)name, l); MD5Final(digest, &ctxt); - if (inet_pton(AF_INET6, "ff02::2:0000:0000", &in6) != 1) + if (nig_oldmcprefix) { + /* draft-ietf-ipngwg-icmp-name-lookup */ + valid = inet_pton(AF_INET6, "ff02::2:0000:0000", &in6); + } else { + /* RFC 4620 */ + valid = inet_pton(AF_INET6, "ff02::2:ff00:0000", &in6); + } + if (valid != 1) return NULL; /*XXX*/ - bcopy(digest, &in6.s6_addr[12], 4); + + if (nig_oldmcprefix) { + /* draft-ietf-ipngwg-icmp-name-lookup */ + bcopy(digest, &in6.s6_addr[12], 4); + } else { + /* RFC 4620 */ + bcopy(digest, &in6.s6_addr[13], 3); + } if (inet_ntop(AF_INET6, &in6, hbuf, sizeof(hbuf)) == NULL) return NULL; @@ -2863,7 +2863,7 @@ nigroup(name) } void -usage() +usage(void) { (void)fprintf(stderr, #if defined(IPSEC) && !defined(IPSEC_POLICY_IPSEC) |