diff options
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ping6/ping6.c | 88 |
1 files changed, 49 insertions, 39 deletions
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index a7508893c23..da0290eab72 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,5 +1,5 @@ -/* $OpenBSD: ping6.c,v 1.27 2001/01/26 12:16:49 itojun Exp $ */ -/* $KAME: ping6.c,v 1.115 2001/01/26 09:01:23 itojun Exp $ */ +/* $OpenBSD: ping6.c,v 1.28 2001/02/04 00:37:21 itojun Exp $ */ +/* $KAME: ping6.c,v 1.121 2001/02/01 16:43:01 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -245,7 +245,9 @@ char *scmsg = 0; volatile int signo; volatile sig_atomic_t seenalrm; volatile sig_atomic_t seenint; +#ifdef SIGINFO volatile sig_atomic_t seeninfo; +#endif int main __P((int, char *[])); void fill __P((char *, char *)); @@ -253,10 +255,9 @@ int get_hoplim __P((struct msghdr *)); struct in6_pktinfo *get_rcvpktinfo __P((struct msghdr *)); void onsignal __P((int)); void retransmit __P((void)); -void oninfo __P((int)); void onint __P((int)); void pinger __P((void)); -const char *pr_addr __P((struct sockaddr_in6 *)); +const char *pr_addr __P((struct sockaddr *, int)); void pr_icmph __P((struct icmp6_hdr *, u_char *)); void pr_iph __P((struct ip6_hdr *)); void pr_suptypes __P((struct icmp6_nodeinfo *, size_t)); @@ -354,8 +355,14 @@ main(argc, argv) naflags |= NI_NODEADDR_FLAG_GLOBAL; break; case 'A': /* experimental. not in the spec */ +#ifdef NI_NODEADDR_FLAG_ANYCAST naflags |= NI_NODEADDR_FLAG_ANYCAST; break; +#else + errx(1, +"-a A is not supported on the platform"); + /*NOTREACHED*/ +#endif default: usage(); /*NOTREACHED*/ @@ -954,8 +961,8 @@ main(argc, argv) #endif printf("PING6(%d=40+8+%d bytes) ", datalen + 48, datalen); - printf("%s --> ", pr_addr(&src)); - printf("%s\n", pr_addr(&dst)); + printf("%s --> ", pr_addr((struct sockaddr *)&src, sizeof(src))); + printf("%s\n", pr_addr((struct sockaddr *)&dst, sizeof(dst))); while (preload--) /* Fire off them quickies. */ pinger(); @@ -977,7 +984,10 @@ main(argc, argv) if ((fdmaskp = malloc(fdmasks)) == NULL) err(1, "malloc"); - signo = seenalrm = seenint = seeninfo = 0; + signo = seenalrm = seenint = 0; +#ifdef SIGINFO + seeninfo = 0; +#endif for (;;) { struct msghdr m; @@ -996,11 +1006,13 @@ main(argc, argv) seenint = 0; continue; } +#ifdef SIGINFO if (seeninfo) { - oninfo(SIGINFO); + summary(); seeninfo = 0; continue; } +#endif if (options & F_FLOOD) { pinger(); @@ -1064,9 +1076,11 @@ onsignal(sig) case SIGINT: seenint++; break; +#ifdef SIGINFO case SIGINFO: seeninfo++; break; +#endif } } @@ -1315,7 +1329,8 @@ pr_pack(buf, cc, mhdr) struct icmp6_nodeinfo *ni; int i; int hoplim; - struct sockaddr_in6 *from; + struct sockaddr *from; + int fromlen; u_char *cp = NULL, *dp, *end = buf + cc; struct in6_pktinfo *pktinfo = NULL; struct timeval tv, *tp; @@ -1328,17 +1343,19 @@ pr_pack(buf, cc, mhdr) (void)gettimeofday(&tv, NULL); - if (!mhdr || !mhdr->msg_name || mhdr->msg_namelen != sizeof(*from) || + if (!mhdr || !mhdr->msg_name || + mhdr->msg_namelen != sizeof(struct sockaddr_in6) || ((struct sockaddr *)mhdr->msg_name)->sa_family != AF_INET6) { if (options & F_VERBOSE) warnx("invalid peername\n"); return; } - from = (struct sockaddr_in6 *)mhdr->msg_name; + from = (struct sockaddr *)mhdr->msg_name; + fromlen = mhdr->msg_namelen; if (cc < sizeof(struct icmp6_hdr)) { if (options & F_VERBOSE) warnx("packet too short (%d bytes) from %s\n", cc, - pr_addr(from)); + pr_addr(from, fromlen)); return; } icp = (struct icmp6_hdr *)buf; @@ -1388,17 +1405,21 @@ pr_pack(buf, cc, mhdr) (void)write(STDOUT_FILENO, &BSPACE, 1); else { (void)printf("%d bytes from %s, icmp_seq=%u", cc, - pr_addr(from), seq); + pr_addr(from, fromlen), seq); (void)printf(" hlim=%d", hoplim); if ((options & F_VERBOSE) != 0) { struct sockaddr_in6 dstsa; memset(&dstsa, 0, sizeof(dstsa)); dstsa.sin6_family = AF_INET6; +#ifdef SIN6_LEN dstsa.sin6_len = sizeof(dstsa); +#endif dstsa.sin6_scope_id = pktinfo->ipi6_ifindex; dstsa.sin6_addr = pktinfo->ipi6_addr; - (void)printf(" dst=%s", pr_addr(&dstsa)); + (void)printf(" dst=%s", + pr_addr((struct sockaddr *)&dstsa, + sizeof(dstsa))); } if (timing) (void)printf(" time=%g ms", triptime); @@ -1429,7 +1450,7 @@ pr_pack(buf, cc, mhdr) if (options & F_QUIET) return; - (void)printf("%d bytes from %s: ", cc, pr_addr(from)); + (void)printf("%d bytes from %s: ", cc, pr_addr(from, fromlen)); switch (ntohs(ni->ni_code)) { case ICMP6_NI_SUCCESS: @@ -1564,7 +1585,7 @@ pr_pack(buf, cc, mhdr) /* We've got something other than an ECHOREPLY */ if (!(options & F_VERBOSE)) return; - (void)printf("%d bytes from %s: ", cc, pr_addr(from)); + (void)printf("%d bytes from %s: ", cc, pr_addr(from, fromlen)); pr_icmph(icp, end); } @@ -1953,19 +1974,6 @@ tvsub(out, in) } /* - * oninfo -- - * SIGINFO handler. - */ -/* ARGSUSED */ -void -oninfo(notused) - int notused; -{ - - summary(); -} - -/* * onint -- * SIGINT handler. */ @@ -2303,20 +2311,22 @@ pr_iph(ip6) * a hostname. */ const char * -pr_addr(addr) - struct sockaddr_in6 *addr; +pr_addr(addr, addrlen) + struct sockaddr *addr; + int addrlen; { - static char buf[MAXHOSTNAMELEN]; - int flag = 0; + static char buf[NI_MAXHOST]; + int flag; - if ((options & F_HOSTNAME) == 0) - flag |= NI_NUMERICHOST; #ifdef NI_WITHSCOPEID - flag |= NI_WITHSCOPEID; + flag = NI_WITHSCOPEID; +#else + flag = 0; #endif + if ((options & F_HOSTNAME) == 0) + flag |= NI_NUMERICHOST; - if (getnameinfo((struct sockaddr *)addr, addr->sin6_len, - buf, sizeof(buf), NULL, 0, flag) == 0) + if (getnameinfo(addr, addrlen, buf, sizeof(buf), NULL, 0, flag) == 0) return (buf); else return "?"; @@ -2514,7 +2524,7 @@ void usage() { (void)fprintf(stderr, - "usage: ping6 [-dfHnNqvwW" + "usage: ping6 [-dfHmnNqvwW" #ifdef IPV6_REACHCONF "R" #endif |