Index: ping6.c =================================================================== RCS file: /home/dcvs/src/sbin/ping6/ping6.c,v retrieving revision 1.8 diff -u -u -r1.8 ping6.c --- ping6.c 5 Mar 2005 22:27:08 -0000 1.8 +++ ping6.c 22 Aug 2008 07:33:28 -0000 @@ -296,13 +296,16 @@ int sockbufsize = 0; int usepktinfo = 0; struct in6_pktinfo *pktinfo = NULL; -#ifdef USE_RFC2292BIS +#ifdef USE_RFC3542 struct ip6_rthdr *rthdr = NULL; #endif #ifdef IPSEC_POLICY_IPSEC char *policy_in = NULL; char *policy_out = NULL; #endif +#ifdef IPV6_USE_MIN_MTU + int mflag = 0; +#endif double intval; size_t rthlen; @@ -440,7 +443,7 @@ break; case 'm': #ifdef IPV6_USE_MIN_MTU - options |= F_NOMINMTU; + mflag++; break; #else errx(1, "-%c is not supported on this platform", ch); @@ -532,18 +535,10 @@ usage(); /*NOTREACHED*/ } - if (argc > 1) { -#ifdef IPV6_RECVRTHDR /* 2292bis */ - rthlen = CMSG_SPACE(inet6_rth_space(IPV6_RTHDR_TYPE_0, - argc - 1)); -#else /* RFC2292 */ - rthlen = inet6_rthdr_space(IPV6_RTHDR_TYPE_0, argc - 1); -#endif - if (rthlen == 0) { - errx(1, "too many intermediate hops"); - /*NOTREACHED*/ - } + rthlen = 0; + errx(1, "too many intermediate hops"); + /*NOTREACHED*/ ip6optlen += rthlen; } @@ -590,7 +585,7 @@ int opton = 1; #ifdef IPV6_RECVHOPOPTS - if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPOPTS, &opton, + if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPOPTS, &opton, sizeof(opton))) err(1, "setsockopt(IPV6_RECVHOPOPTS)"); #else /* old adv. API */ @@ -669,8 +664,8 @@ &optval, sizeof(optval)) == -1) err(1, "IPV6_MULTICAST_HOPS"); #ifdef IPV6_USE_MIN_MTU - if ((options & F_NOMINMTU) == 0) { - optval = 1; + if (mflag != 1) { + optval = mflag > 1 ? 0 : 1; if (setsockopt(s, IPPROTO_IPV6, IPV6_USE_MIN_MTU, &optval, sizeof(optval)) == -1) err(1, "setsockopt(IPV6_USE_MIN_MTU)"); @@ -818,60 +813,6 @@ scmsgp = CMSG_NXTHDR(&smsghdr, scmsgp); } #endif - - if (argc > 1) { /* some intermediate addrs are specified */ - int hops, error; -#ifdef USE_RFC2292BIS - int rthdrlen; -#endif - -#ifdef USE_RFC2292BIS - rthdrlen = inet6_rth_space(IPV6_RTHDR_TYPE_0, argc - 1); - scmsgp->cmsg_len = CMSG_LEN(rthdrlen); - scmsgp->cmsg_level = IPPROTO_IPV6; - scmsgp->cmsg_type = IPV6_RTHDR; - rthdr = (struct ip6_rthdr *)CMSG_DATA(scmsgp); - rthdr = inet6_rth_init((void *)rthdr, rthdrlen, - IPV6_RTHDR_TYPE_0, argc - 1); - if (rthdr == NULL) - errx(1, "can't initialize rthdr"); -#else /* old advanced API */ - if ((scmsgp = (struct cmsghdr *)inet6_rthdr_init(scmsgp, - IPV6_RTHDR_TYPE_0)) == 0) - errx(1, "can't initialize rthdr"); -#endif /* USE_RFC2292BIS */ - - for (hops = 0; hops < argc - 1; hops++) { - struct addrinfo *iaip; - - if ((error = getaddrinfo(argv[hops], NULL, &hints, - &iaip))) - errx(1, "%s", gai_strerror(error)); - if (SIN6(iaip->ai_addr)->sin6_family != AF_INET6) - errx(1, - "bad addr family of an intermediate addr"); - -#ifdef USE_RFC2292BIS - if (inet6_rth_add(rthdr, - &(SIN6(iaip->ai_addr))->sin6_addr)) - errx(1, "can't add an intermediate node"); -#else /* old advanced API */ - if (inet6_rthdr_add(scmsgp, - &(SIN6(iaip->ai_addr))->sin6_addr, - IPV6_RTHDR_LOOSE)) - errx(1, "can't add an intermediate node"); -#endif /* USE_RFC2292BIS */ - freeaddrinfo(iaip); - } - -#ifndef USE_RFC2292BIS - if (inet6_rthdr_lasthop(scmsgp, IPV6_RTHDR_LOOSE)) - errx(1, "can't set the last flag"); -#endif - - scmsgp = CMSG_NXTHDR(&smsghdr, scmsgp); - } - { /* * source selection @@ -886,17 +827,19 @@ src.sin6_port = ntohs(DUMMY_PORT); src.sin6_scope_id = dst.sin6_scope_id; -#ifdef USE_RFC2292BIS +#ifdef USE_RFC3542 if (pktinfo && setsockopt(dummy, IPPROTO_IPV6, IPV6_PKTINFO, (void *)pktinfo, sizeof(*pktinfo))) err(1, "UDP setsockopt(IPV6_PKTINFO)"); - if (hoplimit != -1 && - setsockopt(dummy, IPPROTO_IPV6, IPV6_HOPLIMIT, + setsockopt(dummy, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (void *)&hoplimit, sizeof(hoplimit))) - err(1, "UDP setsockopt(IPV6_HOPLIMIT)"); - + err(1, "UDP setsockopt(IPV6_UNICAST_HOPS)"); + if (hoplimit != -1 && + setsockopt(dummy, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, + (void *)&hoplimit, sizeof(hoplimit))) + err(1, "UDP setsockopt(IPV6_MULTICAST_HOPS)"); if (rthdr && setsockopt(dummy, IPPROTO_IPV6, IPV6_RTHDR, (void *)rthdr, (rthdr->ip6r_len + 1) << 3)) @@ -1664,7 +1607,7 @@ } } -#ifdef USE_RFC2292BIS +#ifdef USE_RFC3542 void pr_ip6opt(void *extbuf) { @@ -1715,7 +1658,7 @@ } return; } -#else /* !USE_RFC2292BIS */ +#else /* !USE_RFC3542 */ /* ARGSUSED */ void pr_ip6opt(void *extbuf __unused) @@ -1723,9 +1666,9 @@ putchar('\n'); return; } -#endif /* USE_RFC2292BIS */ +#endif /* USE_RFC3542 */ -#ifdef USE_RFC2292BIS +#ifdef USE_RFC3542 void pr_rthdr(void *extbuf) { @@ -1737,29 +1680,13 @@ /* print fixed part of the header */ printf("nxt %u, len %u (%d bytes), type %u, ", rh->ip6r_nxt, rh->ip6r_len, (rh->ip6r_len + 1) << 3, rh->ip6r_type); - if ((segments = inet6_rth_segments(extbuf)) >= 0) - printf("%d segments, ", segments); - else - printf("segments unknown, "); + printf("segments unknown, "); printf("%d left\n", rh->ip6r_segleft); - - for (i = 0; i < segments; i++) { - in6 = inet6_rth_getaddr(extbuf, i); - if (in6 == NULL) - printf(" [%d]\n", i); - else { - if (!inet_ntop(AF_INET6, in6, ntopbuf, - sizeof(ntopbuf))) - strncpy(ntopbuf, "?", sizeof(ntopbuf)); - printf(" [%d]%s\n", i, ntopbuf); - } - } - return; } -#else /* !USE_RFC2292BIS */ +#else /* !USE_RFC3542 */ /* ARGSUSED */ void pr_rthdr(void *extbuf __unused) @@ -1767,7 +1694,7 @@ putchar('\n'); return; } -#endif /* USE_RFC2292BIS */ +#endif /* USE_RFC3542 */ int pr_bitrange(u_int32_t v, int ss, int ii)