style(9) cleanup.

Submitted by:	kris (an early version of this patch)
Reviewed by:	bde
Approved by:	ru
MFC after:	2 weeks
This commit is contained in:
Maxim Konovalov 2002-04-02 09:36:46 +00:00
parent 3419a3b021
commit 1ad0b1beb4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=93638

View File

@ -206,6 +206,7 @@ main(argc, argv)
struct timeval last, intvl; struct timeval last, intvl;
struct hostent *hp; struct hostent *hp;
struct sockaddr_in *to; struct sockaddr_in *to;
double t;
u_char *datap, *packet; u_char *datap, *packet;
char *ep, *source, *target; char *ep, *source, *target;
#ifdef IPSEC_POLICY_IPSEC #ifdef IPSEC_POLICY_IPSEC
@ -275,36 +276,29 @@ main(argc, argv)
setbuf(stdout, (char *)NULL); setbuf(stdout, (char *)NULL);
break; break;
case 'i': /* wait between sending packets */ case 'i': /* wait between sending packets */
{ t = strtod(optarg, &ep) * 1000.0;
double t = strtod(optarg, &ep) * 1000.0; if (*ep || ep == optarg || t > (double)INT_MAX)
errx(EX_USAGE, "invalid timing interval: `%s'",
if (*ep || ep == optarg || t > (double)INT_MAX) { optarg);
errx( options |= F_INTERVAL;
EX_USAGE, interval = (int)t;
"invalid timing interval: `%s'", if (uid && interval < 1000) {
optarg errno = EPERM;
); err(EX_NOPERM, "-i interval too short");
}
options |= F_INTERVAL;
interval = (int)t;
if (uid && interval < 1000) {
errno = EPERM;
err(EX_NOPERM, "-i interval too short");
}
} }
break; break;
case 'I': /* multicast interface */ case 'I': /* multicast interface */
if (inet_aton(optarg, &ifaddr) == 0) if (inet_aton(optarg, &ifaddr) == 0)
errx(EX_USAGE, errx(EX_USAGE,
"invalid multicast interface: `%s'", "invalid multicast interface: `%s'",
optarg); optarg);
options |= F_MIF; options |= F_MIF;
break; break;
case 'l': case 'l':
ultmp = strtoul(optarg, &ep, 0); ultmp = strtoul(optarg, &ep, 0);
if (*ep || ep == optarg || ultmp > INT_MAX) if (*ep || ep == optarg || ultmp > INT_MAX)
errx(EX_USAGE, errx(EX_USAGE,
"invalid preload value: `%s'", optarg); "invalid preload value: `%s'", optarg);
if (uid) { if (uid) {
errno = EPERM; errno = EPERM;
err(EX_NOPERM, "-l flag"); err(EX_NOPERM, "-l flag");
@ -318,8 +312,7 @@ main(argc, argv)
case 'm': /* TTL */ case 'm': /* TTL */
ultmp = strtoul(optarg, &ep, 0); ultmp = strtoul(optarg, &ep, 0);
if (*ep || ep == optarg || ultmp > 255) if (*ep || ep == optarg || ultmp > 255)
errx(EX_USAGE, "invalid TTL: `%s'", errx(EX_USAGE, "invalid TTL: `%s'", optarg);
optarg);
ttl = ultmp; ttl = ultmp;
options |= F_TTL; options |= F_TTL;
break; break;
@ -350,10 +343,10 @@ main(argc, argv)
ultmp = strtoul(optarg, &ep, 0); ultmp = strtoul(optarg, &ep, 0);
if (ultmp > MAXPACKET) if (ultmp > MAXPACKET)
errx(EX_USAGE, "packet size too large: %lu", errx(EX_USAGE, "packet size too large: %lu",
ultmp); ultmp);
if (*ep || ep == optarg || !ultmp) if (*ep || ep == optarg || !ultmp)
errx(EX_USAGE, "invalid packet size: `%s'", errx(EX_USAGE, "invalid packet size: `%s'",
optarg); optarg);
datalen = ultmp; datalen = ultmp;
break; break;
case 'S': case 'S':
@ -373,7 +366,7 @@ main(argc, argv)
ultmp = strtoul(optarg, &ep, 0); ultmp = strtoul(optarg, &ep, 0);
if (*ep || ep == optarg || ultmp > 255) if (*ep || ep == optarg || ultmp > 255)
errx(EX_USAGE, "invalid multicast TTL: `%s'", errx(EX_USAGE, "invalid multicast TTL: `%s'",
optarg); optarg);
mttl = ultmp; mttl = ultmp;
options |= F_MTTL; options |= F_MTTL;
break; break;
@ -411,15 +404,15 @@ main(argc, argv)
hp = gethostbyname2(source, AF_INET); hp = gethostbyname2(source, AF_INET);
if (!hp) if (!hp)
errx(EX_NOHOST, "cannot resolve %s: %s", errx(EX_NOHOST, "cannot resolve %s: %s",
source, hstrerror(h_errno)); source, hstrerror(h_errno));
sin.sin_len = sizeof sin; sin.sin_len = sizeof sin;
if (hp->h_length > sizeof(sin.sin_addr)) if (hp->h_length > sizeof(sin.sin_addr))
errx(1,"gethostbyname2: illegal address"); errx(1, "gethostbyname2: illegal address");
memcpy(&sin.sin_addr, hp->h_addr_list[0], memcpy(&sin.sin_addr, hp->h_addr_list[0],
sizeof (sin.sin_addr)); sizeof(sin.sin_addr));
(void)strncpy(snamebuf, hp->h_name, (void)strncpy(snamebuf, hp->h_name,
sizeof(snamebuf) - 1); sizeof(snamebuf) - 1);
snamebuf[sizeof(snamebuf) - 1] = '\0'; snamebuf[sizeof(snamebuf) - 1] = '\0';
shostname = snamebuf; shostname = snamebuf;
} }
@ -437,10 +430,10 @@ main(argc, argv)
hp = gethostbyname2(target, AF_INET); hp = gethostbyname2(target, AF_INET);
if (!hp) if (!hp)
errx(EX_NOHOST, "cannot resolve %s: %s", errx(EX_NOHOST, "cannot resolve %s: %s",
target, hstrerror(h_errno)); target, hstrerror(h_errno));
if (hp->h_length > sizeof(to->sin_addr)) if (hp->h_length > sizeof(to->sin_addr))
errx(1,"gethostbyname2 returned an illegal address"); errx(1, "gethostbyname2 returned an illegal address");
memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr); memcpy(&to->sin_addr, hp->h_addr_list[0], sizeof to->sin_addr);
(void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1); (void)strncpy(hnamebuf, hp->h_name, sizeof(hnamebuf) - 1);
hnamebuf[sizeof(hnamebuf) - 1] = '\0'; hnamebuf[sizeof(hnamebuf) - 1] = '\0';
@ -451,12 +444,12 @@ main(argc, argv)
errx(EX_USAGE, "-f and -i: incompatible options"); errx(EX_USAGE, "-f and -i: incompatible options");
if (options & F_FLOOD && IN_MULTICAST(ntohl(to->sin_addr.s_addr))) if (options & F_FLOOD && IN_MULTICAST(ntohl(to->sin_addr.s_addr)))
errx(EX_USAGE, errx(EX_USAGE,
"-f flag cannot be used with multicast destination"); "-f flag cannot be used with multicast destination");
if (options & (F_MIF | F_NOLOOP | F_MTTL) if (options & (F_MIF | F_NOLOOP | F_MTTL)
&& !IN_MULTICAST(ntohl(to->sin_addr.s_addr))) && !IN_MULTICAST(ntohl(to->sin_addr.s_addr)))
errx(EX_USAGE, errx(EX_USAGE,
"-I, -L, -T flags cannot be used with unicast destination"); "-I, -L, -T flags cannot be used with unicast destination");
if (datalen >= PHDR_LEN) /* can we time transfer */ if (datalen >= PHDR_LEN) /* can we time transfer */
timing = 1; timing = 1;
@ -491,7 +484,8 @@ main(argc, argv)
errx(EX_CONFIG, "%s", ipsec_strerror()); errx(EX_CONFIG, "%s", ipsec_strerror());
if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY, if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
buf, ipsec_get_policylen(buf)) < 0) buf, ipsec_get_policylen(buf)) < 0)
err(EX_CONFIG, "ipsec policy cannot be configured"); err(EX_CONFIG,
"ipsec policy cannot be configured");
free(buf); free(buf);
} }
@ -501,7 +495,8 @@ main(argc, argv)
errx(EX_CONFIG, "%s", ipsec_strerror()); errx(EX_CONFIG, "%s", ipsec_strerror());
if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY, if (setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
buf, ipsec_get_policylen(buf)) < 0) buf, ipsec_get_policylen(buf)) < 0)
err(EX_CONFIG, "ipsec policy cannot be configured"); err(EX_CONFIG,
"ipsec policy cannot be configured");
free(buf); free(buf);
} }
} }
@ -521,7 +516,7 @@ main(argc, argv)
err(EX_OSERR, "setsockopt IP_OPTIONS"); err(EX_OSERR, "setsockopt IP_OPTIONS");
#else #else
errx(EX_UNAVAILABLE, errx(EX_UNAVAILABLE,
"record route not available in this implementation"); "record route not available in this implementation");
#endif /* IP_OPTIONS */ #endif /* IP_OPTIONS */
} }
@ -886,14 +881,14 @@ pr_pack(buf, cc, from, tv)
if (*cp != *dp) { if (*cp != *dp) {
(void)printf("\nwrong data byte #%d should be 0x%x but was 0x%x", (void)printf("\nwrong data byte #%d should be 0x%x but was 0x%x",
i, *dp, *cp); i, *dp, *cp);
printf("\ncp:"); (void)printf("\ncp:");
cp = (u_char*)&icp->icmp_data[0]; cp = (u_char*)&icp->icmp_data[0];
for (i = 0; i < datalen; ++i, ++cp) { for (i = 0; i < datalen; ++i, ++cp) {
if ((i % 32) == 8) if ((i % 32) == 8)
(void)printf("\n\t"); (void)printf("\n\t");
(void)printf("%x ", *cp); (void)printf("%x ", *cp);
} }
printf("\ndp:"); (void)printf("\ndp:");
cp = &outpack[8]; cp = &outpack[8];
for (i = 0; i < datalen; ++i, ++cp) { for (i = 0; i < datalen; ++i, ++cp) {
if ((i % 32) == 8) if ((i % 32) == 8)
@ -912,7 +907,7 @@ pr_pack(buf, cc, from, tv)
* and ICMP type and ID. * and ICMP type and ID.
* *
* Only print all the error messages if we are running * Only print all the error messages if we are running
* as root to avoid leaking information not normally * as root to avoid leaking information not normally
* available to those not running as root. * available to those not running as root.
*/ */
#ifndef icmp_data #ifndef icmp_data
@ -955,11 +950,12 @@ pr_pack(buf, cc, from, tv)
l = (l<<8) + *++cp; l = (l<<8) + *++cp;
l = (l<<8) + *++cp; l = (l<<8) + *++cp;
if (l == 0) { if (l == 0) {
printf("\t0.0.0.0"); (void)printf("\t0.0.0.0");
} else { } else {
struct in_addr ina; struct in_addr ina;
ina.s_addr = ntohl(l); ina.s_addr = ntohl(l);
printf("\t%s", pr_addr(ina)); (void)printf("\t%s",
pr_addr(ina));
} }
hlen -= 4; hlen -= 4;
j -= 4; j -= 4;
@ -1001,11 +997,11 @@ pr_pack(buf, cc, from, tv)
l = (l<<8) + *++cp; l = (l<<8) + *++cp;
l = (l<<8) + *++cp; l = (l<<8) + *++cp;
if (l == 0) { if (l == 0) {
printf("\t0.0.0.0"); (void)printf("\t0.0.0.0");
} else { } else {
struct in_addr ina; struct in_addr ina;
ina.s_addr = ntohl(l); ina.s_addr = ntohl(l);
printf("\t%s", pr_addr(ina)); (void)printf("\t%s", pr_addr(ina));
} }
hlen -= 4; hlen -= 4;
i -= 4; i -= 4;
@ -1013,7 +1009,7 @@ pr_pack(buf, cc, from, tv)
if (i <= 0) if (i <= 0)
break; break;
if (j >= MAX_IPOPTLEN) { if (j >= MAX_IPOPTLEN) {
(void) printf("\t(truncated route)"); (void)printf("\t(truncated route)");
break; break;
} }
(void)putchar('\n'); (void)putchar('\n');
@ -1147,7 +1143,7 @@ finish()
(void)printf("-- somebody's printing up packets!"); (void)printf("-- somebody's printing up packets!");
else else
(void)printf("%d%% packet loss", (void)printf("%d%% packet loss",
(int) (((ntransmitted - nreceived) * 100) / (int)(((ntransmitted - nreceived) * 100) /
ntransmitted)); ntransmitted));
} }
(void)putchar('\n'); (void)putchar('\n');
@ -1155,8 +1151,8 @@ finish()
double n = nreceived + nrepeats; double n = nreceived + nrepeats;
double avg = tsum / n; double avg = tsum / n;
double vari = tsumsq / n - avg * avg; double vari = tsumsq / n - avg * avg;
printf("round-trip min/avg/max/stddev = " (void)printf(
"%.3f/%.3f/%.3f/%.3f ms\n", "round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\n",
tmin, avg, tmax, sqrt(vari)); tmin, avg, tmax, sqrt(vari));
} }
if (reset_kerninfo && tcgetattr(STDOUT_FILENO, &ts) != -1) { if (reset_kerninfo && tcgetattr(STDOUT_FILENO, &ts) != -1) {
@ -1420,9 +1416,9 @@ fill(bp, patp)
for (cp = patp; *cp; cp++) { for (cp = patp; *cp; cp++) {
if (!isxdigit(*cp)) if (!isxdigit(*cp))
errx(EX_USAGE, errx(EX_USAGE,
"patterns must be specified as hex digits"); "patterns must be specified as hex digits");
} }
ii = sscanf(patp, ii = sscanf(patp,
"%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x", "%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x%2x",
@ -1447,7 +1443,7 @@ fill(bp, patp)
static void static void
usage() usage()
{ {
fprintf(stderr, "%s\n%s\n%s\n", (void)fprintf(stderr, "%s\n%s\n%s\n",
"usage: ping [-QRadfnqrv] [-c count] [-i wait] [-l preload] [-m ttl]", "usage: ping [-QRadfnqrv] [-c count] [-i wait] [-l preload] [-m ttl]",
" [-p pattern] " " [-p pattern] "
#ifdef IPSEC #ifdef IPSEC