[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Communications Technical Reference, 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.

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).

Implementation Specifics

The htons subroutine is part of Base Operating System (BOS) Runtime.

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.

Related Information

The htonl subroutine, ntohl subroutine, ntohs subroutine.

Sockets Overview in AIX Version 4.3 Communications Programming Concepts.


[ Previous | Next | Contents | Glossary | Home | Search ]