[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Communications, Volume 2

htons Subroutine

Purpose

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

Library

ISODE Library (libisode.a)

Syntax

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


unsigned short htons ( HostShort)
unsigned short HostShort;

Description

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

The Internet network requires ports and addresses in network standard byte order. Use the htons subroutine to convert addresses and ports from their host integer representation to network standard byte order.

The htons subroutine is defined in the net/nh.h file as a macro.

All applications containing the htons subroutine must be compiled with _BSD set to a specific value. Acceptable values are 43 and 44. In addition, all socket applications must include the BSD libbsd.a library.

Parameters

HostShort Specifies a 16-bit integer in host byte order that is a host address or port.

Return Values

The htons subroutine returns a 16-bit integer in Internet network byte order (most significant byte first).

Related Information

The htonl subroutine, ntohl subroutine, ntohs subroutine.

Sockets Overview in AIX 5L Version 5.2 Communications Programming Concepts.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]