qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian


From: Laurent Vivier
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

Le lundi 31 décembre 2012 à 21:32 +0000, Peter Maydell a écrit :
> On 31 December 2012 19:38, Laurent Vivier <address@hidden> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]