os.h revision 10271:0edd36ea6130
1/* 2 * os.h 3 * 4 * Sleazy OS-specific defines. 5 * 6 * Copyright (c) 2000 Dug Song <dugsong@monkey.org> 7 * 8 * $Id: os.h,v 1.10 2004/05/04 03:19:42 dugsong Exp $ 9 */ 10 11#ifndef DNET_OS_H 12#define DNET_OS_H 13 14#ifdef _WIN32 15# include <windows.h> 16# include <winsock2.h> 17# include <stdint.h> 18/* XXX */ 19# undef IP_OPT_LSRR 20# undef IP_OPT_TS 21# undef IP_OPT_RR 22# undef IP_OPT_SSRR 23#else 24# include <sys/param.h> 25# include <sys/types.h> 26# include <sys/socket.h> 27# include <netinet/in.h> 28# include <arpa/inet.h> 29# include <netdb.h> 30# ifdef __bsdi__ 31# include <machine/types.h> 32 typedef u_int8_t uint8_t; 33 typedef u_int16_t uint16_t; 34 typedef u_int32_t uint32_t; 35 typedef u_int64_t uint64_t; 36# else 37# include <inttypes.h> 38# endif 39#endif 40 41#define DNET_LIL_ENDIAN 1234 42#define DNET_BIG_ENDIAN 4321 43 44/* BSD and IRIX */ 45#ifdef BYTE_ORDER 46#if BYTE_ORDER == LITTLE_ENDIAN 47# define DNET_BYTESEX DNET_LIL_ENDIAN 48#elif BYTE_ORDER == BIG_ENDIAN 49# define DNET_BYTESEX DNET_BIG_ENDIAN 50#endif 51#endif 52 53/* Linux */ 54#ifdef __BYTE_ORDER 55#if __BYTE_ORDER == __LITTLE_ENDIAN 56# define DNET_BYTESEX DNET_LIL_ENDIAN 57#elif __BYTE_ORDER == __BIG_ENDIAN 58# define DNET_BYTESEX DNET_BIG_ENDIAN 59#endif 60#endif 61 62/* Solaris */ 63#if defined(_BIT_FIELDS_LTOH) 64# define DNET_BYTESEX DNET_LIL_ENDIAN 65#elif defined (_BIT_FIELDS_HTOL) 66# define DNET_BYTESEX DNET_BIG_ENDIAN 67#endif 68 69/* Nastiness from old BIND code. */ 70#ifndef DNET_BYTESEX 71# if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \ 72 defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \ 73 defined(__alpha__) || defined(__alpha) 74# define DNET_BYTESEX DNET_LIL_ENDIAN 75# elif defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \ 76 defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \ 77 defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || defined(DGUX) ||\ 78 defined(apollo) || defined(__convex__) || defined(_CRAY) || \ 79 defined(__hppa) || defined(__hp9000) || \ 80 defined(__hp9000s300) || defined(__hp9000s700) || defined(__ia64) || \ 81 defined (BIT_ZERO_ON_LEFT) || defined(m68k) 82# define DNET_BYTESEX DNET_BIG_ENDIAN 83# else 84# error "bytesex unknown" 85# endif 86#endif 87 88/* C++ support. */ 89#undef __BEGIN_DECLS 90#undef __END_DECLS 91#ifdef __cplusplus 92# define __BEGIN_DECLS extern "C" { 93# define __END_DECLS } /* extern "C" */ 94#else 95# define __BEGIN_DECLS 96# define __END_DECLS 97#endif 98 99/* Support for flexible arrays. */ 100#undef __flexarr 101#if !defined(__clang__) && defined(__GNUC__) && \ 102 ((__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)) 103/* GCC 2.97 supports C99 flexible array members. */ 104# define __flexarr [] 105#else 106# ifdef __GNUC__ 107# define __flexarr [0] 108# else 109# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L 110# define __flexarr [] 111# else 112/* Some other non-C99 compiler. Approximate with [1]. */ 113# define __flexarr [1] 114# endif 115# endif 116#endif 117 118#endif /* DNET_OS_H */ 119