Author: dim
Date: Fri Jan  6 18:41:28 2017
New Revision: 311530
URL: https://svnweb.freebsd.org/changeset/base/311530

Log:
  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

Modified:
  head/sbin/ping/ping.c

Modified: head/sbin/ping/ping.c
==============================================================================
--- head/sbin/ping/ping.c       Fri Jan  6 18:08:53 2017        (r311529)
+++ head/sbin/ping/ping.c       Fri Jan  6 18:41:28 2017        (r311530)
@@ -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++);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to