diff options
author | Florian Obser <florian@cvs.openbsd.org> | 2016-09-17 09:30:01 +0000 |
---|---|---|
committer | Florian Obser <florian@cvs.openbsd.org> | 2016-09-17 09:30:01 +0000 |
commit | 91992dc2e747ba5b513cbe9f2991d91690d4f49e (patch) | |
tree | af30879eeb4a513e53e8b8af2dc0e8595adb65ec | |
parent | 740c2bb38301b5a405aa30c4de760d0f47cde49b (diff) |
Use AF independent dst where possible.
-rw-r--r-- | sbin/ping/ping.c | 13 | ||||
-rw-r--r-- | sbin/ping6/ping6.c | 13 |
2 files changed, 14 insertions, 12 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index f45ff74fc80..0a37e4fdf81 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping.c,v 1.194 2016/09/17 09:29:27 florian Exp $ */ +/* $OpenBSD: ping.c,v 1.195 2016/09/17 09:30:00 florian Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -224,6 +224,7 @@ main(int argc, char *argv[]) { struct addrinfo hints, *res; struct itimerval itimer; + struct sockaddr *dst; struct sockaddr_in from4, dst4; socklen_t maxsizelen; int64_t preload; @@ -407,6 +408,7 @@ main(int argc, char *argv[]) case AF_INET: if (res->ai_addrlen != sizeof(dst4)) errx(1, "size of sockaddr mismatch"); + dst = (struct sockaddr *)&dst4; break; case AF_INET6: default: @@ -414,7 +416,7 @@ main(int argc, char *argv[]) break; } - memcpy(&dst4, res->ai_addr, res->ai_addrlen); + memcpy(dst, res->ai_addr, res->ai_addrlen); if (!hostname) { hostname = res->ai_canonname ? strdup(res->ai_canonname) : @@ -612,11 +614,10 @@ main(int argc, char *argv[]) if (0 && (options & F_VERBOSE)) printf("%s --> ", pr_addr((struct sockaddr *)&from4, sizeof(from4))); - printf("%s): %d data bytes\n", pr_addr((struct sockaddr *)&dst4, - sizeof(dst4)), datalen); + printf("%s): %d data bytes\n", pr_addr(dst, dst->sa_len), datalen); - smsghdr.msg_name = &dst4; - smsghdr.msg_namelen = sizeof(dst4); + smsghdr.msg_name = dst; + smsghdr.msg_namelen = dst->sa_len; smsgiov.iov_base = (caddr_t)outpack; smsghdr.msg_iov = &smsgiov; smsghdr.msg_iovlen = 1; diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index 1118a0a5eb2..9e192f7395f 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.210 2016/09/17 09:29:27 florian Exp $ */ +/* $OpenBSD: ping6.c,v 1.211 2016/09/17 09:30:00 florian Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -222,6 +222,7 @@ main(int argc, char *argv[]) { struct addrinfo hints, *res; struct itimerval itimer; + struct sockaddr *dst; struct sockaddr_in6 from6, dst6; struct cmsghdr *scmsg = NULL; struct in6_pktinfo *pktinfo = NULL; @@ -388,6 +389,7 @@ main(int argc, char *argv[]) case AF_INET6: if (res->ai_addrlen != sizeof(dst6)) errx(1, "size of sockaddr mismatch"); + dst = (struct sockaddr *)&dst6; break; case AF_INET: default: @@ -395,7 +397,7 @@ main(int argc, char *argv[]) break; } - memcpy(&dst6, res->ai_addr, res->ai_addrlen); + memcpy(dst, res->ai_addr, res->ai_addrlen); if (!hostname) { hostname = res->ai_canonname ? strdup(res->ai_canonname) : @@ -620,11 +622,10 @@ main(int argc, char *argv[]) if (options & F_VERBOSE) printf("%s --> ", pr_addr((struct sockaddr *)&from6, sizeof(from6))); - printf("%s): %d data bytes\n", pr_addr((struct sockaddr *)&dst6, - sizeof(dst6)), datalen); + printf("%s): %d data bytes\n", pr_addr(dst, dst->sa_len), datalen); - smsghdr.msg_name = &dst6; - smsghdr.msg_namelen = sizeof(dst6); + smsghdr.msg_name = dst; + smsghdr.msg_namelen = dst->sa_len; smsgiov.iov_base = (caddr_t)outpack; smsghdr.msg_iov = &smsgiov; smsghdr.msg_iovlen = 1; |