Go to the documentation of this file.
26 #ifndef SURICATA_SURICATA_COMMON_H
27 #define SURICATA_SURICATA_COMMON_H
36 #if defined(__clang_analyzer__)
39 #define DEBUG_VALIDATION 1
42 #if defined(__has_feature)
43 #if __has_feature(address_sanitizer)
44 #define SC_ADDRESS_SANITIZER 1
46 #elif defined(__SANITIZE_ADDRESS__)
47 #define SC_ADDRESS_SANITIZER 1
55 #warning "L1 cache line size not detected during build. Assuming 64 bytes."
123 #if HAVE_SYS_SYSCALL_H
124 #include <sys/syscall.h>
132 #include <sys/types.h>
139 #ifdef HAVE_TYPE_U_LONG_NOT_DEFINED
140 typedef unsigned long int u_long;
142 #ifdef HAVE_TYPE_U_INT_NOT_DEFINED
143 typedef unsigned int u_int;
145 #ifdef HAVE_TYPE_U_SHORT_NOT_DEFINED
146 typedef unsigned short u_short;
148 #ifdef HAVE_TYPE_U_CHAR_NOT_DEFINED
149 typedef unsigned char u_char;
168 #include <sys/time.h>
175 #if HAVE_SYS_SIGNAL_H
176 #include <sys/signal.h>
183 #if HAVE_SYS_SOCKET_H
184 #include <sys/socket.h>
188 #include <sys/stat.h>
192 #include <sys/ioctl.h>
196 #include <sys/mman.h>
199 #if HAVE_SYS_RANDOM_H
200 #include <sys/random.h>
203 #if HAVE_NETINET_IN_H
204 #include <netinet/in.h>
208 #include <arpa/inet.h>
220 #if !defined _X86_ && !defined __x86_64
226 #ifdef HAVE_WINSOCK2_H
227 #include <winsock2.h>
229 #ifdef HAVE_WS2TCPIP_H
230 #include <ws2tcpip.h>
234 #ifdef HAVE_WINDOWS_H
236 #define _WIN32_WINNT 0x0501
241 #ifdef HAVE_W32API_WINBASE_H
242 #include <w32api/winbase.h>
245 #ifdef HAVE_W32API_WTYPES_H
246 #include <w32api/wtypes.h>
249 #ifndef SC_PCAP_DONT_INCLUDE_PCAP_H
254 #ifdef HAVE_PCAP_PCAP_H
255 #include <pcap/pcap.h>
276 #ifndef JSON_ESCAPE_SLASH
277 #define JSON_ESCAPE_SLASH 0
290 #define xstr(s) str(s)
294 #define BUG_ON(x) if (((x))) exit(1)
296 #if defined HAVE_ASSERT_H && !defined NDEBUG
298 #define BUG_ON(x) assert(!(x))
300 #define BUG_ON(x) do { \
302 fprintf(stderr, "BUG at %s:%d(%s)\n", __FILE__, __LINE__, __func__); \
303 fprintf(stderr, "Code: '%s'\n", xstr((x))); \
304 exit(EXIT_FAILURE); \
315 #define SigIntId uint32_t
318 #define PatIntId uint32_t
323 #define __WORDSIZE __LONG_BIT
326 #define __WORDSIZE LONG_BIT
333 #if defined(__X86__) || defined(_X86_) || defined(_M_IX86)
334 #define __WORDSIZE 32
336 #if defined(__X86_64__) || defined(_X86_64_) || \
337 defined(__x86_64) || defined(__x86_64__) || \
338 defined(__amd64) || defined(__amd64__)
339 #define __WORDSIZE 64
346 #if defined(_ILP32) || defined(__ILP32__)
347 #define __WORDSIZE 32
349 #if defined(_LP64) || defined(__LP64__)
350 #define __WORDSIZE 64
355 #warning Defaulting to __WORDSIZE 32
356 #define __WORDSIZE 32
361 #if defined(BYTE_ORDER)
362 #define __BYTE_ORDER BYTE_ORDER
363 #elif defined(__BYTE_ORDER__)
364 #define __BYTE_ORDER __BYTE_ORDER__
366 #error "byte order not detected"
370 #ifndef __LITTLE_ENDIAN
371 #if defined(LITTLE_ENDIAN)
372 #define __LITTLE_ENDIAN LITTLE_ENDIAN
373 #elif defined(__ORDER_LITTLE_ENDIAN__)
374 #define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
379 #if defined(BIG_ENDIAN)
380 #define __BIG_ENDIAN BIG_ENDIAN
381 #elif defined(__ORDER_BIG_ENDIAN__)
382 #define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
386 #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
387 #error "byte order: can't figure out big or little"
391 #define MIN(x, y) (((x)<(y))?(x):(y))
395 #define MAX(x, y) (((x)<(y))?(y):(x))
398 #define BIT_U8(n) ((uint8_t)(1 << (n)))
399 #define BIT_U16(n) ((uint16_t)(1 << (n)))
400 #define BIT_U32(n) ((uint32_t)(1UL << (n)))
401 #define BIT_U64(n) (1ULL << (n))
403 #define WARN_UNUSED __attribute__((warn_unused_result))
405 #if defined(__MINGW32__)
406 #define ATTR_FMT_PRINTF(x, y) __attribute__((format(__MINGW_PRINTF_FORMAT, (x), (y))))
407 #elif defined(__GNUC__)
408 #define ATTR_FMT_PRINTF(x, y) __attribute__((format(printf, (x), (y))))
410 #define ATTR_FMT_PRINTF(x, y)
413 #define SCNtohl(x) (uint32_t)ntohl((x))
414 #define SCNtohs(x) (uint16_t)ntohs((x))
417 #define SWAP_FLAGS(flags, a, b) \
419 if (((flags) & ((a)|(b))) == (a)) { \
422 } else if (((flags) & ((a)|(b))) == (b)) { \
428 #define SWAP_VARS(type, a, b) \
436 #define u8_tolower(c) ((uint8_t)tolower((uint8_t)(c)))
437 #define u8_toupper(c) ((uint8_t)toupper((uint8_t)(c)))
521 size_t strlcat(
char *,
const char *
src,
size_t siz);
526 #ifndef HAVE_STRPTIME
527 char *
strptime(
const char * __restrict,
const char * __restrict,
struct tm * __restrict);
530 #ifndef HAVE_FWRITE_UNLOCKED
531 #define SCFwriteUnlocked fwrite
532 #define SCFflushUnlocked fflush
533 #define SCClearErrUnlocked clearerr
534 #define SCFerrorUnlocked ferror
536 #define SCFwriteUnlocked fwrite_unlocked
537 #define SCFflushUnlocked fflush_unlocked
538 #define SCClearErrUnlocked clearerr_unlocked
539 #define SCFerrorUnlocked ferror_unlocked
545 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
size_t strlcpy(char *dst, const char *src, size_t siz)
struct lua_State lua_State
char * strptime(const char *__restrict, const char *__restrict, struct tm *__restrict)
size_t strlcat(char *, const char *src, size_t siz)
enum PacketProfileDetectId_ PacketProfileDetectId
@ LOGGER_TLS_STORE_CLIENT