Simplify: remove #ifdefs for constants that are always defined, and

remove their #else's (some of which can't compile, since they use values
that since got removed).
This commit is contained in:
maxv 2018-04-23 18:32:18 +00:00
parent ce1a532448
commit ed8f79525d
1 changed files with 15 additions and 75 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ping6.c,v 1.97 2018/04/23 10:35:20 maxv Exp $ */ /* $NetBSD: ping6.c,v 1.98 2018/04/23 18:32:18 maxv Exp $ */
/* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */ /* $KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $ */
/* /*
@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c 8.1 (Berkeley) 6/5/93";
#else #else
#include <sys/cdefs.h> #include <sys/cdefs.h>
#ifndef lint #ifndef lint
__RCSID("$NetBSD: ping6.c,v 1.97 2018/04/23 10:35:20 maxv Exp $"); __RCSID("$NetBSD: ping6.c,v 1.98 2018/04/23 18:32:18 maxv Exp $");
#endif #endif
#endif #endif
@ -171,14 +171,9 @@ struct tv32 {
#define F_RROUTE 0x0020 #define F_RROUTE 0x0020
#define F_SO_DEBUG 0x0040 #define F_SO_DEBUG 0x0040
#define F_VERBOSE 0x0100 #define F_VERBOSE 0x0100
#ifdef IPSEC #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
#ifdef IPSEC_POLICY_IPSEC
#define F_POLICY 0x0400 #define F_POLICY 0x0400
#else #endif
#define F_AUTHHDR 0x0200
#define F_ENCRYPT 0x0400
#endif /*IPSEC_POLICY_IPSEC*/
#endif /*IPSEC*/
#define F_NODEADDR 0x0800 #define F_NODEADDR 0x0800
#define F_FQDN 0x1000 #define F_FQDN 0x1000
#define F_INTERFACE 0x2000 #define F_INTERFACE 0x2000
@ -282,11 +277,9 @@ static int pr_bitrange(u_int32_t, int, int);
static void pr_retip(struct ip6_hdr *, u_char *); static void pr_retip(struct ip6_hdr *, u_char *);
static void summary(void); static void summary(void);
static void tvsub(struct timeval *, struct timeval *); static void tvsub(struct timeval *, struct timeval *);
#ifdef IPSEC #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
#ifdef IPSEC_POLICY_IPSEC
static int setpolicy(int, char *); static int setpolicy(int, char *);
#endif /* IPSEC_POLICY_IPSEC */ #endif
#endif /* IPSEC */
static char *nigroup(char *); static char *nigroup(char *);
static double timespec_to_sec(const struct timespec *tp); static double timespec_to_sec(const struct timespec *tp);
static double diffsec(struct timespec *, struct timespec *); static double diffsec(struct timespec *, struct timespec *);
@ -303,10 +296,8 @@ main(int argc, char *argv[])
char *e, *target, *ifname = NULL, *gateway = NULL; char *e, *target, *ifname = NULL, *gateway = NULL;
int ip6optlen = 0; int ip6optlen = 0;
struct cmsghdr *scmsgp = NULL; struct cmsghdr *scmsgp = NULL;
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
u_long lsockbufsize; u_long lsockbufsize;
int sockbufsize = 0; int sockbufsize = 0;
#endif
int usepktinfo = 0; int usepktinfo = 0;
struct in6_pktinfo *pktinfo = NULL; struct in6_pktinfo *pktinfo = NULL;
struct ip6_rthdr *rthdr = NULL; struct ip6_rthdr *rthdr = NULL;
@ -315,9 +306,7 @@ main(int argc, char *argv[])
char *policy_out = NULL; char *policy_out = NULL;
#endif #endif
double intval; double intval;
#ifdef IPV6_USE_MIN_MTU
int mflag = 0; int mflag = 0;
#endif
/* just to be sure */ /* just to be sure */
memset(&smsghdr, 0, sizeof(smsghdr)); memset(&smsghdr, 0, sizeof(smsghdr));
@ -325,14 +314,11 @@ main(int argc, char *argv[])
preload = 0; preload = 0;
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN]; datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN];
#ifndef IPSEC
#define ADDOPTS #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
#else
#ifdef IPSEC_POLICY_IPSEC
#define ADDOPTS "P:" #define ADDOPTS "P:"
#else #else
#define ADDOPTS "AE" #define ADDOPTS
#endif /*IPSEC_POLICY_IPSEC*/
#endif #endif
if (prog_init && prog_init() == -1) if (prog_init && prog_init() == -1)
@ -386,7 +372,6 @@ main(int argc, char *argv[])
break; break;
} }
case 'b': case 'b':
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
errno = 0; errno = 0;
e = NULL; e = NULL;
lsockbufsize = strtoul(optarg, &e, 10); lsockbufsize = strtoul(optarg, &e, 10);
@ -394,10 +379,6 @@ main(int argc, char *argv[])
if (errno || !*optarg || *e || if (errno || !*optarg || *e ||
(u_long)sockbufsize != lsockbufsize) (u_long)sockbufsize != lsockbufsize)
errx(1, "invalid socket buffer size"); errx(1, "invalid socket buffer size");
#else
errx(1,
"-b option ignored: SO_SNDBUF/SO_RCVBUF socket options not supported");
#endif
break; break;
case 'c': case 'c':
l = strtol(optarg, &e, 10); l = strtol(optarg, &e, 10);
@ -485,13 +466,8 @@ main(int argc, char *argv[])
preload = l; preload = l;
break; break;
case 'm': case 'm':
#ifdef IPV6_USE_MIN_MTU
mflag++; mflag++;
break; break;
#else
errx(1, "-%c is not supported on this platform", ch);
/*NOTREACHED*/
#endif
case 'n': case 'n':
options &= ~F_HOSTNAME; options &= ~F_HOSTNAME;
break; break;
@ -573,8 +549,8 @@ main(int argc, char *argv[])
errx(EXIT_FAILURE, "Bad/invalid deadline time: " errx(EXIT_FAILURE, "Bad/invalid deadline time: "
"%s", optarg); "%s", optarg);
break; break;
#ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
case 'P': case 'P':
options |= F_POLICY; options |= F_POLICY;
if (!strncmp("in", optarg, 2)) { if (!strncmp("in", optarg, 2)) {
@ -586,15 +562,7 @@ main(int argc, char *argv[])
} else } else
errx(1, "invalid security policy"); errx(1, "invalid security policy");
break; break;
#else #endif
case 'A':
options |= F_AUTHHDR;
break;
case 'E':
options |= F_ENCRYPT;
break;
#endif /*IPSEC_POLICY_IPSEC*/
#endif /*IPSEC*/
default: default:
usage(); usage();
/*NOTREACHED*/ /*NOTREACHED*/
@ -758,34 +726,13 @@ main(int argc, char *argv[])
err(1, "setsockopt(IPV6_RECVPATHMTU)"); err(1, "setsockopt(IPV6_RECVPATHMTU)");
} }
#ifdef IPSEC #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
#ifdef IPSEC_POLICY_IPSEC
if (options & F_POLICY) { if (options & F_POLICY) {
if (setpolicy(s, policy_in) < 0) if (setpolicy(s, policy_in) < 0)
errx(1, "%s", ipsec_strerror()); errx(1, "%s", ipsec_strerror());
if (setpolicy(s, policy_out) < 0) if (setpolicy(s, policy_out) < 0)
errx(1, "%s", ipsec_strerror()); errx(1, "%s", ipsec_strerror());
} }
#else
if (options & F_AUTHHDR) {
optval = IPSEC_LEVEL_REQUIRE;
#ifdef IPV6_AUTH_TRANS_LEVEL
if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_AUTH_TRANS_LEVEL,
&optval, sizeof(optval)) == -1)
err(1, "setsockopt(IPV6_AUTH_TRANS_LEVEL)");
#else /* old def */
if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_AUTH_LEVEL,
&optval, sizeof(optval)) == -1)
err(1, "setsockopt(IPV6_AUTH_LEVEL)");
#endif
}
if (options & F_ENCRYPT) {
optval = IPSEC_LEVEL_REQUIRE;
if (prog_setsockopt(s, IPPROTO_IPV6, IPV6_ESP_TRANS_LEVEL,
&optval, sizeof(optval)) == -1)
err(1, "setsockopt(IPV6_ESP_TRANS_LEVEL)");
}
#endif /*IPSEC_POLICY_IPSEC*/
#endif #endif
#ifdef ICMP6_FILTER #ifdef ICMP6_FILTER
@ -927,7 +874,6 @@ main(int argc, char *argv[])
prog_close(dummy); prog_close(dummy);
} }
#if defined(SO_SNDBUF) && defined(SO_RCVBUF)
if (sockbufsize) { if (sockbufsize) {
if (datalen > sockbufsize) if (datalen > sockbufsize)
warnx("you need -b to increase socket buffer size"); warnx("you need -b to increase socket buffer size");
@ -937,8 +883,7 @@ main(int argc, char *argv[])
if (prog_setsockopt(s, SOL_SOCKET, SO_RCVBUF, &sockbufsize, if (prog_setsockopt(s, SOL_SOCKET, SO_RCVBUF, &sockbufsize,
sizeof(sockbufsize)) < 0) sizeof(sockbufsize)) < 0)
err(1, "setsockopt(SO_RCVBUF)"); err(1, "setsockopt(SO_RCVBUF)");
} } else {
else {
if (datalen > 8 * 1024) /*XXX*/ if (datalen > 8 * 1024) /*XXX*/
warnx("you need -b to increase socket buffer size"); warnx("you need -b to increase socket buffer size");
/* /*
@ -951,7 +896,6 @@ main(int argc, char *argv[])
prog_setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold, prog_setsockopt(s, SOL_SOCKET, SO_RCVBUF, (char *)&hold,
sizeof(hold)); sizeof(hold));
} }
#endif
optval = 1; optval = 1;
#ifndef USE_SIN6_SCOPE_ID #ifndef USE_SIN6_SCOPE_ID
@ -2514,8 +2458,7 @@ fill(char *bp, char *patp)
} }
} }
#ifdef IPSEC #if defined(IPSEC) && defined(IPSEC_POLICY_IPSEC)
#ifdef IPSEC_POLICY_IPSEC
static int static int
setpolicy(int so, char *policy) setpolicy(int so, char *policy)
{ {
@ -2535,7 +2478,6 @@ setpolicy(int so, char *policy)
return 0; return 0;
} }
#endif #endif
#endif
static char * static char *
nigroup(char *name) nigroup(char *name)
@ -2610,9 +2552,7 @@ usage(void)
#else #else
"AdEfH" "AdEfH"
#endif #endif
#ifdef IPV6_USE_MIN_MTU
"m" "m"
#endif
"Nnq" "Nnq"
#ifdef IPV6_REACHCONF #ifdef IPV6_REACHCONF
"R" "R"