ntohs Subroutine

Purpose

Converts an unsigned short integer from Internet network byte order to host byte order.

Library

ISODE Library (libisode.a)

Syntax

#include <sys/types.h>
#include <netinet/in.h>

uint16_t ntohs ( NetShort)
uint16_t NetShort;

Description

The ntohs subroutine converts an unsigned short (16-bit) integer from Internet network byte order to the host byte order.

Receiving hosts require Internet addresses and ports in host byte order. Use the ntohs subroutine to convert Internet addresses and ports to the host integer representation.

The ntohs subroutine is defined in the net/nh.h file as a null macro if the host byte order is same as the network byte order.

The ntohs subroutine is declared in the net/nh.h file as a function if the host byte order is not same as the network byte order.

All applications containing the ntohs 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.

Parameters

Item Description
NetShort Requires a 16-bit integer in network standard byte order.

Return Values

The ntohs subroutine returns a 16-bit integer in host byte order.