Go to the documentation of this file.
26 #ifndef SURICATA_SURICATA_COMMON_H
27 #define SURICATA_SURICATA_COMMON_H
44 #if defined(__clang_analyzer__)
47 #define DEBUG_VALIDATION 1
50 #if defined(__has_feature)
51 #if __has_feature(address_sanitizer)
52 #define SC_ADDRESS_SANITIZER 1
54 #elif defined(__SANITIZE_ADDRESS__)
55 #define SC_ADDRESS_SANITIZER 1
61 #define REVISION "undefined"
63 #ifndef __SCFILENAME__
64 #define __SCFILENAME__ "undefined"
68 #warning "L1 cache line size not detected during build. Assuming 64 bytes."
109 #include <inttypes.h>
136 #if HAVE_SYS_SYSCALL_H
137 #include <sys/syscall.h>
145 #include <sys/types.h>
152 #ifdef HAVE_TYPE_U_LONG_NOT_DEFINED
153 typedef unsigned long int u_long;
155 #ifdef HAVE_TYPE_U_INT_NOT_DEFINED
156 typedef unsigned int u_int;
158 #ifdef HAVE_TYPE_U_SHORT_NOT_DEFINED
159 typedef unsigned short u_short;
161 #ifdef HAVE_TYPE_U_CHAR_NOT_DEFINED
162 typedef unsigned char u_char;
181 #include <sys/time.h>
188 #if HAVE_SYS_SIGNAL_H
189 #include <sys/signal.h>
196 #if HAVE_SYS_SOCKET_H
197 #include <sys/socket.h>
201 #include <sys/stat.h>
205 #include <sys/ioctl.h>
209 #include <sys/mman.h>
212 #if HAVE_SYS_RANDOM_H
213 #include <sys/random.h>
216 #if HAVE_NETINET_IN_H
217 #include <netinet/in.h>
221 #include <arpa/inet.h>
233 #if !defined _X86_ && !defined __x86_64
239 #ifdef HAVE_WINSOCK2_H
240 #include <winsock2.h>
242 #ifdef HAVE_WS2TCPIP_H
243 #include <ws2tcpip.h>
247 #ifdef HAVE_WINDOWS_H
249 #define _WIN32_WINNT 0x0501
254 #ifdef HAVE_W32API_WINBASE_H
255 #include <w32api/winbase.h>
258 #ifdef HAVE_W32API_WTYPES_H
259 #include <w32api/wtypes.h>
262 #ifndef SC_PCAP_DONT_INCLUDE_PCAP_H
267 #ifdef HAVE_PCAP_PCAP_H
268 #include <pcap/pcap.h>
289 #ifndef JSON_ESCAPE_SLASH
290 #define JSON_ESCAPE_SLASH 0
301 #ifdef HAVE_MM_MALLOC_H
302 #include <mm_malloc.h>
307 #define xstr(s) str(s)
311 #define BUG_ON(x) if (((x))) exit(1)
313 #if defined HAVE_ASSERT_H && !defined NDEBUG
315 #define BUG_ON(x) assert(!(x))
317 #define BUG_ON(x) do { \
319 fprintf(stderr, "BUG at %s:%d(%s)\n", __FILE__, __LINE__, __func__); \
320 fprintf(stderr, "Code: '%s'\n", xstr((x))); \
321 exit(EXIT_FAILURE); \
332 #define SigIntId uint32_t
335 #define PatIntId uint32_t
340 #define __WORDSIZE __LONG_BIT
343 #define __WORDSIZE LONG_BIT
350 #if defined(__X86__) || defined(_X86_) || defined(_M_IX86)
351 #define __WORDSIZE 32
353 #if defined(__X86_64__) || defined(_X86_64_) || \
354 defined(__x86_64) || defined(__x86_64__) || \
355 defined(__amd64) || defined(__amd64__)
356 #define __WORDSIZE 64
363 #if defined(_ILP32) || defined(__ILP32__)
364 #define __WORDSIZE 32
366 #if defined(_LP64) || defined(__LP64__)
367 #define __WORDSIZE 64
372 #warning Defaulting to __WORDSIZE 32
373 #define __WORDSIZE 32
378 #if defined(BYTE_ORDER)
379 #define __BYTE_ORDER BYTE_ORDER
380 #elif defined(__BYTE_ORDER__)
381 #define __BYTE_ORDER __BYTE_ORDER__
383 #error "byte order not detected"
387 #ifndef __LITTLE_ENDIAN
388 #if defined(LITTLE_ENDIAN)
389 #define __LITTLE_ENDIAN LITTLE_ENDIAN
390 #elif defined(__ORDER_LITTLE_ENDIAN__)
391 #define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
396 #if defined(BIG_ENDIAN)
397 #define __BIG_ENDIAN BIG_ENDIAN
398 #elif defined(__ORDER_BIG_ENDIAN__)
399 #define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
403 #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
404 #error "byte order: can't figure out big or little"
408 #define MIN(x, y) (((x)<(y))?(x):(y))
412 #define MAX(x, y) (((x)<(y))?(y):(x))
415 #define BIT_U8(n) ((uint8_t)(1 << (n)))
416 #define BIT_U16(n) ((uint16_t)(1 << (n)))
417 #define BIT_U32(n) ((uint32_t)(1UL << (n)))
418 #define BIT_U64(n) (1ULL << (n))
420 #define WARN_UNUSED __attribute__((warn_unused_result))
422 #if defined(__MINGW32__)
423 #define ATTR_FMT_PRINTF(x, y) __attribute__((format(__MINGW_PRINTF_FORMAT, (x), (y))))
424 #elif defined(__GNUC__)
425 #define ATTR_FMT_PRINTF(x, y) __attribute__((format(printf, (x), (y))))
427 #define ATTR_FMT_PRINTF(x, y)
430 #define SCNtohl(x) (uint32_t)ntohl((x))
431 #define SCNtohs(x) (uint16_t)ntohs((x))
434 #define SWAP_FLAGS(flags, a, b) \
436 if (((flags) & ((a)|(b))) == (a)) { \
439 } else if (((flags) & ((a)|(b))) == (b)) { \
445 #define SWAP_VARS(type, a, b) \
453 #define u8_tolower(c) ((uint8_t)tolower((uint8_t)(c)))
454 #define u8_toupper(c) ((uint8_t)toupper((uint8_t)(c)))
538 size_t strlcat(
char *,
const char *
src,
size_t siz);
543 #ifndef HAVE_STRPTIME
544 char *
strptime(
const char * __restrict,
const char * __restrict,
struct tm * __restrict);
547 #ifndef HAVE_FWRITE_UNLOCKED
548 #define SCFwriteUnlocked fwrite
549 #define SCFflushUnlocked fflush
550 #define SCClearErrUnlocked clearerr
551 #define SCFerrorUnlocked ferror
553 #define SCFwriteUnlocked fwrite_unlocked
554 #define SCFflushUnlocked fflush_unlocked
555 #define SCClearErrUnlocked clearerr_unlocked
556 #define SCFerrorUnlocked ferror_unlocked
562 #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