xref: /netbsd-src/common/lib/libc/net/ntohs.c (revision 2fa47ecfcb23a9fa15f2448c2ad113946a4b0bf9)
1 /*	$NetBSD: ntohs.c,v 1.3 2012/03/21 20:02:56 he Exp $	*/
2 
3 /*
4  * Written by J.T. Conklin <jtc@NetBSD.org>.
5  * Public domain.
6  */
7 
8 #include <sys/cdefs.h>
9 #if defined(LIBC_SCCS) && !defined(lint)
10 __RCSID("$NetBSD: ntohs.c,v 1.3 2012/03/21 20:02:56 he Exp $");
11 #endif
12 
13 #include <sys/types.h>
14 
15 #undef ntohs
16 
17 uint16_t
ntohs(uint16_t x)18 ntohs(uint16_t x)
19 {
20 #if BYTE_ORDER == LITTLE_ENDIAN
21 	u_char *s = (void *) &x;
22 	return (uint16_t)(s[0] << 8 | s[1]);
23 #else
24 	return x;
25 #endif
26 }
27