diff options
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ping/ping.c | 13 | ||||
-rw-r--r-- | sbin/ping6/ping6.c | 14 |
2 files changed, 12 insertions, 15 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index 158b38f9ca7..811ee4f1fda 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping.c,v 1.198 2016/09/17 09:32:54 florian Exp $ */ +/* $OpenBSD: ping.c,v 1.199 2016/09/17 09:33:32 florian Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -464,13 +464,12 @@ main(int argc, char *argv[]) * privilege, we cannot use a raw socket for this. */ int dummy; - socklen_t len = sizeof(from4); + socklen_t len = dst->sa_len; - if ((dummy = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + if ((dummy = socket(dst->sa_family, SOCK_DGRAM, 0)) < 0) err(1, "UDP socket"); - from4.sin_family = AF_INET; - from4.sin_addr = dst4.sin_addr; + memcpy(from, dst, dst->sa_len); from4.sin_port = ntohs(DUMMY_PORT); if ((moptions & MULTICAST_NOLOOP) && @@ -487,10 +486,10 @@ main(int argc, char *argv[]) sizeof(rtableid)) < 0) err(1, "setsockopt(SO_RTABLE)"); - if (connect(dummy, (struct sockaddr *)&from4, len) < 0) + if (connect(dummy, from, len) < 0) err(1, "UDP connect"); - if (getsockname(dummy, (struct sockaddr *)&from4, &len) < 0) + if (getsockname(dummy, from, &len) < 0) err(1, "getsockname"); close(dummy); diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index 76a0a966ff8..d078643d856 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.214 2016/09/17 09:32:54 florian Exp $ */ +/* $OpenBSD: ping6.c,v 1.215 2016/09/17 09:33:32 florian Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -434,15 +434,13 @@ main(int argc, char *argv[]) * privilege, we cannot use a raw socket for this. */ int dummy; - socklen_t len = sizeof(from6); + socklen_t len = dst->sa_len; - if ((dummy = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + if ((dummy = socket(dst->sa_family, SOCK_DGRAM, 0)) < 0) err(1, "UDP socket"); - from6.sin6_family = AF_INET6; - from6.sin6_addr = dst6.sin6_addr; + memcpy(from, dst, dst->sa_len); from6.sin6_port = ntohs(DUMMY_PORT); - from6.sin6_scope_id = dst6.sin6_scope_id; if (pktinfo && setsockopt(dummy, IPPROTO_IPV6, IPV6_PKTINFO, @@ -464,10 +462,10 @@ main(int argc, char *argv[]) sizeof(rtableid)) < 0) err(1, "setsockopt(SO_RTABLE)"); - if (connect(dummy, (struct sockaddr *)&from6, len) < 0) + if (connect(dummy, from, len) < 0) err(1, "UDP connect"); - if (getsockname(dummy, (struct sockaddr *)&from6, &len) < 0) + if (getsockname(dummy, from, &len) < 0) err(1, "getsockname"); close(dummy); |