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
53 #define REVISION "undefined"
55 #ifndef __SCFILENAME__
56 #define __SCFILENAME__ "undefined"
60 #warning "L1 cache line size not detected during build. Assuming 64 bytes."
101 #include <inttypes.h>
128 #if HAVE_SYS_SYSCALL_H
129 #include <sys/syscall.h>
137 #include <sys/types.h>
144 #ifdef HAVE_TYPE_U_LONG_NOT_DEFINED
145 typedef unsigned long int u_long;
147 #ifdef HAVE_TYPE_U_INT_NOT_DEFINED
148 typedef unsigned int u_int;
150 #ifdef HAVE_TYPE_U_SHORT_NOT_DEFINED
151 typedef unsigned short u_short;
153 #ifdef HAVE_TYPE_U_CHAR_NOT_DEFINED
154 typedef unsigned char u_char;
173 #include <sys/time.h>
180 #if HAVE_SYS_SIGNAL_H
181 #include <sys/signal.h>
188 #if HAVE_SYS_SOCKET_H
189 #include <sys/socket.h>
193 #include <sys/stat.h>
197 #include <sys/ioctl.h>
201 #include <sys/mman.h>
204 #if HAVE_SYS_RANDOM_H
205 #include <sys/random.h>
208 #if HAVE_NETINET_IN_H
209 #include <netinet/in.h>
213 #include <arpa/inet.h>
225 #if !defined _X86_ && !defined __x86_64
231 #ifdef HAVE_WINSOCK2_H
232 #include <winsock2.h>
234 #ifdef HAVE_WS2TCPIP_H
235 #include <ws2tcpip.h>
239 #ifdef HAVE_WINDOWS_H
241 #define _WIN32_WINNT 0x0501
246 #ifdef HAVE_W32API_WINBASE_H
247 #include <w32api/winbase.h>
250 #ifdef HAVE_W32API_WTYPES_H
251 #include <w32api/wtypes.h>
254 #ifndef SC_PCAP_DONT_INCLUDE_PCAP_H
259 #ifdef HAVE_PCAP_PCAP_H
260 #include <pcap/pcap.h>
281 #ifndef JSON_ESCAPE_SLASH
282 #define JSON_ESCAPE_SLASH 0
293 #ifdef HAVE_MM_MALLOC_H
294 #include <mm_malloc.h>
299 #define xstr(s) str(s)
303 #define BUG_ON(x) if (((x))) exit(1)
305 #if defined HAVE_ASSERT_H && !defined NDEBUG
307 #define BUG_ON(x) assert(!(x))
309 #define BUG_ON(x) do { \
311 fprintf(stderr, "BUG at %s:%d(%s)\n", __FILE__, __LINE__, __func__); \
312 fprintf(stderr, "Code: '%s'\n", xstr((x))); \
313 exit(EXIT_FAILURE); \
324 #define SigIntId uint32_t
327 #define PatIntId uint32_t
332 #define __WORDSIZE __LONG_BIT
335 #define __WORDSIZE LONG_BIT
342 #if defined(__X86__) || defined(_X86_) || defined(_M_IX86)
343 #define __WORDSIZE 32
345 #if defined(__X86_64__) || defined(_X86_64_) || \
346 defined(__x86_64) || defined(__x86_64__) || \
347 defined(__amd64) || defined(__amd64__)
348 #define __WORDSIZE 64
355 #if defined(_ILP32) || defined(__ILP32__)
356 #define __WORDSIZE 32
358 #if defined(_LP64) || defined(__LP64__)
359 #define __WORDSIZE 64
364 #warning Defaulting to __WORDSIZE 32
365 #define __WORDSIZE 32
370 #if defined(BYTE_ORDER)
371 #define __BYTE_ORDER BYTE_ORDER
372 #elif defined(__BYTE_ORDER__)
373 #define __BYTE_ORDER __BYTE_ORDER__
375 #error "byte order not detected"
379 #ifndef __LITTLE_ENDIAN
380 #if defined(LITTLE_ENDIAN)
381 #define __LITTLE_ENDIAN LITTLE_ENDIAN
382 #elif defined(__ORDER_LITTLE_ENDIAN__)
383 #define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
388 #if defined(BIG_ENDIAN)
389 #define __BIG_ENDIAN BIG_ENDIAN
390 #elif defined(__ORDER_BIG_ENDIAN__)
391 #define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
395 #if !defined(__LITTLE_ENDIAN) && !defined(__BIG_ENDIAN)
396 #error "byte order: can't figure out big or little"
400 #define MIN(x, y) (((x)<(y))?(x):(y))
404 #define MAX(x, y) (((x)<(y))?(y):(x))
407 #define BIT_U8(n) ((uint8_t)(1 << (n)))
408 #define BIT_U16(n) ((uint16_t)(1 << (n)))
409 #define BIT_U32(n) ((uint32_t)(1UL << (n)))
410 #define BIT_U64(n) (1ULL << (n))
412 #define WARN_UNUSED __attribute__((warn_unused_result))
414 #if defined(__MINGW32__)
415 #define ATTR_FMT_PRINTF(x, y) __attribute__((format(__MINGW_PRINTF_FORMAT, (x), (y))))
416 #elif defined(__GNUC__)
417 #define ATTR_FMT_PRINTF(x, y) __attribute__((format(printf, (x), (y))))
419 #define ATTR_FMT_PRINTF(x, y)
422 #define SCNtohl(x) (uint32_t)ntohl((x))
423 #define SCNtohs(x) (uint16_t)ntohs((x))
426 #define SWAP_FLAGS(flags, a, b) \
428 if (((flags) & ((a)|(b))) == (a)) { \
431 } else if (((flags) & ((a)|(b))) == (b)) { \
437 #define SWAP_VARS(type, a, b) \
445 #define u8_tolower(c) ((uint8_t)tolower((uint8_t)(c)))
446 #define u8_toupper(c) ((uint8_t)toupper((uint8_t)(c)))
530 size_t strlcat(
char *,
const char *
src,
size_t siz);
535 #ifndef HAVE_STRPTIME
536 char *
strptime(
const char * __restrict,
const char * __restrict,
struct tm * __restrict);
539 #ifndef HAVE_FWRITE_UNLOCKED
540 #define SCFwriteUnlocked fwrite
541 #define SCFflushUnlocked fflush
542 #define SCClearErrUnlocked clearerr
543 #define SCFerrorUnlocked ferror
545 #define SCFwriteUnlocked fwrite_unlocked
546 #define SCFflushUnlocked fflush_unlocked
547 #define SCClearErrUnlocked clearerr_unlocked
548 #define SCFerrorUnlocked ferror_unlocked
554 #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