From patchwork Wed May 20 16:27:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Ellcey X-Patchwork-Id: 474567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 06F4714027F for ; Thu, 21 May 2015 02:30:38 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=sourceware.org header.i=@sourceware.org header.b=Eem3/EnK; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:subject:from:reply-to:to:cc:date :in-reply-to:references:content-type:content-transfer-encoding :mime-version; q=dns; s=default; b=B7OgBpZPkqZrqTwQKPmB0GQWUv2Lh Ysq3R6qF15YSIGAYzD2i4tzr5qpLoU6IrQ28Ku3GbsIcWkuM5mXJ4lGb7wjacGDP vibDyR08ZX2UlRmIdHK2xZkKYZOt97XT1Rm1YO18GmJQJu7ueTtSyHsV+EUKVnf1 0ZGi+fy60e7XVg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:message-id:subject:from:reply-to:to:cc:date :in-reply-to:references:content-type:content-transfer-encoding :mime-version; s=default; bh=q/JtDeXY2c7Ckwjzf5VGKaY+LoE=; b=Eem 3/EnKBjymIhBPmdmsoEHE3yjlKtSlSb0QFBsNRRTLanmodCjvfOUTTUDZbsgetGX hgcQrHHG31zveUlf6RwhK2n8dDKlxCOSTFe1ALi6+6OZYsyLMjklXbIGQDRaJxD/ YEMV0QHNHObzkWqeVKJ22doDBPifjFFN5MZZAfuY= Received: (qmail 88257 invoked by alias); 20 May 2015 16:30:33 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 88240 invoked by uid 89); 20 May 2015 16:30:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_40, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mailapp01.imgtec.com Message-ID: <1432139240.16668.77.camel@ubuntu-sellcey> Subject: Re: [PATCH] Fix strict-aliasing warning in resolv/res_hconf.c From: Steve Ellcey Reply-To: To: Florian Weimer CC: Andreas Schwab , Roland McGrath , Paul Eggert , Date: Wed, 20 May 2015 09:27:20 -0700 In-Reply-To: <555C48F0.2030208@redhat.com> References: <5bfa6373-3817-4d31-a5ee-a8676e79b723@BAMAIL02.ba.imgtec.org> <555BB55E.3050304@cs.ucla.edu> <1432075989.16668.62.camel@ubuntu-sellcey> <555BC19B.90001@cs.ucla.edu> <1432077972.16668.65.camel@ubuntu-sellcey> <20150519235817.9516F2C3A73@topped-with-meat.com> <555C3E0B.2040404@redhat.com> <555C48F0.2030208@redhat.com> MIME-Version: 1.0 On Wed, 2015-05-20 at 10:42 +0200, Florian Weimer wrote: > On 05/20/2015 10:23 AM, Andreas Schwab wrote: > > Florian Weimer writes: > > > >> Looking at struct ifreq, it is rather mysterious to me how this is > >> supposed to work at all. I mean, struct sockaddr has just 14 bytes > >> storage for address information, but IPv6 addresses need 16 bytes, and > >> socket addresses contain even more information than a raw address. > > > > This ioctl is only defined for IPv4. > > Oh, but then we can add a union member of the appropriate type (just one > is needed): > > diff --git a/sysdeps/gnu/net/if.h b/sysdeps/gnu/net/if.h > index 49a048c..39f40de 100644 > --- a/sysdeps/gnu/net/if.h > +++ b/sysdeps/gnu/net/if.h > @@ -24,6 +24,7 @@ > #ifdef __USE_MISC > # include > # include > +# include > #endif > > > @@ -139,6 +140,7 @@ struct ifreq > struct sockaddr ifru_broadaddr; > struct sockaddr ifru_netmask; > struct sockaddr ifru_hwaddr; > + struct sockaddr_in ifru_addr_in; > short int ifru_flags; > int ifru_ivalue; > int ifru_mtu; > > > This doesn't change ABI. And then the code in resolv/res_hconf.c could > use that new member, without any casts. I don't know if this change is going to be considered acceptable or not but here is a complete patch with the new union member, a macro definition to access it (in order to match the other union members) and the needed change to resolv/res_hconf.c. Steve Ellcey sellcey@imgtec.com 2015-05-20 Steve Ellcey Florian Weimer * resolv/res_hconf.c (_res_hconf_reorder_addrs): Use new ifr_addr_in name to access address. * sysdeps/gnu/net/if.h (struct ifreq): Add new ifru_addr_in union member. (ifr_addr_in): New macro. diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c index 73942e8..3b05287 100644 --- a/resolv/res_hconf.c +++ b/resolv/res_hconf.c @@ -444,13 +444,13 @@ _res_hconf_reorder_addrs (struct hostent *hp) ifaddrs[new_num_ifs].addrtype = AF_INET; ifaddrs[new_num_ifs].u.ipv4.addr = - ((struct sockaddr_in *) &cur_ifr->ifr_addr)->sin_addr.s_addr; + cur_ifr->ifr_addr_in.sin_addr.s_addr; if (__ioctl (sd, SIOCGIFNETMASK, cur_ifr) < 0) continue; ifaddrs[new_num_ifs].u.ipv4.mask = - ((struct sockaddr_in *) &cur_ifr->ifr_netmask)->sin_addr.s_addr; + cur_ifr->ifr_addr_in.sin_addr.s_addr; /* Now we're committed to this entry. */ ++new_num_ifs; diff --git a/sysdeps/gnu/net/if.h b/sysdeps/gnu/net/if.h index 49a048c..b741d14 100644 --- a/sysdeps/gnu/net/if.h +++ b/sysdeps/gnu/net/if.h @@ -24,6 +24,7 @@ #ifdef __USE_MISC # include # include +# include #endif @@ -139,6 +140,7 @@ struct ifreq struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; + struct sockaddr_in ifru_addr_in; short int ifru_flags; int ifru_ivalue; int ifru_mtu; @@ -151,6 +153,7 @@ struct ifreq # define ifr_name ifr_ifrn.ifrn_name /* interface name */ # define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ # define ifr_addr ifr_ifru.ifru_addr /* address */ +# define ifr_addr_in ifr_ifru.ifru_addr_in /* sockaddr_in address */ # define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-p lnk */ # define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ # define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */