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
52 void ScanBuildMarkSanitized(
const void *);
56 #define __has_feature(x) 0
58 #if defined(__has_feature)
59 #if __has_feature(address_sanitizer)
60 #define SC_ADDRESS_SANITIZER 1
62 #elif defined(__SANITIZE_ADDRESS__)
63 #define SC_ADDRESS_SANITIZER 1
69 #define REVISION "undefined"
71 #ifndef __SCFILENAME__
72 #define __SCFILENAME__ "undefined"
76 #warning "L1 cache line size not detected during build. Assuming 64 bytes."
117 #include <inttypes.h>
144 #if HAVE_SYS_SYSCALL_H
145 #include <sys/syscall.h>
153 #include <sys/types.h>
160 #ifdef HAVE_TYPE_U_LONG_NOT_DEFINED
161 typedef unsigned long int u_long;
163 #ifdef HAVE_TYPE_U_INT_NOT_DEFINED
164 typedef unsigned int u_int;
166 #ifdef HAVE_TYPE_U_SHORT_NOT_DEFINED
167 typedef unsigned short u_short;
169 #ifdef HAVE_TYPE_U_CHAR_NOT_DEFINED
170 typedef unsigned char u_char;
189 #include <sys/time.h>
196 #if HAVE_SYS_SIGNAL_H
197 #include <sys/signal.h>
204 #if HAVE_SYS_SOCKET_H
205 #include <sys/socket.h>
209 #include <sys/stat.h>
213 #include <sys/ioctl.h>
217 #include <sys/mman.h>
220 #if HAVE_SYS_RANDOM_H
221 #include <sys/random.h>
224 #if HAVE_NETINET_IN_H
225 #include <netinet/in.h>
229 #include <arpa/inet.h>
241 #if !defined _X86_ && !defined __x86_64
247 #ifdef HAVE_WINSOCK2_H
248 #include <winsock2.h>
250 #ifdef HAVE_WS2TCPIP_H
251 #include <ws2tcpip.h>
255 #ifdef HAVE_WINDOWS_H
257 #define _WIN32_WINNT 0x0501
262 #ifdef HAVE_W32API_WINBASE_H
263 #include <w32api/winbase.h>
266 #ifdef HAVE_W32API_WTYPES_H
267 #include <w32api/wtypes.h>
270 #ifndef SC_PCAP_DONT_INCLUDE_PCAP_H
275 #ifdef HAVE_PCAP_PCAP_H
276 #include <pcap/pcap.h>
297 #ifndef JSON_ESCAPE_SLASH
298 #define JSON_ESCAPE_SLASH 0
309 #ifdef HAVE_MM_MALLOC_H
310 #include <mm_malloc.h>
315 #define xstr(s) str(s)
319 #define BUG_ON(x) if (((x))) exit(1)
321 #if defined HAVE_ASSERT_H && !defined NDEBUG
323 #define BUG_ON(x) assert(!(x))
325 #define BUG_ON(x) do { \
327 fprintf(stderr, "BUG at %s:%d(%s)\n", __FILE__, __LINE__, __func__); \
328 fprintf(stderr, "Code: '%s'\n", xstr((x))); \
329 exit(EXIT_FAILURE); \
340 #define SigIntId uint32_t
343 #define PatIntId uint32_t
348 #define __WORDSIZE __LONG_BIT
351 #define __WORDSIZE LONG_BIT
358 #if defined(__X86__) || defined(_X86_) || defined(_M_IX86)
359 #define __WORDSIZE 32
361 #if defined(__X86_64__) || defined(_X86_64_) || \
362 defined(__x86_64) || defined(__x86_64__) || \
363 defined(__amd64) || defined(__amd64__)
364 #define __WORDSIZE 64
371 #if defined(_ILP32) || defined(__ILP32__)
372 #define __WORDSIZE 32
374 #if defined(_LP64) || defined(__LP64__)
375 #define __WORDSIZE 64
380 #warning Defaulting to __WORDSIZE 32
381 #define __WORDSIZE 32
386 #if defined(BYTE_ORDER)
387 #define __BYTE_ORDER BYTE_ORDER
388 #elif defined(__BYTE_ORDER__)
389 #define __BYTE_ORDER __BYTE_ORDER__
391 #error "byte order not detected"
395 #ifndef __LITTLE_ENDIAN
396 #if defined(LITTLE_ENDIAN)
397 #define __LITTLE_ENDIAN LITTLE_ENDIAN
398 #elif defined(__ORDER_LITTLE_ENDIAN__)
399 #define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
404 #if defined(BIG_ENDIAN)
405 #define __BIG_ENDIAN BIG_ENDIAN
406 #elif defined(__ORDER_BIG_ENDIAN__)
407 #define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
411 #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
412 #error "byte order: can't figure out big or little"
416 #define MIN(x, y) (((x)<(y))?(x):(y))
420 #define MAX(x, y) (((x)<(y))?(y):(x))
423 #define BIT_U8(n) ((uint8_t)(1 << (n)))
424 #define BIT_U16(n) ((uint16_t)(1 << (n)))
425 #define BIT_U32(n) ((uint32_t)(1UL << (n)))
426 #define BIT_U64(n) (1ULL << (n))
428 #define WARN_UNUSED __attribute__((warn_unused_result))
430 #if defined(__MINGW32__)
431 #define ATTR_FMT_PRINTF(x, y) __attribute__((format(__MINGW_PRINTF_FORMAT, (x), (y))))
432 #elif defined(__GNUC__)
433 #define ATTR_FMT_PRINTF(x, y) __attribute__((format(printf, (x), (y))))
435 #define ATTR_FMT_PRINTF(x, y)
438 #define SCNtohl(x) (uint32_t)ntohl((x))
439 #define SCNtohs(x) (uint16_t)ntohs((x))
442 #define SWAP_FLAGS(flags, a, b) \
444 if (((flags) & ((a)|(b))) == (a)) { \
447 } else if (((flags) & ((a)|(b))) == (b)) { \
453 #define SWAP_VARS(type, a, b) \
461 #define u8_tolower(c) ((uint8_t)tolower((uint8_t)(c)))
462 #define u8_toupper(c) ((uint8_t)toupper((uint8_t)(c)))
545 size_t strlcat(
char *,
const char *
src,
size_t siz);
550 #ifndef HAVE_STRPTIME
551 char *
strptime(
const char * __restrict,
const char * __restrict,
struct tm * __restrict);
554 #ifndef HAVE_FWRITE_UNLOCKED
555 #define SCFwriteUnlocked fwrite
556 #define SCFflushUnlocked fflush
557 #define SCClearErrUnlocked clearerr
558 #define SCFerrorUnlocked ferror
560 #define SCFwriteUnlocked fwrite_unlocked
561 #define SCFflushUnlocked fflush_unlocked
562 #define SCClearErrUnlocked clearerr_unlocked
563 #define SCFerrorUnlocked ferror_unlocked
569 #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