htons

Converts short integers from host to network byte order.

Format

#include  <in.h>

unsigned short int htons  (unsigned short int hostshort);

Argument

hostshort
A short integer in host (VAX system) byte order. All short integers on VAX systems are in host byte order unless otherwise specified.

Description

This routine converts 16-bit unsigned integers from host byte order to network byte order.

The network byte order is the format in which data bytes are supposed to be transmitted through a network. All hosts on a network must send data in network byte order. Not all hosts have an internal data representation format that is identical to the network byte order. The host byte order is the format in which bytes are ordered internally on a specific host.

The host byte order on VAX systems differs from the network order.

This routine is most often used with Internet addresses and ports as returned by gethostent and getservent, and when manipulating values in the structures. Network byte order places the byte with the most significant bits at lower addresses; VAX systems place the most significant bits at the highest address.

Return Value
A short integer in network byte order. Integers in network byte order cannot be used for arithmetic computation on VAX systems. 


Previous Page | Next Page | Table of Contents | Index