Rev | Line | |
---|
[9] | 1 | .TH HTON 3
|
---|
| 2 | .SH NAME
|
---|
| 3 | hton, htons, htonl, ntohs, ntohl \- host to network byte order conversion
|
---|
| 4 | .SH SYNOPSIS
|
---|
| 5 | .ft B
|
---|
| 6 | .nf
|
---|
| 7 | #define _MINIX_SOURCE 1
|
---|
| 8 | #include <stddef.h>
|
---|
| 9 | #include <sys/types.h>
|
---|
| 10 |
|
---|
| 11 | #include <net/hton.h>
|
---|
| 12 |
|
---|
| 13 | u16_t htons(u16_t \fIhost_word\fP)
|
---|
| 14 | u32_t htonl(u32_t \fIhost_dword\fP)
|
---|
| 15 | u16_t ntohs(u16_t \fInetwork_word\fP)
|
---|
| 16 | u32_t ntohl(u32_t \fInetwork_dword\fP)
|
---|
| 17 | u16_t HTONS(u16_t \fIhost_word\fP)
|
---|
| 18 | u32_t HTONL(u32_t \fIhost_dword\fP)
|
---|
| 19 | u16_t NTOHS(u16_t \fInetwork_word\fP)
|
---|
| 20 | u32_t NTOHL(u32_t \fInetwork_dword\fP)
|
---|
| 21 | .fi
|
---|
| 22 | .ft R
|
---|
| 23 | .SH DESCRIPTION
|
---|
| 24 | These macros convert 16-bit and 32-bit quantities to and from the network
|
---|
| 25 | byte order used by the TCP/IP protocols.
|
---|
| 26 | The function of the macros is encoded in their name.
|
---|
| 27 | .B H
|
---|
| 28 | means host byte order,
|
---|
| 29 | .B n
|
---|
| 30 | means network byte order,
|
---|
| 31 | .B s
|
---|
| 32 | means a 16-bit quantity and
|
---|
| 33 | .B l
|
---|
| 34 | means a 32-bit quantity.
|
---|
| 35 | Thus
|
---|
| 36 | .B htons
|
---|
| 37 | converts a 16-bit quantity from host byte order to network byte order.
|
---|
| 38 | The difference between the lower case and upper case variants is that
|
---|
| 39 | the lower case variants evaluate the argument at most once and the
|
---|
| 40 | upper case variants can be used for constant folding.
|
---|
| 41 | That is,
|
---|
| 42 | .PP
|
---|
| 43 | .RS
|
---|
| 44 | htonl(f(x))
|
---|
| 45 | .RE
|
---|
| 46 | .PP
|
---|
| 47 | will call f(x) at most once and
|
---|
| 48 | .PP
|
---|
| 49 | .RS
|
---|
| 50 | HTONS(0x10)
|
---|
| 51 | .RE
|
---|
| 52 | .PP
|
---|
| 53 | will be equivalent to 0x10 on a big-endian machine and 0x1000 on a
|
---|
| 54 | little-endian machine.
|
---|
| 55 | .SH "SEE ALSO"
|
---|
| 56 | .BR ip (4).
|
---|
| 57 | .SH AUTHOR
|
---|
| 58 | Philip Homburg (philip@cs.vu.nl)
|
---|
| 59 | .\"
|
---|
| 60 | .\" $PchId: hton.3,v 1.3 1996/02/22 21:10:01 philip Exp $
|
---|
Note:
See
TracBrowser
for help on using the repository browser.