From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Fix use of sockaddr_in Date: Sun, 14 May 2017 19:06:26 +0000 Message-ID: References: <83shk989r5.fsf@gnu.org> <20170513150837.31184-1-phst@google.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a114b33e44ef60a054f80a33b" X-Trace: blaine.gmane.org 1494788850 21737 195.159.176.226 (14 May 2017 19:07:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 14 May 2017 19:07:30 +0000 (UTC) Cc: Philipp Stephani , emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun May 14 21:07:25 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d9yrS-0005UA-H6 for ged-emacs-devel@m.gmane.org; Sun, 14 May 2017 21:07:22 +0200 Original-Received: from localhost ([::1]:33640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9yrY-0005RX-0v for ged-emacs-devel@m.gmane.org; Sun, 14 May 2017 15:07:28 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d9yqq-0005RP-UQ for emacs-devel@gnu.org; Sun, 14 May 2017 15:06:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d9yql-0001xX-2S for emacs-devel@gnu.org; Sun, 14 May 2017 15:06:44 -0400 Original-Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:35524) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d9yqk-0001x2-Rk for emacs-devel@gnu.org; Sun, 14 May 2017 15:06:38 -0400 Original-Received: by mail-wm0-x234.google.com with SMTP id b84so60721232wmh.0 for ; Sun, 14 May 2017 12:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=wzZxfsGWE2dBDLvQIRDhFbiq+XzB/D2Tno2QvO+hJAI=; b=Fv2pABWQHJS6Acr2XYhmqNF6xJ1+vatc7hjD2T13iYj3WQe+1H2nz532SVteUYlS4L CAPLStLOfxEfb+Wh1coBI8uoHKhqqVuWX/FTGjrSPXslLi8oOrcNYj2Ks10L9iJzuxkp pc7jgbdtAkMNUISVScFwsWNz9ApTuRfsuxwZEibuyRTOL+LRpuVSevxvHGFvC9rPqyI5 oDNmCXUrI7rDGQSPG6gHv08dxdJsDWKJHNR+9Tfr+EfFfMPds4893gbzMMenEHAYNx1B A7x4y1GMoh6CyjTvT5j7Ite8smZ7p2cYMI7Dt/8HBeBL1VNxfQkHSGE+ApZeaPrDZ1Uh HW0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wzZxfsGWE2dBDLvQIRDhFbiq+XzB/D2Tno2QvO+hJAI=; b=rbe7uGbcjjNo/x2voHyh3vruE3SxE8Io2lC9fomjYWibx2c5fjJSR6zMiCSfa8Nvv6 WjOjFhNdjiWEXpxanD5ZPEIY6rgId8VuHY1+Iy4GBAQKPuxO60wpfdC82oWRaeOr0HSk eh/KSI+VF/XnaYpHyLwpC1tOSVudK9Ae5qLbtRQWkBMOEefOhtXXERVXZ5VROPlIjS7F pQiKtSBNo9zJblx517s1fJOZF9SFhTJ8dj2xiDP/dMJ8X/x49hfFGNe89kcXzSwPF5Kr Dhu8Wrtqkm7QFzQehihQhqoNj+9KDw26lbaroEQRQm4GQ9qoxbtqdws6xNvKLgEM8AsX gkVw== X-Gm-Message-State: AODbwcCDjM1NXqE4Kgu01PZEdnepvj4aG0vEXP2W7aTOIPlHenYZIWYs ib5dZZexAhgTJi2WFlnoomjLmSngmA== X-Received: by 10.28.150.86 with SMTP id y83mr1695770wmd.46.1494788797820; Sun, 14 May 2017 12:06:37 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::234 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214845 Archived-At: --001a114b33e44ef60a054f80a33b Content-Type: text/plain; charset="UTF-8" Lars Ingebrigtsen schrieb am So., 14. Mai 2017 um 12:28 Uhr: > Philipp Stephani writes: > > > + case AF_INET: > > + port = ((struct sockaddr_in6 *) (struct sockaddr > *) &sa1)->sin6_port; > > + has_port = true; > > + break; > > + case AF_INET6: > > + port = ((struct sockaddr_in *) (struct sockaddr > *) &sa1)->sin_port; > > + has_port = true; > > Aren't these two cases in reverse? If it's AF_INET6, it's an in6 > struct, not the other way around. > Oops, thanks! > > Not that it matters, since (as Eli said) the sizes of the first elements > in the structs are identical... > > I don't know whether we can rely on that (i.e. whether Posix guarantees it) or whether it's an implementation detail. (This also needs __attribute__((may_alias)), type punning, or memcpy due to aliasing.) --001a114b33e44ef60a054f80a33b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Lars I= ngebrigtsen <larsi@gnus.org> sc= hrieb am So., 14. Mai 2017 um 12:28=C2=A0Uhr:
Philipp Stephani <p.stephani2@gmail.com> writes:

> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= case AF_INET:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 port =3D ((struct sockaddr_in6 *) (struct sockaddr *) &sa1)->= ;sin6_port;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 has_port =3D true;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 break;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= case AF_INET6:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 port =3D ((struct sockaddr_in *) (struct sockaddr *) &sa1)->= sin_port;
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 has_port =3D true;

Aren't these two cases in reverse?=C2=A0 If it's AF_INET6, it's= an in6
struct, not the other way around.

Oops,= thanks!
=C2=A0

Not that it matters, since (as Eli said) the sizes of the first elements in the structs are identical...


I don't know whether we can rely o= n that (i.e. whether Posix guarantees it) or whether it's an implementa= tion detail.
(This also needs __attribute__((may_alias)), type pu= nning, or memcpy due to aliasing.)
--001a114b33e44ef60a054f80a33b--