Changeset View
Changeset View
Standalone View
Standalone View
sbin/ping/ping6.c
Show First 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | |||||
#define F_SUPTYPES 0x80000 | #define F_SUPTYPES 0x80000 | ||||
#define F_NOMINMTU 0x100000 | #define F_NOMINMTU 0x100000 | ||||
#define F_ONCE 0x200000 | #define F_ONCE 0x200000 | ||||
#define F_AUDIBLE 0x400000 | #define F_AUDIBLE 0x400000 | ||||
#define F_MISSED 0x800000 | #define F_MISSED 0x800000 | ||||
#define F_DONTFRAG 0x1000000 | #define F_DONTFRAG 0x1000000 | ||||
#define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES) | #define F_NOUSERDATA (F_NODEADDR | F_FQDN | F_FQDNOLD | F_SUPTYPES) | ||||
#define F_WAITTIME 0x2000000 | #define F_WAITTIME 0x2000000 | ||||
#define F_DOT 0x4000000 | |||||
static u_int options; | static u_int options; | ||||
#define IN6LEN sizeof(struct in6_addr) | #define IN6LEN sizeof(struct in6_addr) | ||||
#define SA6LEN sizeof(struct sockaddr_in6) | #define SA6LEN sizeof(struct sockaddr_in6) | ||||
#define DUMMY_PORT 10101 | #define DUMMY_PORT 10101 | ||||
#define SIN6(s) ((struct sockaddr_in6 *)(s)) | #define SIN6(s) ((struct sockaddr_in6 *)(s)) | ||||
Show All 10 Lines | |||||
static struct sockaddr_in6 src; /* src addr of this packet */ | static struct sockaddr_in6 src; /* src addr of this packet */ | ||||
static socklen_t srclen; | static socklen_t srclen; | ||||
static size_t datalen = DEFDATALEN; | static size_t datalen = DEFDATALEN; | ||||
static int ssend; /* send socket file descriptor */ | static int ssend; /* send socket file descriptor */ | ||||
static int srecv; /* receive socket file descriptor */ | static int srecv; /* receive socket file descriptor */ | ||||
static u_char outpack[MAXPACKETLEN]; | static u_char outpack[MAXPACKETLEN]; | ||||
static char BSPACE = '\b'; /* characters written for flood */ | static char BSPACE = '\b'; /* characters written for flood */ | ||||
static char BBELL = '\a'; /* characters written for AUDIBLE */ | static char BBELL = '\a'; /* characters written for AUDIBLE */ | ||||
static char DOT = '.'; | static const char *DOT = "."; | ||||
static size_t DOTlen = 1; | |||||
static size_t DOTidx = 0; | |||||
static char *hostname; | static char *hostname; | ||||
static int ident; /* process id to identify our packets */ | static int ident; /* process id to identify our packets */ | ||||
static u_int8_t nonce[8]; /* nonce field for node information */ | static u_int8_t nonce[8]; /* nonce field for node information */ | ||||
static int hoplimit = -1; /* hoplimit */ | static int hoplimit = -1; /* hoplimit */ | ||||
static int tclass = -1; /* traffic class */ | static int tclass = -1; /* traffic class */ | ||||
static int pcp = -2; /* vlan priority code point */ | static int pcp = -2; /* vlan priority code point */ | ||||
static u_char *packet = NULL; | static u_char *packet = NULL; | ||||
static cap_channel_t *capdns; | static cap_channel_t *capdns; | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | #endif | ||||
intvl.tv_nsec = interval % 1000 * 1000000; | intvl.tv_nsec = interval % 1000 * 1000000; | ||||
alarmtimeout = preload = 0; | alarmtimeout = preload = 0; | ||||
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN]; | datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN]; | ||||
capdns = capdns_setup(); | capdns = capdns_setup(); | ||||
while ((ch = getopt(argc, argv, PING6OPTS)) != -1) { | while ((ch = getopt(argc, argv, PING6OPTS)) != -1) { | ||||
switch (ch) { | switch (ch) { | ||||
case '.': | |||||
options |= F_DOT; | |||||
if (optarg != NULL) { | |||||
DOT = optarg; | |||||
DOTlen = strlen(optarg); | |||||
} | |||||
break; | |||||
case '6': | case '6': | ||||
/* This option is processed in main(). */ | /* This option is processed in main(). */ | ||||
break; | break; | ||||
case 'k': | case 'k': | ||||
{ | { | ||||
char *cp; | char *cp; | ||||
options &= ~F_NOUSERDATA; | options &= ~F_NOUSERDATA; | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | case 'd': | ||||
options |= F_SO_DEBUG; | options |= F_SO_DEBUG; | ||||
break; | break; | ||||
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; | ||||
options |= F_DOT; | |||||
setbuf(stdout, (char *)NULL); | setbuf(stdout, (char *)NULL); | ||||
break; | break; | ||||
case 'e': | case 'e': | ||||
gateway = optarg; | gateway = optarg; | ||||
break; | break; | ||||
case 'H': | case 'H': | ||||
options |= F_HOSTNAME; | options |= F_HOSTNAME; | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 1,010 Lines • ▼ Show 20 Lines | #endif | ||||
if (i < 0 || i != cc) { | if (i < 0 || i != cc) { | ||||
if (i < 0) { | if (i < 0) { | ||||
ntransmitfailures++; | ntransmitfailures++; | ||||
warn("sendmsg"); | warn("sendmsg"); | ||||
} | } | ||||
(void)printf("ping6: wrote %s %d chars, ret=%d\n", | (void)printf("ping6: wrote %s %d chars, ret=%d\n", | ||||
hostname, cc, i); | hostname, cc, i); | ||||
} | } | ||||
if (!(options & F_QUIET) && options & F_FLOOD) | if (!(options & F_QUIET) && options & F_DOT) | ||||
(void)write(STDOUT_FILENO, &DOT, 1); | (void)write(STDOUT_FILENO, &DOT[DOTidx++ % DOTlen], 1); | ||||
return(0); | return(0); | ||||
} | } | ||||
static int | static int | ||||
myechoreply(const struct icmp6_hdr *icp) | myechoreply(const struct icmp6_hdr *icp) | ||||
{ | { | ||||
if (ntohs(icp->icmp6_id) == ident) | if (ntohs(icp->icmp6_id) == ident) | ||||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | if (icp->icmp6_type == ICMP6_ECHO_REPLY && myechoreply(icp)) { | ||||
if (options & F_QUIET) | if (options & F_QUIET) | ||||
return; | return; | ||||
if (options & F_WAITTIME && triptime > waittime) { | if (options & F_WAITTIME && triptime > waittime) { | ||||
++nrcvtimeout; | ++nrcvtimeout; | ||||
return; | return; | ||||
} | } | ||||
if (options & F_FLOOD) | if (options & F_DOT) | ||||
(void)write(STDOUT_FILENO, &BSPACE, 1); | (void)write(STDOUT_FILENO, &BSPACE, 1); | ||||
else { | else { | ||||
if (options & F_AUDIBLE) | if (options & F_AUDIBLE) | ||||
(void)write(STDOUT_FILENO, &BBELL, 1); | (void)write(STDOUT_FILENO, &BBELL, 1); | ||||
(void)printf("%d bytes from %s, icmp_seq=%u", cc, | (void)printf("%d bytes from %s, icmp_seq=%u", cc, | ||||
pr_addr(from, fromlen), seq); | pr_addr(from, fromlen), seq); | ||||
(void)printf(" hlim=%d", hoplim); | (void)printf(" hlim=%d", hoplim); | ||||
if ((options & F_VERBOSE) != 0) { | if ((options & F_VERBOSE) != 0) { | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | #define safeputc(c) printf((isprint((c)) ? "%c" : "\\%03o"), c) | ||||
} else { | } else { | ||||
/* We've got something other than an ECHOREPLY */ | /* We've got something other than an ECHOREPLY */ | ||||
if (!(options & F_VERBOSE)) | if (!(options & F_VERBOSE)) | ||||
return; | return; | ||||
(void)printf("%d bytes from %s: ", cc, pr_addr(from, fromlen)); | (void)printf("%d bytes from %s: ", cc, pr_addr(from, fromlen)); | ||||
pr_icmph(icp, end); | pr_icmph(icp, end); | ||||
} | } | ||||
if (!(options & F_FLOOD)) { | if (!(options & F_DOT)) { | ||||
(void)putchar('\n'); | (void)putchar('\n'); | ||||
if (options & F_VERBOSE) | if (options & F_VERBOSE) | ||||
pr_exthdrs(mhdr); | pr_exthdrs(mhdr); | ||||
(void)fflush(stdout); | (void)fflush(stdout); | ||||
} | } | ||||
#undef safeputc | #undef safeputc | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,008 Lines • Show Last 20 Lines |