htons()--Convert Short Integer to Network Byte Order


  BSD 4.3 Syntax
  #include <sys/types.h>
  #include <netinet/in.h>

  unsigned short htons(unsigned short host_short)

  Threadsafe: Yes



  UNIX® 98 Compatible Syntax
  #define _XOPEN_SOURCE 520
  #include <netinet/in.h>

  uint16_t htons(uint16_t host_short)

  Threadsafe: Yes


The htons() function is used to convert a short (2-byte) integer from the local host byte order to standard network byte order.

There are two versions of the API, as shown above. The base IBM® i API uses BSD 4.3 structures and syntax. The other uses syntax and structures compatible with the UNIX 98 programming interface specifications. You can select the UNIX 98 compatible interface with the _XOPEN_SOURCE macro.


Parameters

host_short
(Input) The 2-byte integer in local host byte order that is to be converted to standard network byte order.

Authorities

No authorization is required.


Return Value

htons() returns an integer. Possible values are:


Usage Notes

  1. On the System i® platform, the value returned to the caller will be the same as the value that was passed to htons(), since the local host byte order does not differ from the standard network byte order.

Related Information



API introduced: V3R1

[ Back to top | UNIX-Type APIs | APIs by category ]