1*ce666bb8Sperry /* $NetBSD: ntohs.c,v 1.3 2005/12/24 23:10:08 perry Exp $ */
295d875fbSmsaitoh
395d875fbSmsaitoh /*-
495d875fbSmsaitoh * Copyright (c) 1990 The Regents of the University of California.
595d875fbSmsaitoh * All rights reserved.
695d875fbSmsaitoh *
795d875fbSmsaitoh * This code is derived from software contributed to Berkeley by
895d875fbSmsaitoh * William Jolitz.
995d875fbSmsaitoh *
1095d875fbSmsaitoh * Redistribution and use in source and binary forms, with or without
1195d875fbSmsaitoh * modification, are permitted provided that the following conditions
1295d875fbSmsaitoh * are met:
1395d875fbSmsaitoh * 1. Redistributions of source code must retain the above copyright
1495d875fbSmsaitoh * notice, this list of conditions and the following disclaimer.
1595d875fbSmsaitoh * 2. Redistributions in binary form must reproduce the above copyright
1695d875fbSmsaitoh * notice, this list of conditions and the following disclaimer in the
1795d875fbSmsaitoh * documentation and/or other materials provided with the distribution.
18eb7c1594Sagc * 3. Neither the name of the University nor the names of its contributors
1995d875fbSmsaitoh * may be used to endorse or promote products derived from this software
2095d875fbSmsaitoh * without specific prior written permission.
2195d875fbSmsaitoh *
2295d875fbSmsaitoh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2395d875fbSmsaitoh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2495d875fbSmsaitoh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2595d875fbSmsaitoh * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2695d875fbSmsaitoh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2795d875fbSmsaitoh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2895d875fbSmsaitoh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2995d875fbSmsaitoh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3095d875fbSmsaitoh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3195d875fbSmsaitoh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3295d875fbSmsaitoh * SUCH DAMAGE.
3395d875fbSmsaitoh *
3495d875fbSmsaitoh * from: @(#)ntohl.s 5.2 (Berkeley) 12/17/90
3595d875fbSmsaitoh */
3695d875fbSmsaitoh
3795d875fbSmsaitoh #include <sys/types.h>
3895d875fbSmsaitoh #include <machine/endian.h>
3995d875fbSmsaitoh #if defined(LIBC_SCCS)
40*ce666bb8Sperry __RCSID("$NetBSD: ntohs.c,v 1.3 2005/12/24 23:10:08 perry Exp $");
4195d875fbSmsaitoh #endif
4295d875fbSmsaitoh
4395d875fbSmsaitoh /* hostorder = ntohs(netorder) */
4495d875fbSmsaitoh #if BYTE_ORDER == LITTLE_ENDIAN
4595d875fbSmsaitoh u_int16_t
ntohs(x)4695d875fbSmsaitoh ntohs(x)
4795d875fbSmsaitoh u_int16_t x;
4895d875fbSmsaitoh {
49*ce666bb8Sperry __asm("swap.b %1, %0" : "=r" (x) : "r" (x));
5095d875fbSmsaitoh return x;
5195d875fbSmsaitoh }
5295d875fbSmsaitoh #endif
53