xref: /titanic_41/usr/src/stand/lib/xdr/byteorder.c (revision 1d4b38e0077763e7c9b20768eacb841957e787bc)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1991-2000, 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <netinet/in.h>
31 
32 #ifdef	_LITTLE_ENDIAN
33 uint32_t
34 htonl(uint32_t in)
35 {
36 	uint32_t	i;
37 
38 	i = (uint32_t)((in & (uint32_t)0xff000000) >> 24) +
39 	    (uint32_t)((in & (uint32_t)0x00ff0000) >> 8) +
40 	    (uint32_t)((in & (uint32_t)0x0000ff00) << 8) +
41 	    (uint32_t)((in & (uint32_t)0x000000ff) << 24);
42 	return (i);
43 }
44 
45 uint32_t
46 ntohl(uint32_t in)
47 {
48 	return (htonl(in));
49 }
50 
51 uint16_t
52 htons(uint16_t in)
53 {
54 	register int arg = (int)in;
55 	uint16_t i;
56 
57 	i = (uint16_t)(((arg & 0xff00) >> 8) & 0xff);
58 	i |= (uint16_t)((arg & 0xff) << 8);
59 	return ((uint16_t)i);
60 }
61 
62 uint16_t
63 ntohs(uint16_t in)
64 {
65 	return (htons(in));
66 }
67 
68 #else	/* _LITTLE_ENDIAN */
69 
70 #if defined(lint)
71 
72 uint32_t
73 htonl(uint32_t in)
74 {
75 	return (in);
76 }
77 
78 uint32_t
79 ntohl(uint32_t in)
80 {
81 	return (in);
82 }
83 
84 uint16_t
85 htons(uint16_t in)
86 {
87 	return (in);
88 }
89 
90 uint16_t
91 ntohs(uint16_t in)
92 {
93 	return (in);
94 }
95 
96 #endif	/* lint */
97 #endif	/* _LITTLE_ENDIAN */
98