From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpniC-0006s6-0L for qemu-devel@nongnu.org; Mon, 31 Dec 2012 17:20:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TpniA-0002oI-Vz for qemu-devel@nongnu.org; Mon, 31 Dec 2012 17:19:59 -0500 Received: from moutng.kundenserver.de ([212.227.126.171]:52992) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpniA-0002kO-MU for qemu-devel@nongnu.org; Mon, 31 Dec 2012 17:19:58 -0500 Message-ID: <1356992395.3199.25.camel@Quad> From: Laurent Vivier Date: Mon, 31 Dec 2012 23:19:55 +0100 In-Reply-To: References: <1356982680-12436-1-git-send-email-laurent@vivier.eu> <1356982680-12436-3-git-send-email-laurent@vivier.eu> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Riku Voipio , qemu-devel@nongnu.org Le lundi 31 d=C3=A9cembre 2012 =C3=A0 21:32 +0000, Peter Maydell a =C3=A9cr= it : > On 31 December 2012 19:38, Laurent Vivier wrote: > > @@ -1900,6 +1900,12 @@ static abi_long do_socket(int domain, int type, = int protocol) > > #endif > > if (domain =3D=3D PF_NETLINK) > > return -EAFNOSUPPORT; /* do not NETLINK socket connections pos= sible */ > > + if (type =3D=3D SOCK_PACKET) { > > + /* in this case, socket() needs a network endian short */ > > + protocol =3D tswapal(protocol); /* restore network endian long= */ > > + protocol =3D abi_ntohl(protocol); /* a host endian long */ > > + protocol =3D htons(protocol); /* network endian short */ > > + } >=20 > Are you sure this is correct for little endian guests? I've only > desk-checked it rather than running a test program, but it looks > to me like you end up passing the wrong value to socket(). I tried to find a solution working in every case. > Also it seems rather involved since we swap things three times and > have an entirely new abi_* function. Either I'm completely confused > or it should be enough to just have >=20 > if (type =3D=3D SOCK_PACKET) { > protocol =3D tswap16(protocol); > } works... sometime. In fact, work if target endianess is network endianess. Correct me if I'm wrong. target host little endian / big endian memory 00 00 00 03 protocol 03000000 tswap16 00000000 -> don't work tswapal() 00000003 abi_ntohl() 00000003 htons() 00000003 -> work big endian / little endian: memory 00 00 00 03 protocol 00000003 tswap16() 00000300 -> work tswapal() 03000000 abi_ntohl() 00000003 htons() 00000300 -> work little endian/little endian: memory: 00 00 00 03 (network endian) protocol : 03000000 tswap16() : 00000000 -> don't work tswapal() 03000000 abi_ntohl() 00000003 htons() 00000300 -> work big endian / big endian memory 00 00 00 03 protocol 00000003 tswap16() 00000003 -> work tswapal() 00000003 abi_ntohl() 00000003 htons() 00000003 -> work Laurent --=20 "Just play. Have fun. Enjoy the game." - Michael Jordan