From: Laurent Vivier <Laurent@vivier.eu>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Riku Voipio <riku.voipio@iki.fi>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()
Date: Mon, 31 Dec 2012 23:19:55 +0100 [thread overview]
Message-ID: <1356992395.3199.25.camel@Quad> (raw)
In-Reply-To: <CAFEAcA-=x91ZRYzKVw6iq33X97epyfurOKcd_Bc3t2eW4drvuw@mail.gmail.com>
Le lundi 31 décembre 2012 à 21:32 +0000, Peter Maydell a écrit :
> On 31 December 2012 19:38, Laurent Vivier <laurent@vivier.eu> wrote:
> > @@ -1900,6 +1900,12 @@ static abi_long do_socket(int domain, int type, int protocol)
> > #endif
> > if (domain == PF_NETLINK)
> > return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */
> > + if (type == SOCK_PACKET) {
> > + /* in this case, socket() needs a network endian short */
> > + protocol = tswapal(protocol); /* restore network endian long */
> > + protocol = abi_ntohl(protocol); /* a host endian long */
> > + protocol = htons(protocol); /* network endian short */
> > + }
>
> 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
>
> if (type == SOCK_PACKET) {
> protocol = 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
--
"Just play. Have fun. Enjoy the game."
- Michael Jordan
next prev parent reply other threads:[~2012-12-31 22:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-31 19:37 [Qemu-devel] [PATCH 0/2] linux-user: dhclient support Laurent Vivier
2012-12-31 19:37 ` [Qemu-devel] [PATCH 1/2] linux-user: Add setsockopt(SO_ATTACH_FILTER) Laurent Vivier
2012-12-31 20:56 ` Peter Maydell
2012-12-31 19:38 ` [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Laurent Vivier
2012-12-31 21:32 ` Peter Maydell
2012-12-31 22:19 ` Laurent Vivier [this message]
2013-01-01 15:03 ` Peter Maydell
2013-01-01 17:27 ` Laurent Vivier
2013-01-01 18:37 ` Laurent Vivier
2013-01-01 19:45 ` Peter Maydell
2013-01-01 22:12 ` Laurent Vivier
2013-01-01 22:50 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1356992395.3199.25.camel@Quad \
--to=laurent@vivier.eu \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.