htons()

The socket call translates a short integer from host-byte order to network-byte order.

Syntax

#include <types.h>
u_short htons(a)
u_short a;

Parameters

a

Description

The htons() call converts an unsigned short (16-bit) integer from host-byte order to internet network-byte order.

The internet network requires addresses and ports in network standard-byte order. Use the htons() call to convert ports from their host integer representation to internet network-byte order.

Return Values

Returns the translated short integer.

Related Calls


[Back: htonl()]
[Next: inet_addr()]