aboutsummaryrefslogtreecommitdiffstats
path: root/sbin/ping
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-06 18:41:28 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-06 18:41:28 +0000
commita94c074d6a47ce64d75a9ce495f2de716b4c83f4 (patch)
treef43964a5a3af2f9544bff63dbffa9d3b3be777da /sbin/ping
parent172ae88fec8ff591810c46f24675ee52f120f2cc (diff)
downloadsrc-a94c074d6a47ce64d75a9ce495f2de716b4c83f4.tar.gz
src-a94c074d6a47ce64d75a9ce495f2de716b4c83f4.zip
Fix clang 4.0.0 warnings about taking the address of a packed member of
struct ip in ping(8): sbin/ping/ping.c:1684:53: error: taking address of packed member 'ip_src' of class or structure 'ip' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member] (void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_src.s_addr)); ^~~~~~~~~~~~~~~~~ sbin/ping/ping.c:1685:53: error: taking address of packed member 'ip_dst' of class or structure 'ip' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member] (void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_dst.s_addr)); ^~~~~~~~~~~~~~~~~ MFC after: 3 days
Notes
Notes: svn path=/head/; revision=311530
Diffstat (limited to 'sbin/ping')
-rw-r--r--sbin/ping/ping.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c
index db78ef606025..ab4764aa27d6 100644
--- a/sbin/ping/ping.c
+++ b/sbin/ping/ping.c
@@ -1666,6 +1666,7 @@ pr_icmph(struct icmp *icp)
static void
pr_iph(struct ip *ip)
{
+ struct in_addr ina;
u_char *cp;
int hlen;
@@ -1681,8 +1682,10 @@ pr_iph(struct ip *ip)
(u_long) ntohl(ip->ip_off) & 0x1fff);
(void)printf(" %02x %02x %04x", ip->ip_ttl, ip->ip_p,
ntohs(ip->ip_sum));
- (void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_src.s_addr));
- (void)printf(" %s ", inet_ntoa(*(struct in_addr *)&ip->ip_dst.s_addr));
+ memcpy(&ina, &ip->ip_src.s_addr, sizeof ina);
+ (void)printf(" %s ", inet_ntoa(ina));
+ memcpy(&ina, &ip->ip_dst.s_addr, sizeof ina);
+ (void)printf(" %s ", inet_ntoa(ina));
/* dump any option bytes */
while (hlen-- > 20) {
(void)printf("%02x", *cp++);