1 /******************************************************************************
2     (c) 1998, 2003 Christine Caulfield               christine.caulfield@googlemail.com
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13  ******************************************************************************
14  */
15 /* Header file to cope with endian issues */
16 
17 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
18 #include <machine/endian.h>
19 #ifndef __BYTE_ORDER
20 #define __BYTE_ORDER BYTE_ORDER
21 #endif
22 #endif
23 
24 #ifdef __APPLE__
25 #include <architecture/byte_order.h>
26 #define __BYTE_ORDER BYTE_ORDER
27 #endif
28 
29 
30 #ifndef __BYTE_ORDER
31     #error "Can't determine endianness - please inform christine.caulfield@googlemail.com with your distribution and hardware type."
32 #endif
33 
34 #if (__BYTE_ORDER == 1234)
35 
36   /* It's a VAX or Intel, or some other obscure make :-) */
37 
38   /* DECnet is little-endian so these are no-ops */
39   #define dn_ntohs(x) (x)
40   #define dn_htons(x) (x)
41 
42   #define dn_ntohl(x) (x)
43   #define dn_htonl(x) (x)
44 
45 #else
46   #if (__BYTE_ORDER == 4321)
47 
48     /* It's a SPARC - most likely than not */
49 
50     #define dn_ntohs(x) ((((x)&0x0ff)<<8) | (((x)&0xff00)>>8))
51 
52     #define dn_ntohl(x) ( ((dn_ntohs((x)&0xffff))<<16) |\
53 			  ((dn_ntohs(((x)>>16)))) )
54 
55     #define dn_htonl(x) dn_ntohl(x)
56     #define dn_htons(x) dn_ntohs(x)
57   #else
58 
59     /* it's a PDP??? */
60     #error "Unsupported endianness - please inform christine.caulfield@googlemail.com with your distribution and hardware type."
61   #endif
62 #endif
63