2012-11-15 12:06:41 +01:00
|
|
|
/* $NetBSD: ntohs.c,v 1.3 2012/03/21 20:02:56 he Exp $ */
|
2011-02-14 20:36:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
|
|
|
* Public domain.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2012-11-15 12:06:41 +01:00
|
|
|
__RCSID("$NetBSD: ntohs.c,v 1.3 2012/03/21 20:02:56 he Exp $");
|
2011-02-14 20:36:03 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#undef ntohs
|
|
|
|
|
|
|
|
uint16_t
|
2012-11-15 12:06:41 +01:00
|
|
|
ntohs(uint16_t x)
|
2011-02-14 20:36:03 +01:00
|
|
|
{
|
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
2012-11-15 12:06:41 +01:00
|
|
|
u_char *s = (void *) &x;
|
2011-02-14 20:36:03 +01:00
|
|
|
return (uint16_t)(s[0] << 8 | s[1]);
|
|
|
|
#else
|
|
|
|
return x;
|
|
|
|
#endif
|
|
|
|
}
|