xorp

xorp.h

00001 /* -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*- */
00002 /* vim:set sts=4 ts=8: */
00003 
00004 /*
00005  * Copyright (c) 2001-2011 XORP, Inc and Others
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU Lesser General Public License, Version
00009  * 2.1, June 1999 as published by the Free Software Foundation.
00010  * Redistribution and/or modification of this program under the terms of
00011  * any other version of the GNU Lesser General Public License is not
00012  * permitted.
00013  * 
00014  * This program is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00017  * see the GNU Lesser General Public License, Version 2.1, a copy of
00018  * which can be found in the XORP LICENSE.lgpl file.
00019  * 
00020  * XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00021  * http://xorp.net
00022  */
00023 
00024 #ifndef __LIBXORP_XORP_H__
00025 #define __LIBXORP_XORP_H__
00026 
00027 #include "xorp_config.h"
00028 
00029 #ifdef HAVE_ENDIAN_H
00030 #  include <endian.h>
00031 #endif
00032 
00033 #ifndef BYTE_ORDER
00034 #ifdef __BYTE_ORDER
00035 #define BYTE_ORDER  __BYTE_ORDER
00036 #define LITTLE_ENDIAN   __LITTLE_ENDIAN
00037 #define BIG_ENDIAN  __BIG_ENDIAN
00038 
00039 #else /* ! _BYTE_ORDER */
00040 
00041 /*
00042  * Presume that the scons logic figured defined WORDS_BIGENDIAN
00043  * or not.
00044  */
00045 
00046 #ifndef __LITTLE_ENDIAN
00047 #define __LITTLE_ENDIAN   1234
00048 #endif
00049 #ifndef __BIG_ENDIAN
00050 #define __BIG_ENDIAN      4321
00051 #endif
00052 
00053 #ifndef LITTLE_ENDIAN
00054 #define LITTLE_ENDIAN   __LITTLE_ENDIAN
00055 #endif
00056 #ifndef BIG_ENDIAN
00057 #define BIG_ENDIAN      __BIG_ENDIAN
00058 #endif
00059 
00060 
00061 #ifdef WORDS_BIGENDIAN
00062 #define BYTE_ORDER  BIG_ENDIAN
00063 #define __BYTE_ORDER    BIG_ENDIAN
00064 #else
00065 #define BYTE_ORDER  LITTLE_ENDIAN
00066 #define __BYTE_ORDER    LITTLE_ENDIAN
00067 #endif
00068 
00069 /*
00070  * XXX: The old C preprocessor error if BYTE_ORDER is not defined.
00071  *
00072  * #error "BYTE_ORDER not defined! Define it to either LITTLE_ENDIAN (e.g. i386, vax) or BIG_ENDIAN (e.g.  68000, ibm, net) based on your architecture!"
00073  */
00074 
00075 #endif /* ! __BYTE_ORDER */
00076 #endif /* ! BYTE_ORDER */
00077 
00078 
00079 #ifdef __cplusplus
00080 #  ifdef XORP_USE_USTL
00081 #    include <ustl.h>
00082      using namespace ustl;
00083 #  else
00084 #    include <new>
00085 #    include <iostream>
00086 #    include <fstream>
00087 #    include <sstream>
00088 #    include <algorithm>
00089 #    include <utility>
00090 #    include <cstdarg>
00091 #    include <cstdio>
00092 #    include <string>
00093 #    include <vector>
00094 #    include <list>
00095 #    include <set>
00096 #    include <map>
00097 #    include <queue>
00098 #    include <functional>
00099 #    include <memory>
00100 #    if !defined(__STL_NO_NAMESPACES)
00101        using namespace std;
00102 #    endif /* namespace std */
00103 #  endif /* else, not ustl */
00104 #endif /* c++ */
00105 
00106 #ifdef HAVE_STDINT_H
00107 #  include <stdint.h>
00108 #endif
00109 
00110 #ifdef HAVE_INTTYPES_H
00111 #  include <inttypes.h>
00112 #endif
00113 
00114 #if defined (__cplusplus)
00115 # if defined (USE_BOOST) && defined (HAS_BOOST_NONCOPYABLE_INC)
00116 #  include <boost/noncopyable.hpp>
00117 #  define NONCOPYABLE boost::noncopyable
00118 # else
00119 #  define NONCOPYABLE xorp_noncopyable
00120 #  include "xorp_noncopyable.hh"
00121 # endif
00122 #endif
00123 
00124 /*
00125  * Include sys/cdefs.h to define __BEGIN_DECLS and __END_DECLS.  Even if
00126  * this file exists, not all platforms define these macros.
00127  */
00128 #ifdef HAVE_SYS_CDEFS_H
00129 #  include <sys/cdefs.h>
00130 #endif
00131 
00132 /*
00133  * Define C++ decls wrappers if not previously defined.
00134  */
00135 #ifndef __BEGIN_DECLS
00136 #  if defined(__cplusplus)
00137 #    define __BEGIN_DECLS   extern "C" {
00138 #    define __END_DECLS     };    
00139 #  else /* __BEGIN_DECLS */
00140 #    define __BEGIN_DECLS
00141 #    define __END_DECLS
00142 #  endif /* __BEGIN_DECLS */
00143 #endif /* __BEGIN_DECLS */
00144 
00145 #include "xorp_osdep_begin.h"
00146 
00147 #ifdef HAVE_SYS_TYPES_H
00148 #include <sys/types.h>
00149 #endif
00150 #ifdef HAVE_SYS_PARAM_H
00151 #include <sys/param.h>
00152 #endif
00153 #ifdef HAVE_SYS_TIME_H
00154 #include <sys/time.h>
00155 #endif
00156 #ifdef HAVE_SYS_SOCKET_H
00157 #include <sys/socket.h>
00158 #endif
00159 /*
00160  * XXX: Include <net/if.h> upfront so we can create a work-around because
00161  * of a problematic name collusion in the Solaris-10 header file.
00162  * That file contains "struct map *" pointer that prevents us from
00163  * including the STL <map> file.
00164  */
00165 #ifdef HAVE_NET_IF_H
00166 #define map solaris_class_map
00167 #include <net/if.h>
00168 #undef map
00169 #endif
00170 #ifdef HAVE_NETINET_IN_H
00171 #include <netinet/in.h>
00172 #endif
00173 #ifdef HAVE_SYS_STAT_H
00174 #include <sys/stat.h>
00175 #endif
00176 
00177 #include <stdarg.h>
00178 
00179 #ifdef HAVE_STDLIB_H
00180 #include <stdlib.h>
00181 #endif
00182 #ifdef HAVE_UNISTD_H
00183 #include <unistd.h>
00184 #endif
00185 
00186 #include <stdio.h>
00187 #include <signal.h>
00188 #include <string.h>
00189 #include <errno.h>
00190 #include <assert.h>
00191 
00192 #ifdef HAVE_SYSLOG_H
00193 #include <syslog.h>
00194 #endif
00195 
00196 #include <time.h>
00197 
00198 #include "utility.h"
00199 
00200 #include "xorp_osdep_mid.h"
00201 
00202 #if defined (__cplusplus) && !defined(__STL_NO_NAMESPACES)
00203 #ifndef XORP_USE_USTL
00204 using namespace std::rel_ops;
00205 #endif
00206 #endif
00207 
00208 /*
00209  * Misc. definitions that may be missing from the system header files.
00210  * TODO: this should go to a different header file.
00211  */
00212 
00213 #ifndef NBBY
00214 #define NBBY    (8) /* number of bits in a byte */
00215 #endif
00216 
00217 /*
00218  * Redefine NULL as per Stroustrup to get additional error checking.
00219  */
00220 #ifdef NULL
00221 #   undef NULL
00222 #   if defined __GNUG__ && \
00223     (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
00224 #   define NULL (__null)
00225 #   else
00226 #   if !defined(__cplusplus)
00227 #       define NULL ((void*)0)
00228 #   else
00229 #       define NULL (0)
00230 #   endif
00231 #   endif
00232 #endif /* NULL */
00233 
00234 /*
00235  * Boolean values
00236  */
00237 #if (!defined(TRUE)) || (!defined(FALSE))
00238 #ifdef TRUE
00239 #undef TRUE
00240 #endif
00241 #ifdef FALSE
00242 #undef FALSE
00243 #endif
00244 #define FALSE (0)
00245 #define TRUE (!FALSE)
00246 #endif /* TRUE, FALSE */
00247 #ifndef __cplusplus
00248 typedef enum { true = TRUE, false = FALSE } bool;
00249 #endif
00250 typedef bool bool_t;
00251 
00252 /*
00253  * Generic error return codes
00254  */
00255 #ifdef XORP_OK
00256 #undef XORP_OK
00257 #endif
00258 #ifdef XORP_ERROR
00259 #undef XORP_ERROR
00260 #endif
00261 #define XORP_OK      (0)
00262 #define XORP_ERROR  (-1)
00263 
00264 #include "xorp_osdep_end.h"
00265 
00266 #endif /* __LIBXORP_XORP_H__ */
 All Classes Namespaces Functions Variables Typedefs Enumerations