htons() — Translate an unsigned short integer into network byte order
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
Format
XPG4.2
#define _XOPEN_SOURCE_EXTENDED 1
#include <arpa/inet.h>
in_port_t htons(in_port_t hostshort);
SUSV3
#define _POSIX_C_SOURCE 200112L
#include <arpa/inet.h>
uint16_t htons(uint16_t hostshort);
Berkeley
Sockets
#define _OE_SOCKETS
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
unsigned short htons(unsigned short a);
General description
The htons()
function translates a short integer from host byte order to network
byte order.
- Parameter
- Description
- a
- The unsigned short integer to be put into network byte order.
- in_port_t hostshort
- Is typed to the unsigned short integer to be put into network byte order.
Notes:
- For MVS™, host byte order and network byte order are the same.
- Since this function is implemented as a macro, you need one of the feature test macros and the inet header file.
Returned value
htons() returns the translated short integer.