1 /*===========================================================================* 2 * byteorder.h * 3 * * 4 * stuff to handle different byte order * 5 * * 6 *===========================================================================*/ 7 8 /* 9 * Copyright (c) 1995 The Regents of the University of California. 10 * All rights reserved. 11 * 12 * Permission to use, copy, modify, and distribute this software and its 13 * documentation for any purpose, without fee, and without written agreement is 14 * hereby granted, provided that the above copyright notice and the following 15 * two paragraphs appear in all copies of this software. 16 * 17 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR 18 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT 19 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF 20 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 * 22 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 24 * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 25 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO 26 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 27 */ 28 29 /* 30 * $Header$ 31 * $Log$ 32 * Revision 1.5 2004/04/02 15:12:41 rwcox 33 * Cput 34 * 35 * Revision 1.4 2004/02/05 21:32:23 rwcox 36 * Cput 37 * 38 * Revision 1.3 2003/12/23 13:50:08 rwcox 39 * Cput 40 * 41 * Revision 1.2 2003/12/03 14:46:15 rwcox 42 * Cput 43 * 44 * Revision 1.1 2001/12/17 18:25:44 rwcox 45 * Cadd 46 * 47 * Revision 1.3 1995/01/19 23:54:39 eyhung 48 * Changed copyrights 49 * 50 * Revision 1.3 1995/01/19 23:54:39 eyhung 51 * Changed copyrights 52 * 53 * Revision 1.2 1994/11/12 02:12:15 keving 54 * nothing 55 * 56 * Revision 1.1 1993/07/22 22:24:23 keving 57 * nothing 58 * 59 */ 60 61 62 #include "general.h" 63 64 65 #ifdef FORCE_BIG_ENDIAN 66 /* leave byte order as it is */ 67 #define htonl(x) (x) 68 #define ntohl(x) (x) 69 #define htons(x) (x) 70 #define ntohs(x) (x) 71 #else 72 #ifdef FORCE_LITTLE_ENDIAN 73 /* need to reverse byte order */ 74 /* note -- we assume here that htonl is called on a variable, not a 75 * constant; thus, this is not for general use, but works with bitio.c 76 */ 77 #define htonl(x) \ 78 ((((unsigned char *)(&x))[0] << 24) | \ 79 (((unsigned char *)(&x))[1] << 16) | \ 80 (((unsigned char *)(&x))[2] << 8) | \ 81 (((unsigned char *)(&x))[3])) 82 #define ntohl(x) htonl(x) 83 #define htons(x) \ 84 ((((unsigned char *)(&x))[0] << 8) | \ 85 ((unsigned char *)(&x))[1]) 86 #define ntohs(x) htons(x) 87 #else 88 /* let in.h handle it, if possible */ 89 #include <sys/types.h> 90 #include <netinet/in.h> 91 #endif /* FORCE_LITTLE_ENDIAN */ 92 #endif /* FORCE_BIG_ENDIAN */ 93