---
name: "byteorder"
section: "3"
platform: "macos"
package: "Libc"
version: "1752.120.2"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/byteorder"
---

# byteorder(3)

convert values between host and network byte order

## NAME

**htonl**, **htons**, **htonll**, **ntohl**, **ntohs**, **ntohll** – convert values between host and network byte order

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<arpa/inet.h\>**

*uint64\_t*\

**htonll**(*uint64\_t hostlonglong*);

*uint32\_t*\

**htonl**(*uint32\_t hostlong*);

*uint16\_t*\

**htons**(*uint16\_t hostshort*);

*uint64\_t*\

**ntohll**(*uint64\_t netlonglong*);

*uint32\_t*\

**ntohl**(*uint32\_t netlong*);

*uint16\_t*\

**ntohs**(*uint16\_t netshort*);

## DESCRIPTION

These routines convert 16 bit, 32 bit, and 64 bit quantities between network byte order and host byte order. (Network byte order is big endian, or most significant byte first.) On machines which have a byte order which is the same as the network order, routines are defined as null macros.

These routines are most often used in conjunction with Internet addresses and ports as returned by [gethostbyname(3)](/gethostbyname/3.md) and [getservent(3)](/getservent/3.md).

## SEE ALSO

[gethostbyname(3)](/gethostbyname/3.md), [getservent(3)](/getservent/3.md)

## STANDARDS

The **byteorder** functions except **htonll** and **ntohll** are expected to conform with IEEE Std POSIX.1-200x (“POSIX.1”)

## HISTORY

The functions **htonl,** **htons,** **ntohl,** **ntohs** appeared in 4.2BSD.

The functions **htonll** and **ntohll** first appeared in OS X 10.10 (Yosemite).

## BUGS

On the VAX bytes are handled backwards from most everyone else in the world.  This is not expected to be fixed in the near future.
