Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/ping6/ping6.c
Show First 20 Lines • Show All 341 Lines • ▼ Show 20 Lines | #endif | ||||
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN]; | datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN]; | ||||
capdns = capdns_setup(); | capdns = capdns_setup(); | ||||
#ifndef IPSEC | #ifndef IPSEC | ||||
#define ADDOPTS | #define ADDOPTS | ||||
#else | #else | ||||
#ifdef IPSEC_POLICY_IPSEC | #ifdef IPSEC_POLICY_IPSEC | ||||
#define ADDOPTS "P:" | #define ADDOPTS "P:" | ||||
#else | #else | ||||
#define ADDOPTS "AE" | #define ADDOPTS "ZE" | ||||
#endif /*IPSEC_POLICY_IPSEC*/ | #endif /*IPSEC_POLICY_IPSEC*/ | ||||
#endif | #endif | ||||
while ((ch = getopt(argc, argv, | while ((ch = getopt(argc, argv, | ||||
"a:b:c:DdfHg:h:I:i:l:mnNop:qrRS:s:tvwWx:X:" ADDOPTS)) != -1) { | "k:b:c:DdfHe:m:I:i:l:unNop:qaAS:s:OvyYW:t:" ADDOPTS)) != -1) { | ||||
#undef ADDOPTS | #undef ADDOPTS | ||||
switch (ch) { | switch (ch) { | ||||
case 'a': | case 'k': | ||||
{ | { | ||||
char *cp; | char *cp; | ||||
options &= ~F_NOUSERDATA; | options &= ~F_NOUSERDATA; | ||||
options |= F_NODEADDR; | options |= F_NODEADDR; | ||||
for (cp = optarg; *cp != '\0'; cp++) { | for (cp = optarg; *cp != '\0'; cp++) { | ||||
switch (*cp) { | switch (*cp) { | ||||
case 'a': | case 'a': | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | #endif | ||||
case 'f': | case 'f': | ||||
if (getuid()) { | if (getuid()) { | ||||
errno = EPERM; | errno = EPERM; | ||||
errx(1, "Must be superuser to flood ping"); | errx(1, "Must be superuser to flood ping"); | ||||
} | } | ||||
options |= F_FLOOD; | options |= F_FLOOD; | ||||
setbuf(stdout, (char *)NULL); | setbuf(stdout, (char *)NULL); | ||||
break; | break; | ||||
case 'g': | case 'e': | ||||
gateway = optarg; | gateway = optarg; | ||||
break; | break; | ||||
case 'H': | case 'H': | ||||
options |= F_HOSTNAME; | options |= F_HOSTNAME; | ||||
break; | break; | ||||
case 'h': /* hoplimit */ | case 'm': /* hoplimit */ | ||||
hoplimit = strtol(optarg, &e, 10); | hoplimit = strtol(optarg, &e, 10); | ||||
if (*optarg == '\0' || *e != '\0') | if (*optarg == '\0' || *e != '\0') | ||||
errx(1, "illegal hoplimit %s", optarg); | errx(1, "illegal hoplimit %s", optarg); | ||||
if (255 < hoplimit || hoplimit < -1) | if (255 < hoplimit || hoplimit < -1) | ||||
errx(1, | errx(1, | ||||
"illegal hoplimit -- %s", optarg); | "illegal hoplimit -- %s", optarg); | ||||
break; | break; | ||||
case 'I': | case 'I': | ||||
Show All 27 Lines | case 'l': | ||||
if (getuid()) { | if (getuid()) { | ||||
errno = EPERM; | errno = EPERM; | ||||
errx(1, "Must be superuser to preload"); | errx(1, "Must be superuser to preload"); | ||||
} | } | ||||
preload = strtol(optarg, &e, 10); | preload = strtol(optarg, &e, 10); | ||||
if (preload < 0 || *optarg == '\0' || *e != '\0') | if (preload < 0 || *optarg == '\0' || *e != '\0') | ||||
errx(1, "illegal preload value -- %s", optarg); | errx(1, "illegal preload value -- %s", optarg); | ||||
break; | break; | ||||
case 'm': | case 'u': | ||||
#ifdef IPV6_USE_MIN_MTU | #ifdef IPV6_USE_MIN_MTU | ||||
mflag++; | mflag++; | ||||
break; | break; | ||||
#else | #else | ||||
errx(1, "-%c is not supported on this platform", ch); | errx(1, "-%c is not supported on this platform", ch); | ||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
#endif | #endif | ||||
case 'n': | case 'n': | ||||
options &= ~F_HOSTNAME; | options &= ~F_HOSTNAME; | ||||
break; | break; | ||||
case 'N': | case 'N': | ||||
options |= F_NIGROUP; | options |= F_NIGROUP; | ||||
nig_oldmcprefix++; | nig_oldmcprefix++; | ||||
break; | break; | ||||
case 'o': | case 'o': | ||||
options |= F_ONCE; | options |= F_ONCE; | ||||
break; | break; | ||||
case 'p': /* fill buffer with user pattern */ | case 'p': /* fill buffer with user pattern */ | ||||
options |= F_PINGFILLED; | options |= F_PINGFILLED; | ||||
fill((char *)datap, optarg); | fill((char *)datap, optarg); | ||||
break; | break; | ||||
case 'q': | case 'q': | ||||
options |= F_QUIET; | options |= F_QUIET; | ||||
break; | break; | ||||
case 'r': | case 'a': | ||||
options |= F_AUDIBLE; | options |= F_AUDIBLE; | ||||
break; | break; | ||||
case 'R': | case 'A': | ||||
options |= F_MISSED; | options |= F_MISSED; | ||||
break; | break; | ||||
case 'S': | case 'S': | ||||
memset(&hints, 0, sizeof(struct addrinfo)); | memset(&hints, 0, sizeof(struct addrinfo)); | ||||
hints.ai_flags = AI_NUMERICHOST; /* allow hostname? */ | hints.ai_flags = AI_NUMERICHOST; /* allow hostname? */ | ||||
hints.ai_family = AF_INET6; | hints.ai_family = AF_INET6; | ||||
hints.ai_socktype = SOCK_RAW; | hints.ai_socktype = SOCK_RAW; | ||||
hints.ai_protocol = IPPROTO_ICMPV6; | hints.ai_protocol = IPPROTO_ICMPV6; | ||||
Show All 17 Lines | case 's': /* size of packet to send */ | ||||
if (datalen <= 0 || *optarg == '\0' || *e != '\0') | if (datalen <= 0 || *optarg == '\0' || *e != '\0') | ||||
errx(1, "illegal datalen value -- %s", optarg); | errx(1, "illegal datalen value -- %s", optarg); | ||||
if (datalen > MAXDATALEN) { | if (datalen > MAXDATALEN) { | ||||
errx(1, | errx(1, | ||||
"datalen value too large, maximum is %d", | "datalen value too large, maximum is %d", | ||||
MAXDATALEN); | MAXDATALEN); | ||||
} | } | ||||
break; | break; | ||||
case 't': | case 'O': | ||||
options &= ~F_NOUSERDATA; | options &= ~F_NOUSERDATA; | ||||
options |= F_SUPTYPES; | options |= F_SUPTYPES; | ||||
break; | break; | ||||
case 'v': | case 'v': | ||||
options |= F_VERBOSE; | options |= F_VERBOSE; | ||||
break; | break; | ||||
case 'w': | case 'y': | ||||
options &= ~F_NOUSERDATA; | options &= ~F_NOUSERDATA; | ||||
options |= F_FQDN; | options |= F_FQDN; | ||||
break; | break; | ||||
case 'W': | case 'Y': | ||||
options &= ~F_NOUSERDATA; | options &= ~F_NOUSERDATA; | ||||
options |= F_FQDNOLD; | options |= F_FQDNOLD; | ||||
break; | break; | ||||
case 'x': | case 'W': | ||||
t = strtod(optarg, &e); | t = strtod(optarg, &e); | ||||
if (*e || e == optarg || t > (double)INT_MAX) | if (*e || e == optarg || t > (double)INT_MAX) | ||||
err(EX_USAGE, "invalid timing interval: `%s'", | err(EX_USAGE, "invalid timing interval: `%s'", | ||||
optarg); | optarg); | ||||
options |= F_WAITTIME; | options |= F_WAITTIME; | ||||
waittime = (int)t; | waittime = (int)t; | ||||
break; | break; | ||||
case 'X': | case 't': | ||||
alarmtimeout = strtoul(optarg, &e, 0); | alarmtimeout = strtoul(optarg, &e, 0); | ||||
if ((alarmtimeout < 1) || (alarmtimeout == ULONG_MAX)) | if ((alarmtimeout < 1) || (alarmtimeout == ULONG_MAX)) | ||||
errx(EX_USAGE, "invalid timeout: `%s'", | errx(EX_USAGE, "invalid timeout: `%s'", | ||||
optarg); | optarg); | ||||
if (alarmtimeout > MAXALARM) | if (alarmtimeout > MAXALARM) | ||||
errx(EX_USAGE, "invalid timeout: `%s' > %d", | errx(EX_USAGE, "invalid timeout: `%s' > %d", | ||||
optarg, MAXALARM); | optarg, MAXALARM); | ||||
alarm((int)alarmtimeout); | alarm((int)alarmtimeout); | ||||
break; | break; | ||||
#ifdef IPSEC | #ifdef IPSEC | ||||
#ifdef IPSEC_POLICY_IPSEC | #ifdef IPSEC_POLICY_IPSEC | ||||
case 'P': | case 'P': | ||||
options |= F_POLICY; | options |= F_POLICY; | ||||
if (!strncmp("in", optarg, 2)) { | if (!strncmp("in", optarg, 2)) { | ||||
if ((policy_in = strdup(optarg)) == NULL) | if ((policy_in = strdup(optarg)) == NULL) | ||||
errx(1, "strdup"); | errx(1, "strdup"); | ||||
} else if (!strncmp("out", optarg, 3)) { | } else if (!strncmp("out", optarg, 3)) { | ||||
if ((policy_out = strdup(optarg)) == NULL) | if ((policy_out = strdup(optarg)) == NULL) | ||||
errx(1, "strdup"); | errx(1, "strdup"); | ||||
} else | } else | ||||
errx(1, "invalid security policy"); | errx(1, "invalid security policy"); | ||||
break; | break; | ||||
#else | #else | ||||
case 'A': | case 'Z': | ||||
options |= F_AUTHHDR; | options |= F_AUTHHDR; | ||||
break; | break; | ||||
case 'E': | case 'E': | ||||
options |= F_ENCRYPT; | options |= F_ENCRYPT; | ||||
break; | break; | ||||
#endif /*IPSEC_POLICY_IPSEC*/ | #endif /*IPSEC_POLICY_IPSEC*/ | ||||
#endif /*IPSEC*/ | #endif /*IPSEC*/ | ||||
default: | default: | ||||
▲ Show 20 Lines • Show All 1,228 Lines • ▼ Show 20 Lines | pr_exthdrs(struct msghdr *mhdr) | ||||
bufp = mhdr->msg_control; | bufp = mhdr->msg_control; | ||||
for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(mhdr); cm; | for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(mhdr); cm; | ||||
cm = (struct cmsghdr *)CMSG_NXTHDR(mhdr, cm)) { | cm = (struct cmsghdr *)CMSG_NXTHDR(mhdr, cm)) { | ||||
if (cm->cmsg_level != IPPROTO_IPV6) | if (cm->cmsg_level != IPPROTO_IPV6) | ||||
continue; | continue; | ||||
bufsize = CONTROLLEN - ((caddr_t)CMSG_DATA(cm) - (caddr_t)bufp); | bufsize = CONTROLLEN - ((caddr_t)CMSG_DATA(cm) - (caddr_t)bufp); | ||||
if (bufsize <= 0) | if (bufsize <= 0) | ||||
continue; | continue; | ||||
switch (cm->cmsg_type) { | switch (cm->cmsg_type) { | ||||
case IPV6_HOPOPTS: | case IPV6_HOPOPTS: | ||||
printf(" HbH Options: "); | printf(" HbH Options: "); | ||||
pr_ip6opt(CMSG_DATA(cm), (size_t)bufsize); | pr_ip6opt(CMSG_DATA(cm), (size_t)bufsize); | ||||
break; | break; | ||||
case IPV6_DSTOPTS: | case IPV6_DSTOPTS: | ||||
#ifdef IPV6_RTHDRDSTOPTS | #ifdef IPV6_RTHDRDSTOPTS | ||||
case IPV6_RTHDRDSTOPTS: | case IPV6_RTHDRDSTOPTS: | ||||
▲ Show 20 Lines • Show All 931 Lines • ▼ Show 20 Lines | if (nig_oldmcprefix) { | ||||
/* draft-ietf-ipngwg-icmp-name-lookup */ | /* draft-ietf-ipngwg-icmp-name-lookup */ | ||||
valid = inet_pton(AF_INET6, "ff02::2:0000:0000", &in6); | valid = inet_pton(AF_INET6, "ff02::2:0000:0000", &in6); | ||||
} else { | } else { | ||||
/* RFC 4620 */ | /* RFC 4620 */ | ||||
valid = inet_pton(AF_INET6, "ff02::2:ff00:0000", &in6); | valid = inet_pton(AF_INET6, "ff02::2:ff00:0000", &in6); | ||||
} | } | ||||
if (valid != 1) | if (valid != 1) | ||||
return NULL; /*XXX*/ | return NULL; /*XXX*/ | ||||
if (nig_oldmcprefix) { | if (nig_oldmcprefix) { | ||||
/* draft-ietf-ipngwg-icmp-name-lookup */ | /* draft-ietf-ipngwg-icmp-name-lookup */ | ||||
bcopy(digest, &in6.s6_addr[12], 4); | bcopy(digest, &in6.s6_addr[12], 4); | ||||
} else { | } else { | ||||
/* RFC 4620 */ | /* RFC 4620 */ | ||||
bcopy(digest, &in6.s6_addr[13], 3); | bcopy(digest, &in6.s6_addr[13], 3); | ||||
} | } | ||||
if (inet_ntop(AF_INET6, &in6, hbuf, sizeof(hbuf)) == NULL) | if (inet_ntop(AF_INET6, &in6, hbuf, sizeof(hbuf)) == NULL) | ||||
return NULL; | return NULL; | ||||
return strdup(hbuf); | return strdup(hbuf); | ||||
} | } | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
(void)fprintf(stderr, | (void)fprintf(stderr, | ||||
#if defined(IPSEC) && !defined(IPSEC_POLICY_IPSEC) | #if defined(IPSEC) && !defined(IPSEC_POLICY_IPSEC) | ||||
"A" | "Z" | ||||
#endif | #endif | ||||
"usage: ping6 [-" | "usage: ping6 [-" | ||||
"Dd" | "aADd" | ||||
#if defined(IPSEC) && !defined(IPSEC_POLICY_IPSEC) | #if defined(IPSEC) && !defined(IPSEC_POLICY_IPSEC) | ||||
"E" | "E" | ||||
#endif | #endif | ||||
"fH" | "fHnNoOq" | ||||
#ifdef IPV6_USE_MIN_MTU | #ifdef IPV6_USE_MIN_MTU | ||||
"m" | "u" | ||||
#endif | #endif | ||||
"nNoqrRtvwW] " | "vyY] " | ||||
"[-a addrtype] [-b bufsiz] [-c count] [-g gateway]\n" | "[-b bufsiz] [-c count] [-e gateway]\n" | ||||
" [-h hoplimit] [-I interface] [-i wait] [-l preload]" | " [-I interface] [-i wait] [-k addrtype] [-l preload] " | ||||
"[-m hoplimit]\n" | |||||
" [-p pattern]" | |||||
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) | #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) | ||||
" [-P policy]" | " [-P policy]" | ||||
#endif | #endif | ||||
"\n" | " [-S sourceaddr] [-s packetsize]\n" | ||||
" [-p pattern] [-S sourceaddr] [-s packetsize] " | " [-t timeout] [-W waittime] [hops ...] host\n"); | ||||
"[-x waittime]\n" | |||||
" [-X timeout] [hops ...] host\n"); | |||||
exit(1); | exit(1); | ||||
} | } | ||||
static cap_channel_t * | static cap_channel_t * | ||||
capdns_setup(void) | capdns_setup(void) | ||||
{ | { | ||||
cap_channel_t *capcas, *capdnsloc; | cap_channel_t *capcas, *capdnsloc; | ||||
#ifdef WITH_CASPER | #ifdef WITH_CASPER | ||||
Show All 22 Lines |