From: Ben Hutchings <bhutchings@solarflare.com>
To: Kevin Wilson <wkevils@gmail.com>
Cc: netdev@vger.kernel.org
Subject: Re: ntohs() and htons() usgae in the network stack
Date: Wed, 10 Jun 2009 15:24:12 +0100 [thread overview]
Message-ID: <1244643852.2848.6.camel@achroite> (raw)
In-Reply-To: <55c333c0906100708q1b0be2ffkc80c2f3258f0e681@mail.gmail.com>
On Wed, 2009-06-10 at 17:08 +0300, Kevin Wilson wrote:
> Hello,
> I will appreciate if someone can explain this mystery to me:
>
> While debugging some kernel module, I added printing of ports.
> I had printer both ntohs() and htons() of a port number. I got the same
> values.
[...]
Yes, these functions have exactly the same effect on the bits of the
value. But "16-bit unsigned value in host order" (u16) and "16-bit
unsigned value in network order" (__be16) should be considered as two
different types, requiring different functions for conversion each way.
The "sparse" static analyser can treat them as separate types and can
catch missing conversions. If we used a single conversion function this
would not be possible.
Ben.
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
prev parent reply other threads:[~2009-06-10 14:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-10 14:08 ntohs() and htons() usgae in the network stack Kevin Wilson
2009-06-10 14:10 ` Florian Weimer
2009-06-10 14:24 ` Ben Hutchings [this message]
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=1244643852.2848.6.camel@achroite \
--to=bhutchings@solarflare.com \
--cc=netdev@vger.kernel.org \
--cc=wkevils@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).