diff options
author | hrs <hrs@FreeBSD.org> | 2014-10-20 00:27:40 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2014-10-20 00:27:40 +0000 |
commit | 4a3d5910e2f211d6f048d619d90b9a06a237ad9b (patch) | |
tree | 94c89abc35b560e4468874af0fc925ec5920cdcf /sbin/ping6 | |
parent | 0a28893572e896d12d1f833c89bf1dc0fcd64a47 (diff) | |
download | FreeBSD-src-4a3d5910e2f211d6f048d619d90b9a06a237ad9b.zip FreeBSD-src-4a3d5910e2f211d6f048d619d90b9a06a237ad9b.tar.gz |
WARNS=3 and style fixes. No functionality change.
Diffstat (limited to 'sbin/ping6')
-rw-r--r-- | sbin/ping6/Makefile | 2 | ||||
-rw-r--r-- | sbin/ping6/ping6.c | 203 |
2 files changed, 102 insertions, 103 deletions
diff --git a/sbin/ping6/Makefile b/sbin/ping6/Makefile index 7f3a008..e40dc6e 100644 --- a/sbin/ping6/Makefile +++ b/sbin/ping6/Makefile @@ -5,7 +5,7 @@ MAN= ping6.8 CFLAGS+=-DIPSEC -DKAME_SCOPEID -DUSE_RFC2292BIS \ -DHAVE_ARC4RANDOM -WARNS?= 2 +WARNS?= 3 BINOWN= root BINMODE=4555 diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index 9ad285c..fa314f6 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -205,84 +205,83 @@ u_int options; * to 8192 for complete accuracy... */ #define MAX_DUP_CHK (8 * 8192) -int mx_dup_ck = MAX_DUP_CHK; -char rcvd_tbl[MAX_DUP_CHK / 8]; - -struct sockaddr_in6 dst; /* who to ping6 */ -struct sockaddr_in6 src; /* src addr of this packet */ -socklen_t srclen; -int datalen = DEFDATALEN; -int s; /* socket file descriptor */ -u_char outpack[MAXPACKETLEN]; -char BSPACE = '\b'; /* characters written for flood */ -char BBELL = '\a'; /* characters written for AUDIBLE */ -char DOT = '.'; -char *hostname; -int ident; /* process id to identify our packets */ -u_int8_t nonce[8]; /* nonce field for node information */ -int hoplimit = -1; /* hoplimit */ -int pathmtu = 0; /* path MTU for the destination. 0 = unspec. */ -u_char *packet = NULL; +static int mx_dup_ck = MAX_DUP_CHK; +static char rcvd_tbl[MAX_DUP_CHK / 8]; + +static struct sockaddr_in6 dst; /* who to ping6 */ +static struct sockaddr_in6 src; /* src addr of this packet */ +static socklen_t srclen; +static size_t datalen = DEFDATALEN; +static int s; /* socket file descriptor */ +static u_char outpack[MAXPACKETLEN]; +static char BSPACE = '\b'; /* characters written for flood */ +static char BBELL = '\a'; /* characters written for AUDIBLE */ +static char DOT = '.'; +static char *hostname; +static int ident; /* process id to identify our packets */ +static u_int8_t nonce[8]; /* nonce field for node information */ +static int hoplimit = -1; /* hoplimit */ +static u_char *packet = NULL; /* counters */ -long nmissedmax; /* max value of ntransmitted - nreceived - 1 */ -long npackets; /* max packets to transmit */ -long nreceived; /* # of packets we got back */ -long nrepeats; /* number of duplicates */ -long ntransmitted; /* sequence # for outbound packets = #sent */ -int interval = 1000; /* interval between packets in ms */ -int waittime = MAXWAIT; /* timeout for each packet */ -long nrcvtimeout = 0; /* # of packets we got back after waittime */ +static long nmissedmax; /* max value of ntransmitted - nreceived - 1 */ +static long npackets; /* max packets to transmit */ +static long nreceived; /* # of packets we got back */ +static long nrepeats; /* number of duplicates */ +static long ntransmitted; /* sequence # for outbound packets = #sent */ +static int interval = 1000; /* interval between packets in ms */ +static int waittime = MAXWAIT; /* timeout for each packet */ +static long nrcvtimeout = 0; /* # of packets we got back after waittime */ /* timing */ -int timing; /* flag to do timing */ -double tmin = 999999999.0; /* minimum round trip time */ -double tmax = 0.0; /* maximum round trip time */ -double tsum = 0.0; /* sum of all times, for doing average */ -double tsumsq = 0.0; /* sum of all times squared, for std. dev. */ +static int timing; /* flag to do timing */ +static double tmin = 999999999.0; /* minimum round trip time */ +static double tmax = 0.0; /* maximum round trip time */ +static double tsum = 0.0; /* sum of all times, for doing average */ +static double tsumsq = 0.0; /* sum of all times squared, for std. dev. */ /* for node addresses */ -u_short naflags; +static u_short naflags; /* for ancillary data(advanced API) */ -struct msghdr smsghdr; -struct iovec smsgiov; -char *scmsg = 0; +static struct msghdr smsghdr; +static struct iovec smsgiov; +static char *scmsg = 0; -volatile sig_atomic_t seenint; +static volatile sig_atomic_t seenint; #ifdef SIGINFO -volatile sig_atomic_t seeninfo; +static volatile sig_atomic_t seeninfo; #endif int main(int, char *[]); -void fill(char *, char *); -int get_hoplim(struct msghdr *); -int get_pathmtu(struct msghdr *); -struct in6_pktinfo *get_rcvpktinfo(struct msghdr *); -void onsignal(int); -void onint(int); -size_t pingerlen(void); -int pinger(void); -const char *pr_addr(struct sockaddr *, int); -void pr_icmph(struct icmp6_hdr *, u_char *); -void pr_iph(struct ip6_hdr *); -void pr_suptypes(struct icmp6_nodeinfo *, size_t); -void pr_nodeaddr(struct icmp6_nodeinfo *, int); -int myechoreply(const struct icmp6_hdr *); -int mynireply(const struct icmp6_nodeinfo *); -char *dnsdecode(const u_char **, const u_char *, const u_char *, - char *, size_t); -void pr_pack(u_char *, int, struct msghdr *); -void pr_exthdrs(struct msghdr *); -void pr_ip6opt(void *, size_t); -void pr_rthdr(void *, size_t); -int pr_bitrange(u_int32_t, int, int); -void pr_retip(struct ip6_hdr *, u_char *); -void summary(void); -void tvsub(struct timeval *, struct timeval *); -int setpolicy(int, char *); -char *nigroup(char *, int); -void usage(void); +static void fill(char *, char *); +static int get_hoplim(struct msghdr *); +static int get_pathmtu(struct msghdr *); +static struct in6_pktinfo *get_rcvpktinfo(struct msghdr *); +static void onsignal(int); +static void onint(int); +static size_t pingerlen(void); +static int pinger(void); +static const char *pr_addr(struct sockaddr *, int); +static void pr_icmph(struct icmp6_hdr *, u_char *); +static void pr_iph(struct ip6_hdr *); +static void pr_suptypes(struct icmp6_nodeinfo *, size_t); +static void pr_nodeaddr(struct icmp6_nodeinfo *, int); +static int myechoreply(const struct icmp6_hdr *); +static int mynireply(const struct icmp6_nodeinfo *); +static char *dnsdecode(const u_char **, const u_char *, const u_char *, + char *, size_t); +static void pr_pack(u_char *, int, struct msghdr *); +static void pr_exthdrs(struct msghdr *); +static void pr_ip6opt(void *, size_t); +static void pr_rthdr(void *, size_t); +static int pr_bitrange(u_int32_t, int, int); +static void pr_retip(struct ip6_hdr *, u_char *); +static void summary(void); +static void tvsub(struct timeval *, struct timeval *); +static int setpolicy(int, char *); +static char *nigroup(char *, int); +static void usage(void); int main(int argc, char *argv[]) @@ -390,9 +389,9 @@ main(int argc, char *argv[]) errno = 0; e = NULL; lsockbufsize = strtoul(optarg, &e, 10); - sockbufsize = lsockbufsize; + sockbufsize = (int)lsockbufsize; if (errno || !*optarg || *e || - sockbufsize != lsockbufsize) + lsockbufsize > INT_MAX) errx(1, "invalid socket buffer size"); #else errx(1, @@ -751,7 +750,7 @@ main(int argc, char *argv[]) *((int *)&nonce[i]) = rand(); #else memset(nonce, 0, sizeof(nonce)); - for (i = 0; i < sizeof(nonce); i += sizeof(u_int32_t)) + for (i = 0; i < (int)sizeof(nonce); i += sizeof(u_int32_t)) *((u_int32_t *)&nonce[i]) = arc4random(); #endif optval = 1; @@ -1009,7 +1008,7 @@ main(int argc, char *argv[]) #if defined(SO_SNDBUF) && defined(SO_RCVBUF) if (sockbufsize) { - if (datalen > sockbufsize) + if (datalen > (size_t)sockbufsize) warnx("you need -b to increase socket buffer size"); if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &sockbufsize, sizeof(sockbufsize)) < 0) @@ -1222,7 +1221,7 @@ main(int argc, char *argv[]) exit(nreceived == 0 ? 2 : 0); } -void +static void onsignal(int sig) { @@ -1247,7 +1246,7 @@ onsignal(int sig) * of the data portion are used to hold a UNIX "timeval" struct in VAX * byte-order, to compute the round-trip time. */ -size_t +static size_t pingerlen(void) { size_t l; @@ -1266,7 +1265,7 @@ pingerlen(void) return l; } -int +static int pinger(void) { struct icmp6_hdr *icp; @@ -1381,7 +1380,7 @@ pinger(void) return(0); } -int +static int myechoreply(const struct icmp6_hdr *icp) { if (ntohs(icp->icmp6_id) == ident) @@ -1390,7 +1389,7 @@ myechoreply(const struct icmp6_hdr *icp) return 0; } -int +static int mynireply(const struct icmp6_nodeinfo *nip) { if (memcmp(nip->icmp6_ni_nonce + sizeof(u_int16_t), @@ -1401,7 +1400,7 @@ mynireply(const struct icmp6_nodeinfo *nip) return 0; } -char * +static char * dnsdecode(const u_char **sp, const u_char *ep, const u_char *base, char *buf, size_t bufsiz) /*base for compressed name*/ @@ -1445,7 +1444,7 @@ dnsdecode(const u_char **sp, const u_char *ep, const u_char *base, char *buf, while (i-- > 0 && cp < ep) { l = snprintf(cresult, sizeof(cresult), isprint(*cp) ? "%c" : "\\%03o", *cp & 0xff); - if (l >= sizeof(cresult) || l < 0) + if ((size_t)l >= sizeof(cresult) || l < 0) return NULL; if (strlcat(buf, cresult, bufsiz) >= bufsiz) return NULL; /*result overrun*/ @@ -1468,7 +1467,7 @@ dnsdecode(const u_char **sp, const u_char *ep, const u_char *base, char *buf, * which arrive ('tis only fair). This permits multiple copies of this * program to be run without having intermingled output (or statistics!). */ -void +static void pr_pack(u_char *buf, int cc, struct msghdr *mhdr) { #define safeputc(c) printf((isprint((c)) ? "%c" : "\\%03o"), c) @@ -1500,7 +1499,7 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr) } from = (struct sockaddr *)mhdr->msg_name; fromlen = mhdr->msg_namelen; - if (cc < sizeof(struct icmp6_hdr)) { + if (cc < (int)sizeof(struct icmp6_hdr)) { if (options & F_VERBOSE) warnx("packet too short (%d bytes) from %s", cc, pr_addr(from, fromlen)); @@ -1754,7 +1753,7 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr) #undef safeputc } -void +static void pr_exthdrs(struct msghdr *mhdr) { ssize_t bufsize; @@ -1792,7 +1791,7 @@ pr_exthdrs(struct msghdr *mhdr) } #ifdef USE_RFC2292BIS -void +static void pr_ip6opt(void *extbuf, size_t bufsize) { struct ip6_hbh *ext; @@ -1855,7 +1854,7 @@ pr_ip6opt(void *extbuf, size_t bufsize) } #else /* !USE_RFC2292BIS */ /* ARGSUSED */ -void +static void pr_ip6opt(void *extbuf, size_t bufsize __unused) { putchar('\n'); @@ -1864,7 +1863,7 @@ pr_ip6opt(void *extbuf, size_t bufsize __unused) #endif /* USE_RFC2292BIS */ #ifdef USE_RFC2292BIS -void +static void pr_rthdr(void *extbuf, size_t bufsize) { struct in6_addr *in6; @@ -1921,7 +1920,7 @@ pr_rthdr(void *extbuf, size_t bufsize) #else /* !USE_RFC2292BIS */ /* ARGSUSED */ -void +static void pr_rthdr(void *extbuf, size_t bufsize __unused) { putchar('\n'); @@ -1929,7 +1928,7 @@ pr_rthdr(void *extbuf, size_t bufsize __unused) } #endif /* USE_RFC2292BIS */ -int +static int pr_bitrange(u_int32_t v, int soff, int ii) { int off; @@ -1975,7 +1974,7 @@ pr_bitrange(u_int32_t v, int soff, int ii) return ii; } -void +static void pr_suptypes(struct icmp6_nodeinfo *ni, size_t nilen) /* ni->qtype must be SUPTYPES */ { @@ -2041,7 +2040,7 @@ pr_suptypes(struct icmp6_nodeinfo *ni, size_t nilen) } } -void +static void pr_nodeaddr(struct icmp6_nodeinfo *ni, int nilen) /* ni->qtype must be NODEADDR */ { @@ -2107,7 +2106,7 @@ pr_nodeaddr(struct icmp6_nodeinfo *ni, int nilen) } } -int +static int get_hoplim(struct msghdr *mhdr) { struct cmsghdr *cm; @@ -2126,7 +2125,7 @@ get_hoplim(struct msghdr *mhdr) return(-1); } -struct in6_pktinfo * +static struct in6_pktinfo * get_rcvpktinfo(struct msghdr *mhdr) { struct cmsghdr *cm; @@ -2145,7 +2144,7 @@ get_rcvpktinfo(struct msghdr *mhdr) return(NULL); } -int +static int get_pathmtu(struct msghdr *mhdr) { #ifdef IPV6_RECVPATHMTU @@ -2205,7 +2204,7 @@ get_pathmtu(struct msghdr *mhdr) * Subtract 2 timeval structs: out = out - in. Out is assumed to * be >= in. */ -void +static void tvsub(struct timeval *out, struct timeval *in) { if ((out->tv_usec -= in->tv_usec) < 0) { @@ -2220,7 +2219,7 @@ tvsub(struct timeval *out, struct timeval *in) * SIGINT handler. */ /* ARGSUSED */ -void +static void onint(int notused __unused) { /* @@ -2235,7 +2234,7 @@ onint(int notused __unused) * summary -- * Print out statistics. */ -void +static void summary(void) { @@ -2285,7 +2284,7 @@ static const char *nircode[] = { * pr_icmph -- * Print a descriptive string about an ICMP header. */ -void +static void pr_icmph(struct icmp6_hdr *icp, u_char *end) { char ntop_buf[INET6_ADDRSTRLEN]; @@ -2515,7 +2514,7 @@ pr_icmph(struct icmp6_hdr *icp, u_char *end) * pr_iph -- * Print an IP6 header. */ -void +static void pr_iph(struct ip6_hdr *ip6) { u_int32_t flow = ip6->ip6_flow & IPV6_FLOWLABEL_MASK; @@ -2543,7 +2542,7 @@ pr_iph(struct ip6_hdr *ip6) * Return an ascii host address as a dotted quad and optionally with * a hostname. */ -const char * +static const char * pr_addr(struct sockaddr *addr, int addrlen) { static char buf[NI_MAXHOST]; @@ -2562,13 +2561,13 @@ pr_addr(struct sockaddr *addr, int addrlen) * pr_retip -- * Dump some info on a returned (via ICMPv6) IPv6 packet. */ -void +static void pr_retip(struct ip6_hdr *ip6, u_char *end) { u_char *cp = (u_char *)ip6, nh; int hlen; - if (end - (u_char *)ip6 < sizeof(*ip6)) { + if ((size_t)(end - (u_char *)ip6) < sizeof(*ip6)) { printf("IP6"); goto trunc; } @@ -2642,7 +2641,7 @@ pr_retip(struct ip6_hdr *ip6, u_char *end) return; } -void +static void fill(char *bp, char *patp) { int ii, jj, kk; @@ -2661,7 +2660,7 @@ fill(char *bp, char *patp) /* xxx */ if (ii > 0) for (kk = 0; - kk <= MAXDATALEN - (8 + sizeof(struct tv32) + ii); + (size_t)kk <= MAXDATALEN - 8 + sizeof(struct tv32) + ii; kk += ii) for (jj = 0; jj < ii; ++jj) bp[jj + kk] = pat[jj]; @@ -2675,7 +2674,7 @@ fill(char *bp, char *patp) #ifdef IPSEC #ifdef IPSEC_POLICY_IPSEC -int +static int setpolicy(int so __unused, char *policy) { char *buf; @@ -2696,7 +2695,7 @@ setpolicy(int so __unused, char *policy) #endif #endif -char * +static char * nigroup(char *name, int nig_oldmcprefix) { char *p; @@ -2755,7 +2754,7 @@ nigroup(char *name, int nig_oldmcprefix) return strdup(hbuf); } -void +static void usage(void) { (void)fprintf(stderr, |