htons

Converts 16-bit quantities from host to network byte order.

Library:LibC
Standard:BSD
Service:Networking

Syntax

  #include <sys/byteorder.h> 
   
  unsigned short htons (
     unsigned short   hostshort);
  

Parameters

hostshort

(IN) Specifies a 16-bit quantity in host byte order.

Return Values

Returns a value that has been converted from host to network byte order.

Remarks

The htons function is frequently used to convert port numbers from host byte order to network byte order for socket calls requiring a port number as a parameter.

NOTE:Network data order places the most significant byte at the lower memory address, while host data order places the least significant byte at the lower address.

See Also