blob: b5ea361f8304c322f46bc564e0e74a9a135d69c4 [file] [log] [blame]
Elliott Hughes08dc9d82014-09-23 13:55:15 -07001/* $OpenBSD: ntohs.c,v 1.9 2014/07/21 01:51:10 guenther Exp $ */
Elliott Hughes6a41b0f2014-05-13 16:05:51 -07002/*
3 * Written by J.T. Conklin <jtc@netbsd.org>.
4 * Public domain.
5 */
6
7#include <sys/types.h>
Elliott Hughes08dc9d82014-09-23 13:55:15 -07008#include <endian.h>
Elliott Hughes6a41b0f2014-05-13 16:05:51 -07009
10#undef ntohs
11
12u_int16_t
13ntohs(u_int16_t x)
14{
15#if BYTE_ORDER == LITTLE_ENDIAN
16 u_char *s = (u_char *) &x;
17 return (u_int16_t)(s[0] << 8 | s[1]);
18#else
19 return x;
20#endif
21}