common/lib/libc/net/ntohs.c
author joerg <joerg@NetBSD.org>
Mon, 04 Jul 2011 21:20:27 +0000
branchtrunk
changeset 202663 d5a7b7ffbc8d
parent 141908 e9a9cdbc5908
child 210135 eb682f326b6d
child 280360 e98874280705
permissions -rw-r--r--
ANSIfy

/*	$NetBSD: ntohs.c,v 1.2 2011/07/04 21:29:16 joerg 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 2011/07/04 21:29:16 joerg Exp $");
#endif

#include <sys/types.h>

#undef ntohs

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