-/* $OpenBSD: ping6.c,v 1.121 2015/10/12 18:32:18 deraadt Exp $ */
+/* $OpenBSD: ping6.c,v 1.122 2015/10/13 16:26:54 florian Exp $ */
/* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */
/*
struct itimerval itimer;
struct sockaddr_in6 from;
struct addrinfo hints;
- int ch, i, packlen, preload, optval, error;
+ int ch, i, maxsize, packlen, preload, optval, error;
+ socklen_t maxsizelen;
u_char *datap, *packet;
char *e, *target, *ifname = NULL, *gateway = NULL;
const char *errstr;
int ip6optlen = 0;
struct cmsghdr *scmsgp = NULL;
- u_long lsockbufsize;
- int sockbufsize = 0;
int usepktinfo = 0;
struct in6_pktinfo *pktinfo = NULL;
double intval;
preload = 0;
datap = &outpack[ICMP6ECHOLEN + ICMP6ECHOTMLEN];
while ((ch = getopt(argc, argv,
- "a:b:c:dEefHg:h:I:i:l:mnNp:qS:s:tvV:w")) != -1) {
+ "a:c:dEefHg:h:I:i:l:mnNp:qS:s:tvV:w")) != -1) {
switch (ch) {
case 'a':
{
}
break;
}
- case 'b':
- errno = 0;
- e = NULL;
- lsockbufsize = strtoul(optarg, &e, 10);
- sockbufsize = lsockbufsize;
- if (errno || !*optarg || *e ||
- sockbufsize != lsockbufsize)
- errx(1, "invalid socket buffer size");
- break;
case 'c':
npackets = strtonum(optarg, 0, INT_MAX, &errstr);
if (errstr)
if (!(packet = malloc(packlen)))
err(1, "Unable to allocate packet");
+
+ /*
+ * When trying to send large packets, you must increase the
+ * size of both the send and receive buffers...
+ */
+ maxsizelen = sizeof maxsize;
+ if (getsockopt(s, SOL_SOCKET, SO_SNDBUF, &maxsize, &maxsizelen) < 0)
+ err(1, "getsockopt");
+ if (maxsize < packlen &&
+ setsockopt(s, SOL_SOCKET, SO_SNDBUF, &packlen, sizeof(maxsize)) < 0)
+ err(1, "setsockopt");
+
+ if (getsockopt(s, SOL_SOCKET, SO_RCVBUF, &maxsize, &maxsizelen) < 0)
+ err(1, "getsockopt");
+ if (maxsize < packlen &&
+ setsockopt(s, SOL_SOCKET, SO_RCVBUF, &packlen, sizeof(maxsize)) < 0)
+ err(1, "setsockopt");
+
if (!(options & F_PINGFILLED))
for (i = ICMP6ECHOLEN; i < packlen; ++i)
*datap++ = i;
close(dummy);
}
- if (sockbufsize) {
- if (datalen > sockbufsize)
- warnx("you need -b to increase socket buffer size");
- if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, &sockbufsize,
- (socklen_t)sizeof(sockbufsize)) < 0)
- err(1, "setsockopt(SO_SNDBUF)");
- if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &sockbufsize,
- (socklen_t)sizeof(sockbufsize)) < 0)
- err(1, "setsockopt(SO_RCVBUF)");
- } else {
- if (datalen > 8 * 1024) /*XXX*/
- warnx("you need -b to increase socket buffer size");
- /*
- * When pinging the broadcast address, you can get a lot of
- * answers. Doing something so evil is useful if you are trying
- * to stress the ethernet, or just want to fill the arp cache
- * to get some stuff for /etc/ethers.
- */
- optval = 48 * 1024;
- setsockopt(s, SOL_SOCKET, SO_RCVBUF, &optval,
- (socklen_t)sizeof(optval));
- }
-
optval = 1;
if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVPKTINFO, &optval,
(socklen_t)sizeof(optval)) < 0)
"usage: ping6 [-dEefH"
"m"
"Nnqtvw"
- "] [-a addrtype] [-b bufsiz] [-c count] [-g gateway]\n\t"
+ "] [-a addrtype] [-c count] [-g gateway]\n\t"
"[-h hoplimit] [-I interface] [-i wait] [-l preload] [-p pattern]"
"\n\t[-S sourceaddr] [-s packetsize] [-V rtable] host\n");
exit(1);