4.2BSD/usr/man/man3/byteorder.3n

.TH BYTEORDER 3N "4 March 1983"
.UC 4
.SH NAME
htonl, htons, ntohl, ntohs \- convert values between host and network byte order
.SH SYNOPSIS
.nf
.B #include <sys/types.h>
.B #include <netinet/in.h>
.PP
.B netlong = htonl(hostlong);
.B u_long netlong, hostlong;
.PP
.B netshort = htons(hostshort);
.B u_short netshort, hostshort;
.PP
.B hostlong = ntohl(netlong);
.B u_long hostlong, netlong;
.PP
.B hostshort = ntohs(netshort);
.B u_short hostshort, netshort;
.fi
.SH DESCRIPTION
These routines convert 16 and 32 bit quantities between network
byte order and host byte order.  On machines such as the SUN
these routines are defined as null macros in the include file
.RI < netinet/in.h >.
.PP
These routines are most often used in conjunction with Internet
addresses and ports as returned by
.IR gethostent (3N)
and
.IR getservent (3N).
.SH "SEE ALSO"
gethostent(3N),
getservent(3N)
.SH BUGS
The VAX handles bytes backwards from most everyone else in
the world.  This is not expected to be fixed in the near future.