Purpose of using __be16 inside a data structure?

Michael Blizek michi1 at michaelblizek.twilightparadox.com
Sun Aug 14 02:21:02 EDT 2011


Hi!

On 08:41 Sun 14 Aug     , ?????? wrote:
> Hi all,
> 
> Please tell me the difference between using unsigned short and __be16
> to declear a variable in a data structure.
> For example, in include/net/inet_sock.h, struct inet_sock is decleared as
> 
> struct inet_sock {
>         __be16                  inet_dport;
> };
> 
> not
> 
> struct inet_sock {
>         unsigned short                  inet_dport;
> };

This is mostly to avoid confusion about where byte order conversation has to
be done. When reading "unsigned short" you would normally expect the variable
to contain host byte order.

	-Michi
-- 
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com




More information about the Kernelnewbies mailing list