11.3She/*	$NetBSD: ntohs.c,v 1.3 2012/03/21 20:02:56 he Exp $	*/
21.1Schristos
31.1Schristos/*
41.1Schristos * Written by J.T. Conklin <jtc@NetBSD.org>.
51.1Schristos * Public domain.
61.1Schristos */
71.1Schristos
81.1Schristos#include <sys/cdefs.h>
91.1Schristos#if defined(LIBC_SCCS) && !defined(lint)
101.3She__RCSID("$NetBSD: ntohs.c,v 1.3 2012/03/21 20:02:56 he Exp $");
111.1Schristos#endif
121.1Schristos
131.1Schristos#include <sys/types.h>
141.1Schristos
151.1Schristos#undef ntohs
161.1Schristos
171.1Schristosuint16_t
181.2Sjoergntohs(uint16_t x)
191.1Schristos{
201.1Schristos#if BYTE_ORDER == LITTLE_ENDIAN
211.3She	u_char *s = (void *) &x;
221.1Schristos	return (uint16_t)(s[0] << 8 | s[1]);
231.1Schristos#else
241.1Schristos	return x;
251.1Schristos#endif
261.1Schristos}
27