4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright (c) 2015, Joyent, Inc.
32 * NOTE: htonl/ntohl are identical routines, as are htons/ntohs.
33 * As such, they could be implemented as a single routine, using
34 * multiple ALTENTRY/SET_SIZE definitions. We don't do this so
35 * that they will have unique addresses, allowing DTrace and
36 * other debuggers to tell them apart. With the endian
37 * functions we do the same, even though it's similarly
41 / unsigned long htonl
( hl
)
42 / unsigned long ntohl
( hl
)
44 / reverses the byte order of
'long hl'
47 movl
4(%esp
), %eax
/ %eax
= hl
48 bswap
%eax
/ reverses the byte order of
%eax
53 movl
4(%esp
), %eax
/ %eax
= hl
54 bswap
%eax
/ reverses the byte order of
%eax
58 / unsigned short htons
( hs
)
61 / reverses the byte order in hs.
64 movl
4(%esp
), %eax
/ %eax
= hs
65 bswap
%eax
/ reverses the byte order of
%eax
66 shrl $
16, %eax
/ moves high
16-bit to low
16-bit
71 movl
4(%esp
), %eax
/ %eax
= hs
72 bswap
%eax
/ reverses the byte order of
%eax
73 shrl $
16, %eax
/ moves high
16-bit to low
16-bit
77 / uint16_t htobe16
(uint16_t in
)
79 / Convert in to big endian
, eg. htons
()
82 movl
4(%esp
), %eax
/ %eax
= hs
83 bswap
%eax
/ reverses the byte order of
%eax
84 shrl $
16, %eax
/ moves high
16-bit to low
16-bit
88 / uint32_t htobe32
(uint32_t in
)
90 / Convert in to big endian
, eg. htonl
()
93 movl
4(%esp
), %eax
/ %eax
= hl
94 bswap
%eax
/ reverses the byte order of
%eax
98 / uint16_t betoh16
(uint16_t in
)
99 / uint16_t be16toh
(uint16_t in
)
101 / Convert in to little endian
, eg. ntohs
()
104 movl
4(%esp
), %eax
/ %eax
= hs
105 bswap
%eax
/ reverses the byte order of
%eax
106 shrl $
16, %eax
/ moves high
16-bit to low
16-bit
111 movl
4(%esp
), %eax
/ %eax
= hs
112 bswap
%eax
/ reverses the byte order of
%eax
113 shrl $
16, %eax
/ moves high
16-bit to low
16-bit
118 / uint32_t be32toh
(uint32_t in
)
119 / uint32_t betoh32
(uint32_t in
)
121 / Convert in to little endian
, eg. ntohl
()
124 movl
4(%esp
), %eax
/ %eax
= hl
125 bswap
%eax
/ reverses the byte order of
%eax
130 movl
4(%esp
), %eax
/ %eax
= hl
131 bswap
%eax
/ reverses the byte order of
%eax