Changeset View
Changeset View
Standalone View
Standalone View
sbin/ping/ping.c
Show First 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | |||||
#define F_TTL 0x8000 | #define F_TTL 0x8000 | ||||
#define F_MISSED 0x10000 | #define F_MISSED 0x10000 | ||||
#define F_ONCE 0x20000 | #define F_ONCE 0x20000 | ||||
#define F_HDRINCL 0x40000 | #define F_HDRINCL 0x40000 | ||||
#define F_MASK 0x80000 | #define F_MASK 0x80000 | ||||
#define F_TIME 0x100000 | #define F_TIME 0x100000 | ||||
#define F_SWEEP 0x200000 | #define F_SWEEP 0x200000 | ||||
#define F_WAITTIME 0x400000 | #define F_WAITTIME 0x400000 | ||||
#define F_IP_VLAN_PCP 0x800000 | |||||
/* | /* | ||||
* MAX_DUP_CHK is the number of bits in received table, i.e. the maximum | * MAX_DUP_CHK is the number of bits in received table, i.e. the maximum | ||||
* number of received sequence numbers we can keep track of. Change 128 | * number of received sequence numbers we can keep track of. Change 128 | ||||
* to 8192 for complete accuracy... | * to 8192 for complete accuracy... | ||||
*/ | */ | ||||
#define MAX_DUP_CHK (8 * 128) | #define MAX_DUP_CHK (8 * 128) | ||||
static int mx_dup_ck = MAX_DUP_CHK; | static int mx_dup_ck = MAX_DUP_CHK; | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
#ifdef IPSEC_POLICY_IPSEC | #ifdef IPSEC_POLICY_IPSEC | ||||
char *policy_in, *policy_out; | char *policy_in, *policy_out; | ||||
#endif | #endif | ||||
struct sockaddr_in *to; | struct sockaddr_in *to; | ||||
double t; | double t; | ||||
u_long alarmtimeout; | u_long alarmtimeout; | ||||
long ltmp; | long ltmp; | ||||
int almost_done, ch, df, hold, i, icmp_len, mib[4], preload; | int almost_done, ch, df, hold, i, icmp_len, mib[4], preload; | ||||
int ssend_errno, srecv_errno, tos, ttl; | int ssend_errno, srecv_errno, tos, ttl, pcp; | ||||
char ctrl[CMSG_SPACE(sizeof(struct timespec))]; | char ctrl[CMSG_SPACE(sizeof(struct timespec))]; | ||||
char hnamebuf[MAXHOSTNAMELEN], snamebuf[MAXHOSTNAMELEN]; | char hnamebuf[MAXHOSTNAMELEN], snamebuf[MAXHOSTNAMELEN]; | ||||
#ifdef IP_OPTIONS | #ifdef IP_OPTIONS | ||||
char rspace[MAX_IPOPTLEN]; /* record route space */ | char rspace[MAX_IPOPTLEN]; /* record route space */ | ||||
#endif | #endif | ||||
unsigned char loop, mttl; | unsigned char loop, mttl; | ||||
payload = source = NULL; | payload = source = NULL; | ||||
Show All 31 Lines | if (ssend < 0) { | ||||
err(EX_OSERR, "ssend socket"); | err(EX_OSERR, "ssend socket"); | ||||
} | } | ||||
if (srecv < 0) { | 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 = pcp = 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:" | "AaC:c: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 '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': | |||||
options |= F_IP_VLAN_PCP; | |||||
ltmp = strtol(optarg, &ep, 0); | |||||
if (*ep || ep == optarg || ltmp > 7 || ltmp < -1) | |||||
errx(EX_USAGE, "invalid PCP: `%s'", optarg); | |||||
pcp = ltmp; | |||||
break; | |||||
case 'c': | case 'c': | ||||
ltmp = strtol(optarg, &ep, 0); | ltmp = strtol(optarg, &ep, 0); | ||||
if (*ep || ep == optarg || ltmp <= 0) | if (*ep || ep == optarg || ltmp <= 0) | ||||
errx(EX_USAGE, | errx(EX_USAGE, | ||||
"invalid count of packets to transmit: `%s'", | "invalid count of packets to transmit: `%s'", | ||||
optarg); | optarg); | ||||
npackets = ltmp; | npackets = ltmp; | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 335 Lines • ▼ Show 20 Lines | if (options & F_SO_DEBUG) { | ||||
(void)setsockopt(ssend, SOL_SOCKET, SO_DEBUG, (char *)&hold, | (void)setsockopt(ssend, SOL_SOCKET, SO_DEBUG, (char *)&hold, | ||||
sizeof(hold)); | sizeof(hold)); | ||||
(void)setsockopt(srecv, SOL_SOCKET, SO_DEBUG, (char *)&hold, | (void)setsockopt(srecv, SOL_SOCKET, SO_DEBUG, (char *)&hold, | ||||
sizeof(hold)); | sizeof(hold)); | ||||
} | } | ||||
if (options & F_SO_DONTROUTE) | if (options & F_SO_DONTROUTE) | ||||
(void)setsockopt(ssend, SOL_SOCKET, SO_DONTROUTE, (char *)&hold, | (void)setsockopt(ssend, SOL_SOCKET, SO_DONTROUTE, (char *)&hold, | ||||
sizeof(hold)); | sizeof(hold)); | ||||
if (options & F_IP_VLAN_PCP) { | |||||
(void)setsockopt(ssend, IPPROTO_IP, IP_VLAN_PCP, (char *)&pcp, | |||||
sizeof(pcp)); | |||||
} | |||||
#ifdef IPSEC | #ifdef IPSEC | ||||
#ifdef IPSEC_POLICY_IPSEC | #ifdef IPSEC_POLICY_IPSEC | ||||
if (options & F_POLICY) { | if (options & F_POLICY) { | ||||
char *buf; | char *buf; | ||||
if (policy_in != NULL) { | if (policy_in != NULL) { | ||||
buf = ipsec_set_policy(policy_in, strlen(policy_in)); | buf = ipsec_set_policy(policy_in, strlen(policy_in)); | ||||
if (buf == NULL) | if (buf == NULL) | ||||
errx(EX_CONFIG, "%s", ipsec_strerror()); | errx(EX_CONFIG, "%s", ipsec_strerror()); | ||||
▲ Show 20 Lines • Show All 1,081 Lines • ▼ Show 20 Lines | |||||
#else | #else | ||||
#define SECOPT "" | #define SECOPT "" | ||||
#endif | #endif | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", | (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]", | "usage: ping [-AaDdfHnoQqRrv] [-C pcp] [-c count] [-G sweepmaxsize] [-g sweepminsize]", | ||||
" [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]", | " [-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]", | ||||
" " SECOPT " [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]", | " " SECOPT " [-p pattern] [-S src_addr] [-s packetsize] [-t timeout]", | ||||
" [-W waittime] [-z tos] host", | " [-W waittime] [-z tos] host", | ||||
" ping [-AaDdfHLnoQqRrv] [-c count] [-I iface] [-i wait] [-l preload]", | " ping [-AaDdfHLnoQqRrv] [-C pcp] [-c count] [-I iface] [-i wait] [-l preload]", | ||||
" [-M mask | time] [-m ttl]" SECOPT " [-p pattern] [-S src_addr]", | " [-M mask | time] [-m ttl]" SECOPT " [-p pattern] [-S src_addr]", | ||||
" [-s packetsize] [-T ttl] [-t timeout] [-W waittime]", | " [-s packetsize] [-T ttl] [-t timeout] [-W waittime]", | ||||
" [-z tos] mcast-group"); | " [-z tos] mcast-group"); | ||||
exit(EX_USAGE); | exit(EX_USAGE); | ||||
} | } |