1 /*
2 ** Copyright (C) 2007-2009 Sourcefire, Inc.
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 Version 2 as
6 ** published by the Free Software Foundation.  You may not use, modify or
7 ** distribute this program under any other version of the GNU General
8 ** Public License.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 
20 #ifndef __SF_TYPES_H__
21 #define __SF_TYPES_H__
22 
23 #include <sys/types.h>
24 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 
28 #ifdef WIN32
29 #  include "stdint.h"
30 #  include "inttypes.h"
31 #else
32 /* Autoconf uses <sys/types.h>, <inttypes.h> and <stdint.h> as standard includes for
33  * determining if these exist so there shouldn't be any typedef conflicts with
34  * including <sys/types.h>, <inttypes.h> or <stdint.h> since these would be
35  * defined already */
36 #  if !defined(HAVE_UINT8_T) || !defined(HAVE_U_INT8_T)
37 #    if !defined(HAVE_UINT8_T) && !defined(HAVE_U_INT8_T)
38 typedef unsigned char   u_int8_t;
39 typedef unsigned char    uint8_t;
40 #    elif defined(HAVE_UINT8_T)
41 typedef uint8_t   u_int8_t;
42 #    else
43 typedef u_int8_t   uint8_t;
44 #    endif  /* !defined(HAVE_UINT8_T) && !defined(HAVE_U_INT8_T) */
45 #  endif  /* !defined(HAVE_UINT8_T) || !defined(HAVE_U_INT8_T) */
46 #  if !defined(HAVE_UINT16_T) || !defined(HAVE_U_INT16_T)
47 #    if !defined(HAVE_UINT16_T) && !defined(HAVE_U_INT16_T)
48 typedef unsigned short    u_int16_t;
49 typedef unsigned short     uint16_t;
50 #    elif defined(HAVE_UINT16_T)
51 typedef uint16_t    u_int16_t;
52 #    else
53 typedef u_int16_t    uint16_t;
54 #    endif  /* !defined(HAVE_UINT16_T) && !defined(HAVE_U_INT16_T) */
55 #  endif  /* !defined(HAVE_UINT16_T) || !defined(HAVE_U_INT16_T) */
56 #  if !defined(HAVE_UINT32_T) || !defined(HAVE_U_INT32_T)
57 #    if !defined(HAVE_UINT32_T) && !defined(HAVE_U_INT32_T)
58 #      if SIZEOF_UNSIGNED_LONG_INT == 4
59 typedef unsigned long int    u_int32_t;
60 typedef unsigned long int     uint32_t;
61 #      elif SIZEOF_UNSIGNED_INT == 4
62 typedef unsigned int    u_int32_t;
63 typedef unsigned int     uint32_t;
64 #      endif  /* SIZEOF_UNSIGNED_LONG_INT == 4 */
65 #    elif defined(HAVE_UINT32_T)
66 typedef uint32_t    u_int32_t;
67 #    else
68 typedef u_int32_t    uint32_t;
69 #    endif  /* !defined(HAVE_UINT32_T) && !defined(HAVE_U_INT32_T) */
70 #  endif  /* !defined(HAVE_UINT32_T) || !defined(HAVE_U_INT32_T) */
71 #  if !defined(HAVE_UINT64_T) || !defined(HAVE_U_INT64_T)
72 #    if !defined(HAVE_UINT64_T) && !defined(HAVE_U_INT64_T)
73 #      if SIZEOF_UNSIGNED_LONG_LONG_INT == 8
74 typedef unsigned long long int    u_int64_t;
75 typedef unsigned long long int     uint64_t;
76 #      elif SIZEOF_UNSIGNED_LONG_INT == 8
77 typedef unsigned long int    u_int64_t;
78 typedef unsigned long int     uint64_t;
79 #      endif
80 #    elif defined(HAVE_UINT64_T)
81 typedef uint64_t    u_int64_t;
82 #    else
83 typedef u_int64_t    uint64_t;
84 #    endif  /* !defined(HAVE_UINT64_T) && !defined(HAVE_U_INT64_T) */
85 #  endif  /* !defined(HAVE_UINT64_T) || !defined(HAVE_U_INT64_T) */
86 #  ifndef HAVE_INT8_T
87 typedef char     int8_t;
88 #  endif
89 #  ifndef HAVE_INT16_T
90 typedef short   int16_t;
91 #  endif
92 #  ifndef HAVE_INT32_T
93 #    if SIZEOF_LONG_INT == 4
94 typedef long int   int32_t;
95 #    else
96 typedef int        int32_t;
97 #    endif
98 #  endif
99 #  ifndef HAVE_INT64_T
100 #    if SIZEOF_LONG_LONG_INT == 8
101 typedef long long int    int64_t;
102 #    else
103 typedef long int         int64_t;
104 #    endif
105 #  endif
106 #  ifndef WIN32
107 #    ifdef HAVE_INTTYPES_H
108 /* <inttypes.h> includes <stdint.h> */
109 #      include <inttypes.h>
110 #    elif HAVE_STDINT_H
111 #      include <stdint.h>
112 #    else
113 /* Solaris - if inttypes.h is present, it should bring this in */
114 #      ifndef SYS_INT_TYPES_H
115 #        if defined(_LP64) || defined(_I32LPx)
116 typedef long int           intptr_t;
117 typedef unsigned long int  uintptr_t;
118 #        else
119 typedef int           intptr_t;
120 typedef unsigned int  uintptr_t;
121 #        endif  /* defined(_LP64) || defined(_I32LPx) */
122 #      endif  /* SYS_INT_TYPES_H */
123 #    endif  /* HAVE_INTTYPES_H elseif HAVE_STDINT_H */
124 #  endif
125 #endif  /* WIN32 */
126 #endif  /* HAVE_CONFIG_H */
127 
128 /* if PRIu64 isn't in <inttypes.h>
129  * we define it and similar here */
130 #ifndef PRIu64
131 #  if SIZEOF_UNSIGNED_LONG_INT == 8
132 #    define _SF_PREFIX "l"
133 #  else
134 #    define _SF_PREFIX "ll"
135 #  endif  /* SIZEOF_UNSIGNED_LONG_INT == 8 */
136 #  define PRIu64 _SF_PREFIX "u"
137 #  define PRIi64 _SF_PREFIX "i"
138 #endif  /* PRIu64 */
139 
140 /* use these macros (and those in <inttypes.h>)
141  * for 64 bit format portability
142  */
143 #define STDu64 "%" PRIu64
144 #define CSVu64 STDu64 ","
145 #define FMTu64(fmt) "%" fmt PRIu64
146 
147 #define STDi64 "%" PRIi64
148 #define CSVi64 STDi64 ","
149 #define FMTi64(fmt) "%" fmt PRIi64
150 
151 #ifndef UINT8_MAX
152 #  define UINT8_MAX 0xff
153 #endif
154 #ifndef USHRT_MAX
155 #  define USHRT_MAX  0xffff
156 #endif
157 #ifndef UINT16_MAX
158 #  define UINT16_MAX 0xffff
159 #endif
160 #ifndef UINT32_MAX
161 #  define UINT32_MAX (4294967295U)
162 #endif
163 #ifndef UINT64_MAX
164 #  if SIZEOF_UNSIGNED_LONG_INT == 8
165 #    define UINT64_MAX (18446744073709551615UL)
166 #  else
167 #    define UINT64_MAX (18446744073709551615ULL)
168 #  endif  /* SIZEOF_UNSIGNED_LONG_INT == 8 */
169 #endif  /* UINT64_MAX */
170 
171 /* Somewhat arbitrary, but should be enough for this application
172  * since files shouldn't be buried too deep.  This provides about
173  * 15 levels of 255 character path components */
174 #ifndef PATH_MAX
175 #  define PATH_MAX 4096
176 #endif
177 
178 #define MAXPORTS 65536
179 #define MAXPORTS_STORAGE 8192
180 
181 #endif  /* __SF_TYPES_H__ */
182 
183