common/lib/libc/net/ntohs.c
author yamt <yamt@NetBSD.org>
Tue, 17 Apr 2012 00:01:34 +0000
branchyamt-pagecache
changeset 280360 e98874280705
parent 202663 d5a7b7ffbc8d
permissions -rw-r--r--
sync with head

/*	$NetBSD: ntohs.c,v 1.2.2.1 2012/04/17 00:01:39 yamt Exp $	*/

/*
 * Written by J.T. Conklin <jtc@NetBSD.org>.
 * Public domain.
 */

#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: ntohs.c,v 1.2.2.1 2012/04/17 00:01:39 yamt Exp $");
#endif

#include <sys/types.h>

#undef ntohs

uint16_t
ntohs(uint16_t x)
{
#if BYTE_ORDER == LITTLE_ENDIAN
	u_char *s = (void *) &x;
	return (uint16_t)(s[0] << 8 | s[1]);
#else
	return x;
#endif
}