Converts an unsigned short integer from host byte order to Internet network byte order.
ISODE Library (libisode.a)
#include <sys/types.h>
#include <netinet/in.h>
uint16_t htons ( HostShort)
uint16_t HostShort;
The htons subroutine converts an unsigned short (16-bit) integer from host byte order to Internet network byte order.
The Internet network requires ports and addresses in network standard byte order. Use the htons subroutine to convert addresses and ports from their host integer representation to network standard byte order.
The htons subroutine is defined in the net/nh.h file as a null macro if the host byte order is the same as the network byte order.
The htons subroutine is declared in the net/nh.h file as a function if the host byte order is not the same as the network byte order.
All applications containing the htons subroutine must be compiled with the _BSD macro set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.
Item | Description |
---|---|
HostShort | Specifies a 16-bit integer in host byte order that is a host address or port. |
The htons subroutine returns a 16-bit integer in Internet network byte order (most significant byte first).