Changeset View
Changeset View
Standalone View
Standalone View
sbin/ping/ping.c
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | |||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <sysexits.h> | #include <sysexits.h> | ||||
#include <time.h> | #include <time.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "main.h" | |||||
#include "ping.h" | |||||
#include "utils.h" | #include "utils.h" | ||||
#define INADDR_LEN ((int)sizeof(in_addr_t)) | #define INADDR_LEN ((int)sizeof(in_addr_t)) | ||||
#define TIMEVAL_LEN ((int)sizeof(struct tv32)) | #define TIMEVAL_LEN ((int)sizeof(struct tv32)) | ||||
#define MASK_LEN (ICMP_MASKLEN - ICMP_MINLEN) | #define MASK_LEN (ICMP_MASKLEN - ICMP_MINLEN) | ||||
#define TS_LEN (ICMP_TSLEN - ICMP_MINLEN) | #define TS_LEN (ICMP_TSLEN - ICMP_MINLEN) | ||||
#define DEFDATALEN 56 /* default data length */ | #define DEFDATALEN 56 /* default data length */ | ||||
#define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */ | #define FLOOD_BACKOFF 20000 /* usecs to back off if F_FLOOD mode */ | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | |||||
static char *pr_addr(struct in_addr); | static char *pr_addr(struct in_addr); | ||||
static char *pr_ntime(n_time); | static char *pr_ntime(n_time); | ||||
static void pr_icmph(struct icmp *); | static void pr_icmph(struct icmp *); | ||||
static void pr_iph(struct ip *); | static void pr_iph(struct ip *); | ||||
static void pr_pack(char *, int, struct sockaddr_in *, struct timespec *); | static void pr_pack(char *, int, struct sockaddr_in *, struct timespec *); | ||||
static void pr_retip(struct ip *); | static void pr_retip(struct ip *); | ||||
static void status(int); | static void status(int); | ||||
static void stopit(int); | static void stopit(int); | ||||
static void usage(void) __dead2; | |||||
int | int | ||||
main(int argc, char *const *argv) | ping(int argc, char *const *argv) | ||||
{ | { | ||||
struct sockaddr_in from, sock_in; | struct sockaddr_in from, sock_in; | ||||
struct in_addr ifaddr; | struct in_addr ifaddr; | ||||
struct timespec last, intvl; | struct timespec last, intvl; | ||||
struct iovec iov; | struct iovec iov; | ||||
struct ip *ip; | struct ip *ip; | ||||
struct msghdr msg; | struct msghdr msg; | ||||
struct sigaction si_sa; | struct sigaction si_sa; | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if (srecv < 0) { | ||||
errno = srecv_errno; | errno = srecv_errno; | ||||
err(EX_OSERR, "srecv socket"); | err(EX_OSERR, "srecv socket"); | ||||
} | } | ||||
alarmtimeout = df = preload = tos = 0; | alarmtimeout = df = preload = tos = 0; | ||||
outpack = outpackhdr + sizeof(struct ip); | outpack = outpackhdr + sizeof(struct ip); | ||||
while ((ch = getopt(argc, argv, | while ((ch = getopt(argc, argv, | ||||
"Aac:DdfG:g:Hh:I:i:Ll:M:m:nop:QqRrS:s:T:t:vW:z:" | "4Aac:DdfG:g:Hh:I:i:Ll:M:m:nop:QqRrS:s:T:t:vW:z:" | ||||
#ifdef IPSEC | #ifdef IPSEC | ||||
#ifdef IPSEC_POLICY_IPSEC | #ifdef IPSEC_POLICY_IPSEC | ||||
"P:" | "P:" | ||||
#endif /*IPSEC_POLICY_IPSEC*/ | #endif /*IPSEC_POLICY_IPSEC*/ | ||||
#endif /*IPSEC*/ | #endif /*IPSEC*/ | ||||
)) != -1) | )) != -1) | ||||
{ | { | ||||
switch(ch) { | switch(ch) { | ||||
case '4': | |||||
/* This options is processed in main(). */ | |||||
asomers: s/options/option/ | |||||
jansucanUnsubmitted Done Inline ActionsFixed. jansucan: Fixed. | |||||
break; | |||||
case 'A': | case 'A': | ||||
options |= F_MISSED; | options |= F_MISSED; | ||||
break; | break; | ||||
case 'a': | case 'a': | ||||
options |= F_AUDIBLE; | options |= F_AUDIBLE; | ||||
break; | break; | ||||
case 'c': | case 'c': | ||||
ltmp = strtol(optarg, &ep, 0); | ltmp = strtol(optarg, &ep, 0); | ||||
▲ Show 20 Lines • Show All 1,412 Lines • ▼ Show 20 Lines | #ifdef WITH_CASPER | ||||
types[1] = "ADDR2NAME"; | types[1] = "ADDR2NAME"; | ||||
if (cap_dns_type_limit(capdnsloc, types, 2) < 0) | if (cap_dns_type_limit(capdnsloc, types, 2) < 0) | ||||
err(1, "unable to limit access to system.dns service"); | err(1, "unable to limit access to system.dns service"); | ||||
families[0] = AF_INET; | families[0] = AF_INET; | ||||
if (cap_dns_family_limit(capdnsloc, families, 1) < 0) | if (cap_dns_family_limit(capdnsloc, families, 1) < 0) | ||||
err(1, "unable to limit access to system.dns service"); | err(1, "unable to limit access to system.dns service"); | ||||
#endif | #endif | ||||
return (capdnsloc); | return (capdnsloc); | ||||
} | |||||
#if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC) | |||||
#define SECOPT " [-P policy]" | |||||
#else | |||||
#define SECOPT "" | |||||
#endif | |||||
static void | |||||
usage(void) | |||||
{ | |||||
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", | |||||
"usage: ping [-AaDdfHnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize]", | |||||
" [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]", | |||||
" " SECOPT " [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]", | |||||
" [-W waittime] [-z tos] host", | |||||
" ping [-AaDdfHLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]", | |||||
" [-M mask | time] [-m ttl]" SECOPT " [-p pattern] [-S src_addr]", | |||||
" [-s packetsize] [-T ttl] [-t timeout] [-W waittime]", | |||||
" [-z tos] mcast-group"); | |||||
exit(EX_USAGE); | |||||
} | } |
s/options/option/