Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/ping Adjust default packet size to 56 data bytes (64 to...
details: https://anonhg.NetBSD.org/src/rev/cf74d93610b0
branches: trunk
changeset: 334658:cf74d93610b0
user: christos <christos%NetBSD.org@localhost>
date: Sat Nov 29 14:48:42 2014 +0000
description:
Adjust default packet size to 56 data bytes (64 total).
Make error messages consistent.
diffstat:
sbin/ping/ping.c | 108 ++++++++++++++++++++++++++++++------------------------
1 files changed, 60 insertions(+), 48 deletions(-)
diffs (truncated from 334 to 300 lines):
diff -r 543848b4d967 -r cf74d93610b0 sbin/ping/ping.c
--- a/sbin/ping/ping.c Sat Nov 29 13:23:48 2014 +0000
+++ b/sbin/ping/ping.c Sat Nov 29 14:48:42 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ping.c,v 1.108 2014/11/27 19:43:58 christos Exp $ */
+/* $NetBSD: ping.c,v 1.109 2014/11/29 14:48:42 christos Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -58,7 +58,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ping.c,v 1.108 2014/11/27 19:43:58 christos Exp $");
+__RCSID("$NetBSD: ping.c,v 1.109 2014/11/29 14:48:42 christos Exp $");
#endif
#include <stdio.h>
@@ -252,12 +252,12 @@
#endif
if (prog_init && prog_init() == -1)
- err(1, "init failed");
+ err(EXIT_FAILURE, "init failed");
if ((s = prog_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0)
- err(1, "Cannot create socket");
+ err(EXIT_FAILURE, "Cannot create socket");
if ((sloop = prog_socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) < 0)
- err(1, "Cannot create socket");
+ err(EXIT_FAILURE, "Cannot create socket");
/*
* sloop is never read on. This prevents packets from
@@ -267,7 +267,7 @@
warn("Cannot shutdown for read");
if (prog_setuid(prog_getuid()) == -1)
- err(1, "setuid");
+ err(EXIT_FAILURE, "setuid");
setprogname(argv[0]);
@@ -293,7 +293,9 @@
case 'c':
npackets = strtol(optarg, &p, 0);
if (*p != '\0' || npackets <= 0)
- errx(1, "Bad/invalid number of packets");
+ errx(EXIT_FAILURE,
+ "Bad/invalid number of packets: %s",
+ optarg);
break;
case 'D':
pingflags |= F_DF;
@@ -310,13 +312,14 @@
case 'i': /* wait between sending packets */
interval = strtod(optarg, &p);
if (*p != '\0' || interval <= 0)
- errx(1, "Bad/invalid interval %s", optarg);
+ errx(EXIT_FAILURE, "Bad/invalid interval: %s",
+ optarg);
break;
case 'l':
preload = strtol(optarg, &p, 0);
if (*p != '\0' || preload < 0)
- errx(1, "Bad/invalid preload value %s",
- optarg);
+ errx(EXIT_FAILURE, "Bad/invalid preload value: "
+ "%s", optarg);
break;
case 'n':
pingflags |= F_NUMERIC;
@@ -326,13 +329,15 @@
break;
case 'p': /* fill buffer with user pattern */
if (pingflags & F_PING_RANDOM)
- errx(1, "Only one of -P and -p allowed");
+ errx(EXIT_FAILURE,
+ "Only one of -P and -p allowed");
pingflags |= F_PING_FILLED;
fill_pat = optarg;
break;
case 'P':
if (pingflags & F_PING_FILLED)
- errx(1, "Only one of -P and -p allowed");
+ errx(EXIT_FAILURE,
+ "Only one of -P and -p allowed");
pingflags |= F_PING_RANDOM;
break;
case 'q':
@@ -347,9 +352,10 @@
case 's': /* size of packet to send */
l = strtol(optarg, &p, 0);
if (*p != '\0' || l < 0)
- errx(1, "Bad/invalid packet size %s", optarg);
+ errx(EXIT_FAILURE,
+ "Bad/invalid packet size: %s", optarg);
if (l > MAXPACKET)
- errx(1, "packet size is too large");
+ errx(EXIT_FAILURE, "packet size is too large");
len = (int)l;
break;
case 'v':
@@ -364,12 +370,13 @@
case 't':
tos = strtoul(optarg, &p, 0);
if (*p != '\0' || tos > 0xFF)
- errx(1, "bad tos value: %s", optarg);
+ errx(EXIT_FAILURE, "bad tos value: %s", optarg);
break;
case 'T':
l = strtol(optarg, &p, 0);
if (*p != '\0' || l > 255 || l <= 0)
- errx(1, "ttl out of range");
+ errx(EXIT_FAILURE, "ttl out of range: %s",
+ optarg);
ttl = (u_char)l; /* cannot check >255 otherwise */
break;
case 'I':
@@ -383,7 +390,8 @@
case 'w':
maxwait = strtod(optarg, &p);
if (*p != '\0' || maxwait <= 0)
- errx(1, "Bad/invalid maxwait time %s", optarg);
+ errx(EXIT_FAILURE, "Bad/invalid maxwait time: "
+ "%s", optarg);
break;
#ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC
@@ -392,13 +400,14 @@
if (!strncmp("in", optarg, 2)) {
policy_in = strdup(optarg);
if (!policy_in)
- err(1, "strdup");
+ err(EXIT_FAILURE, "strdup");
} else if (!strncmp("out", optarg, 3)) {
policy_out = strdup(optarg);
if (!policy_out)
- err(1, "strdup");
+ err(EXIT_FAILURE, "strdup");
} else
- errx(1, "invalid security policy");
+ errx(EXIT_FAILURE, "invalid security policy: "
+ "%s", optarg);
break;
#else
case 'A':
@@ -419,11 +428,12 @@
interval = (pingflags & F_FLOOD) ? FLOOD_INTVL : 1.0;
#ifndef sgi
if (pingflags & F_FLOOD && prog_getuid())
- errx(1, "Must be superuser to use -f");
+ errx(EXIT_FAILURE, "Must be superuser to use -f");
if (interval < 1.0 && prog_getuid())
- errx(1, "Must be superuser to use < 1 sec ping interval");
+ errx(EXIT_FAILURE, "Must be superuser to use < 1 sec "
+ "ping interval");
if (preload > 0 && prog_getuid())
- errx(1, "Must be superuser to use -l");
+ errx(EXIT_FAILURE, "Must be superuser to use -l");
#endif
sec_to_timespec(interval, &interval_tv);
@@ -458,7 +468,7 @@
if (len != -1)
datalen = len;
else
- datalen = 64;
+ datalen = 64 - PHDR_LEN;
if (!compat && datalen >= (int)PHDR64_LEN) { /* can we time them? */
pingflags |= F_TIMING64;
phdrlen = PHDR64_LEN;
@@ -470,7 +480,7 @@
packlen = datalen + 60 + 76; /* MAXIP + MAXICMP */
if ((packet = malloc(packlen)) == NULL)
- err(1, "Out of memory");
+ err(EXIT_FAILURE, "Can't allocate %d bytes", packlen);
if (pingflags & F_PING_FILLED) {
fill();
@@ -525,9 +535,9 @@
- optlen);
(void) memcpy(opack_ip + 1, optspace, optlen);
- if (prog_setsockopt(s,IPPROTO_IP,IP_HDRINCL,
+ if (prog_setsockopt(s, IPPROTO_IP, IP_HDRINCL,
(char *) &on, sizeof(on)) < 0)
- err(1, "Can't set special IP header");
+ err(EXIT_FAILURE, "Can't set special IP header");
opack_ip->ip_v = IPVERSION;
opack_ip->ip_hl = (sizeof(struct ip)+optlen) >> 2;
@@ -544,25 +554,25 @@
if (prog_setsockopt(s, IPPROTO_IP,
IP_MULTICAST_LOOP,
(char *) &loop, 1) < 0)
- err(1, "Can't disable multicast loopback");
+ err(EXIT_FAILURE, "Can't disable multicast loopback");
}
if (ttl != 0
&& prog_setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL,
(char *) &ttl, 1) < 0)
- err(1, "Can't set multicast time-to-live");
+ err(EXIT_FAILURE, "Can't set multicast time-to-live");
if ((pingflags & F_SOURCE_ADDR)
&& prog_setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
(char *) &src_addr.sin_addr,
sizeof(src_addr.sin_addr)) < 0)
- err(1, "Can't set multicast source interface");
+ err(EXIT_FAILURE, "Can't set multicast source interface");
} else if (pingflags & F_SOURCE_ADDR) {
if (prog_setsockopt(s, IPPROTO_IP, IP_MULTICAST_IF,
(char *) &src_addr.sin_addr,
sizeof(src_addr.sin_addr)) < 0)
- err(1, "Can't set source interface/address");
+ err(EXIT_FAILURE, "Can't set source interface/address");
}
#ifdef IPSEC
#ifdef IPSEC_POLICY_IPSEC
@@ -572,27 +582,29 @@
if (policy_in != NULL) {
buf = ipsec_set_policy(policy_in, strlen(policy_in));
if (buf == NULL)
- errx(1, "%s", ipsec_strerror());
+ errx(EXIT_FAILURE, "%s", ipsec_strerror());
if (prog_setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
buf, ipsec_get_policylen(buf)) < 0) {
- err(1, "ipsec policy cannot be configured");
+ err(EXIT_FAILURE, "ipsec policy cannot be "
+ "configured");
}
free(buf);
}
if (policy_out != NULL) {
buf = ipsec_set_policy(policy_out, strlen(policy_out));
if (buf == NULL)
- errx(1, "%s", ipsec_strerror());
+ errx(EXIT_FAILURE, "%s", ipsec_strerror());
if (prog_setsockopt(s, IPPROTO_IP, IP_IPSEC_POLICY,
buf, ipsec_get_policylen(buf)) < 0) {
- err(1, "ipsec policy cannot be configured");
+ err(EXIT_FAILURE, "ipsec policy cannot be "
+ "configured");
}
free(buf);
}
}
buf = ipsec_set_policy("out bypass", strlen("out bypass"));
if (buf == NULL)
- errx(1, "%s", ipsec_strerror());
+ errx(EXIT_FAILURE, "%s", ipsec_strerror());
if (prog_setsockopt(sloop, IPPROTO_IP, IP_IPSEC_POLICY,
buf, ipsec_get_policylen(buf)) < 0) {
#if 0
@@ -646,7 +658,7 @@
while (0 > prog_setsockopt(s, SOL_SOCKET, SO_RCVBUF,
(char*)&bufspace, sizeof(bufspace))) {
if ((bufspace -= 4096) <= 0)
- err(1, "Cannot set the receive buffer size");
+ err(EXIT_FAILURE, "Cannot set the receive buffer size");
}
/* make it possible to send giant probes, but do not worry now
@@ -736,7 +748,7 @@
if (errno == EINTR)
continue;
jiggle_flush(1);
- err(1, "poll");
+ err(EXIT_FAILURE, "poll");
}
continue;
}
@@ -852,9 +864,9 @@
opack_icmp.icmp_cksum = in_cksum((u_int16_t *)&opack_icmp,
phdrlen);
sw = 0;
- if (prog_setsockopt(sloop,IPPROTO_IP,IP_HDRINCL,
- (char *)&sw,sizeof(sw)) < 0)
- err(1, "Can't turn off special IP header");
+ if (prog_setsockopt(sloop, IPPROTO_IP, IP_HDRINCL,
+ (char *)&sw, sizeof(sw)) < 0)
+ err(EXIT_FAILURE, "Can't turn off special IP header");
if (prog_sendto(sloop, (char *) &opack_icmp,
ICMP_MINLEN, MSG_DONTROUTE,
(struct sockaddr *)&loc_addr,
@@ -869,9 +881,9 @@
warn("failed to clear cached route");
}
sw = 1;
- if (prog_setsockopt(sloop,IPPROTO_IP,IP_HDRINCL,
+ if (prog_setsockopt(sloop, IPPROTO_IP, IP_HDRINCL,
(char *)&sw, sizeof(sw)) < 0)
- err(1, "Can't set special IP header");
+ err(EXIT_FAILURE, "Can't set special IP header");
(void)clock_gettime(CLOCK_MONOTONIC, &clear_cache);
Home |
Main Index |
Thread Index |
Old Index