Previous section.

Technical Standard: Networking Services (XNS), Issue 5.2 Draft 2.0
Copyright © 1999 The Open Group

NAME

htonl, htons, ntohl, ntohs - convert values between host and network byte order

SYNOPSIS


#include <arpa/inet.h>

uint32_t htonl(uint32_t hostlong);

uint16_t htons(uint16_t hostshort);

uint32_t ntohl(uint32_t netlong);

uint16_t ntohs(uint16_t netshort);

DESCRIPTION

These functions convert 16-bit and 32-bit quantities between network byte order and host byte order.

The uint32_t and uint16_t types are made available by inclusion of <inttypes.h> (see referenced document XSH).

RETURN VALUES

The htonl() and htons() functions return the argument value converted from host to network byte order.

The ntohl() and ntohs() functions return the argument value converted from network to host byte order.

ERRORS

No errors are defined.

APPLICATION USAGE

These functions are most often used in conjunction with Internet IPv4 addresses and ports as returned by gethostent() and getservent().

On some architectures these functions are defined as macros that expand to the value of their argument.

SEE ALSO

endhostent(), endservent(), <arpa/inet.h>.

CHANGE HISTORY

First released in Issue 4.

Contents Next section Index