summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflorian <florian@openbsd.org>2015-11-04 20:10:15 +0000
committerflorian <florian@openbsd.org>2015-11-04 20:10:15 +0000
commit02ab83e9fdbc663d4a874a49d5981a4b31bb7c2e (patch)
tree452c16e8eeda9fa2fcae051aa896e2d68baf20ef
parentdead store; pointed out by llvm (diff)
downloadwireguard-openbsd-02ab83e9fdbc663d4a874a49d5981a4b31bb7c2e.tar.xz
wireguard-openbsd-02ab83e9fdbc663d4a874a49d5981a4b31bb7c2e.zip
Simplify packet option handling since we are only setting one option
these days.
-rw-r--r--sbin/ping6/ping6.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c
index c172737a088..efb9c9aead5 100644
--- a/sbin/ping6/ping6.c
+++ b/sbin/ping6/ping6.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ping6.c,v 1.136 2015/11/04 20:04:10 florian Exp $ */
+/* $OpenBSD: ping6.c,v 1.137 2015/11/04 20:10:15 florian Exp $ */
/* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */
/*
@@ -195,7 +195,6 @@ SIPHASH_KEY mac_key;
/* for ancillary data(advanced API) */
struct msghdr smsghdr;
struct iovec smsgiov;
-char *scmsg;
volatile sig_atomic_t seenalrm;
volatile sig_atomic_t seenint;
@@ -233,8 +232,7 @@ main(int argc, char *argv[])
u_char *datap, *packet;
char *e, *target;
const char *errstr;
- int ip6optlen = 0;
- struct cmsghdr *scmsgp = NULL;
+ struct cmsghdr *scmsg = NULL;
struct in6_pktinfo *pktinfo = NULL;
double intval;
int mflag = 0, loop = 1;
@@ -533,26 +531,17 @@ main(int argc, char *argv[])
err(1, "setsockopt(IPV6_RECVRTHDR)");
}
- if (hoplimit != -1)
- ip6optlen += CMSG_SPACE(sizeof(int));
-
-
- /* set IP6 packet options */
- if (ip6optlen) {
- if ((scmsg = malloc(ip6optlen)) == 0)
+ if (hoplimit != -1) {
+ /* set IP6 packet options */
+ if ((scmsg = malloc( CMSG_SPACE(sizeof(int)))) == 0)
errx(1, "can't allocate enough memory");
smsghdr.msg_control = (caddr_t)scmsg;
- smsghdr.msg_controllen = ip6optlen;
- scmsgp = (struct cmsghdr *)scmsg;
- }
-
- if (hoplimit != -1) {
- scmsgp->cmsg_len = CMSG_LEN(sizeof(int));
- scmsgp->cmsg_level = IPPROTO_IPV6;
- scmsgp->cmsg_type = IPV6_HOPLIMIT;
- *(int *)(CMSG_DATA(scmsgp)) = hoplimit;
+ smsghdr.msg_controllen = CMSG_SPACE(sizeof(int));
- scmsgp = CMSG_NXTHDR(&smsghdr, scmsgp);
+ scmsg->cmsg_len = CMSG_LEN(sizeof(int));
+ scmsg->cmsg_level = IPPROTO_IPV6;
+ scmsg->cmsg_type = IPV6_HOPLIMIT;
+ *(int *)(CMSG_DATA(scmsg)) = hoplimit;
}
if (!(options & F_SRCADDR) && options & F_VERBOSE) {