public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* ntohs() and htons() usgae in the network stack
@ 2009-06-10 14:08 Kevin Wilson
  2009-06-10 14:10 ` Florian Weimer
  2009-06-10 14:24 ` Ben Hutchings
  0 siblings, 2 replies; 3+ messages in thread
From: Kevin Wilson @ 2009-06-10 14:08 UTC (permalink / raw)
  To: netdev

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. Since I used low port number, I decided to find out from which
port there begins to be a difference. So I tried to write in a simple
kernel module this loop, which tests all ports up till 65536 (since
port number is 16 bit wide):
	...
	int i;
	for (i=0;i<65536;i++)
	 if (ntohs(i) != htons(i))
		printk("found inequality: ntohs(i) != htons(i)\n");

And when running it it did **not** find such a port where ntohs(i) !=
htons ( "found inequality:.. was **not** printed).

So I wondered : when is ntohs(i) != htons(i) ?
Are they always equal (I doubt it); or am I missing something silly here?

I am testing it on x86_64 Intel machine (little endian).
Rgs,
Kevin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-06-10 14:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox