Go to the documentation of this file.
24 #ifndef SURICATA_UTIL_BYTE_H
25 #define SURICATA_UTIL_BYTE_H
29 #define BYTE_BIG_ENDIAN 0
30 #define BYTE_LITTLE_ENDIAN 1
34 #include <sys/endian.h>
35 #define SCByteSwap16(x) bswap16(x)
36 #define SCByteSwap32(x) bswap32(x)
37 #define SCByteSwap64(x) bswap64(x)
38 #elif defined __OpenBSD__
39 #include <sys/types.h>
40 #define SCByteSwap16(x) swap16(x)
41 #define SCByteSwap32(x) swap32(x)
42 #define SCByteSwap64(x) swap64(x)
44 #include <libkern/OSByteOrder.h>
45 #define SCByteSwap16(x) OSSwapInt16(x)
46 #define SCByteSwap32(x) OSSwapInt32(x)
47 #define SCByteSwap64(x) OSSwapInt64(x)
48 #elif defined(__WIN32) || defined(_WIN32) || defined(sun)
50 #define SCByteSwap16(x) \
51 ((((x) & 0xff00) >> 8) \
52 | (((x) & 0x00ff) << 8))
53 #define SCByteSwap32(x) \
54 ((((x) & 0xff000000) >> 24) \
55 | (((x) & 0x00ff0000) >> 8) \
56 | (((x) & 0x0000ff00) << 8) \
57 | (((x) & 0x000000ff) << 24))
58 #define SCByteSwap64(x) \
59 ((((x) & 0xff00000000000000ull) >> 56) \
60 | (((x) & 0x00ff000000000000ull) >> 40) \
61 | (((x) & 0x0000ff0000000000ull) >> 24) \
62 | (((x) & 0x000000ff00000000ull) >> 8) \
63 | (((x) & 0x00000000ff000000ull) << 8) \
64 | (((x) & 0x0000000000ff0000ull) << 24) \
65 | (((x) & 0x000000000000ff00ull) << 40) \
66 | (((x) & 0x00000000000000ffull) << 56))
69 #define SCByteSwap16(x) bswap_16(x)
70 #define SCByteSwap32(x) bswap_32(x)
71 #define SCByteSwap64(x) bswap_64(x)
138 uint64_t *res,
int base,
size_t len,
const char *
str,
bool strict);
205 int64_t *res,
int base,
size_t len,
const char *
str,
bool strict);
375 uint64_t *res,
int base,
size_t len,
const char *
str, uint64_t min, uint64_t max);
389 uint32_t *res,
int base,
size_t len,
const char *
str, uint32_t min, uint32_t max);
403 uint16_t *res,
int base,
size_t len,
const char *
str, uint16_t min, uint16_t max);
417 uint8_t *res,
int base,
size_t len,
const char *
str, uint8_t min, uint8_t max);
431 int64_t *res,
int base,
size_t len,
const char *
str, int64_t min, int64_t max);
445 int32_t *res,
int base,
size_t len,
const char *
str, int32_t min, int32_t max);
459 int16_t *res,
int base,
size_t len,
const char *
str, int16_t min, int16_t max);
473 int8_t *res,
int base,
size_t len,
const char *
str, int8_t min, int8_t max);
480 static inline int WARN_UNUSED ByteExtract(uint64_t *res,
int e, uint16_t
len,
const uint8_t *bytes)
491 for (
int i = 0; i <
len; i++) {
497 b = bytes[
len - i - 1];
500 *res |= (b << ((i & 7) << 3));
int WARN_UNUSED ByteExtractStringInt32(int32_t *res, int base, size_t len, const char *str)
int WARN_UNUSED ByteExtractUint32(uint32_t *res, int e, uint16_t len, const uint8_t *bytes)
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
int WARN_UNUSED ByteExtractStringInt64(int64_t *res, int base, size_t len, const char *str)
int WARN_UNUSED StringParseI32RangeCheck(int32_t *res, int base, size_t len, const char *str, int32_t min, int32_t max)
int WARN_UNUSED ByteExtractStringSigned(int64_t *res, int base, size_t len, const char *str, bool strict)
void BytesToStringBuffer(const uint8_t *bytes, size_t nbytes, char *outstr, size_t outlen)
Turn byte array into string.
int WARN_UNUSED ByteExtractStringUint64(uint64_t *res, int base, size_t len, const char *str)
int WARN_UNUSED ByteExtractStringUint32(uint32_t *res, int base, size_t len, const char *str)
int WARN_UNUSED StringParseU16RangeCheck(uint16_t *res, int base, size_t len, const char *str, uint16_t min, uint16_t max)
int WARN_UNUSED ByteExtractUint16(uint16_t *res, int e, uint16_t len, const uint8_t *bytes)
int WARN_UNUSED ByteExtractUint64(uint64_t *res, int e, uint16_t len, const uint8_t *bytes)
int StringParseUint8(uint8_t *res, int base, size_t len, const char *str)
int WARN_UNUSED ByteExtractStringUint8(uint8_t *res, int base, size_t len, const char *str)
int WARN_UNUSED ByteExtractStringUint16(uint16_t *res, int base, size_t len, const char *str)
int WARN_UNUSED StringParseU64RangeCheck(uint64_t *res, int base, size_t len, const char *str, uint64_t min, uint64_t max)
char * BytesToString(const uint8_t *bytes, size_t nbytes)
Turn byte array into string.
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
int StringParseInt16(int16_t *res, int base, size_t len, const char *str)
int WARN_UNUSED StringParseI16RangeCheck(int16_t *res, int base, size_t len, const char *str, int16_t min, int16_t max)
#define BYTE_LITTLE_ENDIAN
int WARN_UNUSED ByteExtractString(uint64_t *res, int base, size_t len, const char *str, bool strict)
int WARN_UNUSED StringParseI8RangeCheck(int8_t *res, int base, size_t len, const char *str, int8_t min, int8_t max)
int StringParseInt8(int8_t *res, int base, size_t len, const char *str)
int WARN_UNUSED StringParseU32RangeCheck(uint32_t *res, int base, size_t len, const char *str, uint32_t min, uint32_t max)
int WARN_UNUSED ByteExtractStringInt16(int16_t *res, int base, size_t len, const char *str)
int WARN_UNUSED StringParseI64RangeCheck(int64_t *res, int base, size_t len, const char *str, int64_t min, int64_t max)
int StringParseInt32(int32_t *res, int base, size_t len, const char *str)
void ByteRegisterTests(void)
int StringParseInt64(int64_t *res, int base, size_t len, const char *str)
int WARN_UNUSED ByteExtractStringInt8(int8_t *res, int base, size_t len, const char *str)
int StringParseUint64(uint64_t *res, int base, size_t len, const char *str)
int WARN_UNUSED StringParseU8RangeCheck(uint8_t *res, int base, size_t len, const char *str, uint8_t min, uint8_t max)