linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Use of htons function
@ 2004-09-20 16:08 Ronaldo Zacarias Afonso
  2004-09-20 16:41 ` Luciano Moreira - igLnx
  0 siblings, 1 reply; 3+ messages in thread
From: Ronaldo Zacarias Afonso @ 2004-09-20 16:08 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Mail message body --]
[-- Type: text/plain, Size: 452 bytes --]

  Hello all, 

  Some one could tell me what the function "htons" realy does? Where can I 
use it? 
  I tryed to find its purpose in the "man htons", but it seems a little bit 
confusing. 
  Thanks. 

_________________________________________________________________________________
Quer mais velocidade?
Só com o acesso Aditivado iG, a velocidade que você quer na hora que você precisa.
Clique aqui: http://www.acessoaditivado.ig.com.br


^ permalink raw reply	[flat|nested] 3+ messages in thread
* RE: Use of htons function
@ 2004-09-20 18:14 Huber, George K RDECOM CERDEC STCD SRI
  0 siblings, 0 replies; 3+ messages in thread
From: Huber, George K RDECOM CERDEC STCD SRI @ 2004-09-20 18:14 UTC (permalink / raw)
  To: linux-c-programming

Ronaldo wrote:

>  Some one could tell me what the function "htons" realy does? Where can I 
>  use it? I tryed to find its purpose in the "man htons", but it seems a
little 
>  bit confusing. 

`htons' (host to network short) converts a short from the native byte-order
for 
platform to the "network byte-order".  The TCP/IP standard specifies 
that the network byte-order will be big-endian (i.e. the most significant
byte of
a mult-byte value will be stored in the lowest memory addrss).  

Based on this the overall effect of `htons' depends on the architecture of
the 
platform.  For example, if developing on an intel platform (which is
little-endian) 
then `htons' will convert to big-endian.  However, on a Sparc platform
(which is
big-endian) `htons' will do nothing.

You can use `htons' anywhere where you need a value in big-endian format.
You should 
use `htons' in any network related code when sending a short (say a port
number) across 
the network, regardless of the platform you are developing on - this aids
portability 
of your code.

Finally, you should be aware of the following functions:

htonl  -- host to network long
ntohs  -- network to host short
ntohl  -- network to host long

George


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

end of thread, other threads:[~2004-09-20 18:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-20 16:08 Use of htons function Ronaldo Zacarias Afonso
2004-09-20 16:41 ` Luciano Moreira - igLnx
  -- strict thread matches above, loose matches on Subject: below --
2004-09-20 18:14 Huber, George K RDECOM CERDEC STCD SRI

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).