ntohs() — Translate an unsigned short integer into host byte order

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

XPG4.2:
#define _XOPEN_SOURCE_EXTENDED 1
#include <arpa/inet.h>

in_port_t ntohs(in_port_t netshort);
SUSV3:
#define _POSIX_C_SOURCE 200112L
#include <arpa/inet.h>

uint16_t ntohs(uint16_t netshort);
Berkeley sockets:
#define _OE_SOCKETS
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>

unsigned short ntohs(unsigned short a);

General description

The ntohs() function translates a short integer from network byte order to host byte order.
Parameter
Description
a
The unsigned short integer to be put into host byte order.
in_port_t netshort
Is typed to the unsigned short integer to be put into host byte order.
Notes:
  1. For MVS™, host byte order and network byte order are the same.
  2. Since this function is implemented as a macro, you need one of the feature test macros and the inet header file.

Returned value

ntohs() returns the translated short integer.

Related information