|
suricata
|
#include <stdint.h>#include <byteswap.h>
Go to the source code of this file.
Macros | |
| #define | BYTE_BIG_ENDIAN 0 |
| #define | BYTE_LITTLE_ENDIAN 1 |
| #define | SCByteSwap16(x) bswap_16(x) |
| #define | SCByteSwap32(x) bswap_32(x) |
| #define | SCByteSwap64(x) bswap_64(x) |
Functions | |
| char * | BytesToString (const uint8_t *bytes, size_t nbytes) |
| Turn byte array into string. | |
| void | BytesToStringBuffer (const uint8_t *bytes, size_t nbytes, char *outstr, size_t outlen) |
| Turn byte array into string. | |
| int WARN_UNUSED | ByteExtractUint64 (uint64_t *res, int e, uint16_t len, const uint8_t *bytes) |
| int WARN_UNUSED | ByteExtractUint32 (uint32_t *res, int e, uint16_t len, const uint8_t *bytes) |
| int WARN_UNUSED | ByteExtractUint16 (uint16_t *res, int e, uint16_t len, const uint8_t *bytes) |
| int WARN_UNUSED | ByteExtractString (uint64_t *res, int base, size_t len, const char *str, bool strict) |
| 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 | ByteExtractStringUint16 (uint16_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 | ByteExtractStringSigned (int64_t *res, int base, size_t len, const char *str, bool strict) |
| int WARN_UNUSED | ByteExtractStringInt64 (int64_t *res, int base, size_t len, const char *str) |
| int WARN_UNUSED | ByteExtractStringInt32 (int32_t *res, int base, size_t len, const char *str) |
| int WARN_UNUSED | ByteExtractStringInt16 (int16_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 | StringParseUint32 (uint32_t *res, int base, size_t len, const char *str) |
| int | StringParseUint16 (uint16_t *res, int base, size_t len, const char *str) |
| int | StringParseUint8 (uint8_t *res, int base, size_t len, const char *str) |
| int | StringParseInt64 (int64_t *res, int base, size_t len, const char *str) |
| int | StringParseInt32 (int32_t *res, int base, size_t len, const char *str) |
| int | StringParseInt16 (int16_t *res, int base, size_t len, const char *str) |
| int | StringParseInt8 (int8_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) |
| int WARN_UNUSED | StringParseU32RangeCheck (uint32_t *res, int base, size_t len, const char *str, uint32_t min, uint32_t max) |
| int WARN_UNUSED | StringParseU16RangeCheck (uint16_t *res, int base, size_t len, const char *str, uint16_t min, uint16_t max) |
| int WARN_UNUSED | StringParseU8RangeCheck (uint8_t *res, int base, size_t len, const char *str, uint8_t min, uint8_t max) |
| int WARN_UNUSED | StringParseI64RangeCheck (int64_t *res, int base, size_t len, const char *str, int64_t min, int64_t max) |
| int WARN_UNUSED | StringParseI32RangeCheck (int32_t *res, int base, size_t len, const char *str, int32_t min, int32_t max) |
| int WARN_UNUSED | StringParseI16RangeCheck (int16_t *res, int base, size_t len, const char *str, int16_t min, int16_t max) |
| int WARN_UNUSED | StringParseI8RangeCheck (int8_t *res, int base, size_t len, const char *str, int8_t min, int8_t max) |
| void | ByteRegisterTests (void) |
| int | HexToRaw (const uint8_t *in, size_t ins, uint8_t *out, size_t outs) |
Definition in file util-byte.h.
| #define BYTE_BIG_ENDIAN 0 |
Definition at line 29 of file util-byte.h.
| #define BYTE_LITTLE_ENDIAN 1 |
Definition at line 30 of file util-byte.h.
| #define SCByteSwap16 | ( | x | ) | bswap_16(x) |
Wrappers for OS dependent byte swapping functions
Definition at line 69 of file util-byte.h.
| #define SCByteSwap32 | ( | x | ) | bswap_32(x) |
Definition at line 70 of file util-byte.h.
| #define SCByteSwap64 | ( | x | ) | bswap_64(x) |
Definition at line 71 of file util-byte.h.
| int WARN_UNUSED ByteExtractString | ( | uint64_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| bool | strict | ||
| ) |
Extract unsigned integer value from a string.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
| bool | Enable strict check for parsers |
Definition at line 185 of file util-byte.c.
References len, SCLogDebug, SCLogError, and str.
Referenced by ByteExtractStringUint16(), ByteExtractStringUint32(), ByteExtractStringUint64(), ByteExtractStringUint8(), StringParseU16RangeCheck(), StringParseU32RangeCheck(), StringParseU64RangeCheck(), StringParseU8RangeCheck(), StringParseUint16(), StringParseUint32(), StringParseUint64(), and StringParseUint8().

| int WARN_UNUSED ByteExtractStringInt16 | ( | int16_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract signed integer value from a string as uint16_t.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 567 of file util-byte.c.
References ByteExtractStringSigned(), len, SCLogError, and str.

| int WARN_UNUSED ByteExtractStringInt32 | ( | int32_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract signed integer value from a string as uint32_t.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 542 of file util-byte.c.
References ByteExtractStringSigned(), len, SCLogError, and str.

| int WARN_UNUSED ByteExtractStringInt64 | ( | int64_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract signed integer value from a string as uint64_t.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 537 of file util-byte.c.
References ByteExtractStringSigned(), len, and str.

| int WARN_UNUSED ByteExtractStringInt8 | ( | int8_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract signed integer value from a string as uint8_t.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 592 of file util-byte.c.
References ByteExtractStringSigned(), len, SCLogError, and str.

| int WARN_UNUSED ByteExtractStringSigned | ( | int64_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| bool | strict | ||
| ) |
Extract signed integer value from a string.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
| bool | Enable strict check for parsers |
Definition at line 491 of file util-byte.c.
References len, SCLogError, and str.
Referenced by ByteExtractStringInt16(), ByteExtractStringInt32(), ByteExtractStringInt64(), ByteExtractStringInt8(), StringParseI16RangeCheck(), StringParseI32RangeCheck(), StringParseI64RangeCheck(), StringParseI8RangeCheck(), StringParseInt16(), StringParseInt32(), StringParseInt64(), and StringParseInt8().

| int WARN_UNUSED ByteExtractStringUint16 | ( | uint16_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract unsigned integer value from a string as uint16_t.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 262 of file util-byte.c.
References ByteExtractString(), len, SCLogDebug, and str.

| int WARN_UNUSED ByteExtractStringUint32 | ( | uint32_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract unsigned integer value from a string as uint32_t.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 239 of file util-byte.c.
References ByteExtractString(), len, SCLogDebug, and str.
Referenced by CoredumpLoadConfig(), SCGetGroupID(), and SCGetUserID().


| int WARN_UNUSED ByteExtractStringUint64 | ( | uint64_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract unsigned integer value from a string as uint64_t.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 234 of file util-byte.c.
References ByteExtractString(), len, and str.
Referenced by CoredumpLoadConfig(), DetectByteExtractDoMatch(), DetectBytejumpDoMatch(), DetectByteMathDoMatch(), and DetectBytetestDoMatch().


| int WARN_UNUSED ByteExtractStringUint8 | ( | uint8_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract unsigned integer value from a string as uint8_t.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 285 of file util-byte.c.
References ByteExtractString(), len, SCLogDebug, and str.
Referenced by DetectProtoParse().


| int WARN_UNUSED ByteExtractUint16 | ( | uint16_t * | res, |
| int | e, | ||
| uint16_t | len, | ||
| const uint8_t * | bytes | ||
| ) |
Extract bytes from a byte string and convert to a unint16_t.
| res | Stores result |
| e | Endianness (BYTE_BIG_ENDIAN or BYTE_LITTLE_ENDIAN) |
| len | Number of bytes to extract (8 max) |
| bytes | Data to extract from |
Definition at line 164 of file util-byte.c.
References len.
| int WARN_UNUSED ByteExtractUint32 | ( | uint32_t * | res, |
| int | e, | ||
| uint16_t | len, | ||
| const uint8_t * | bytes | ||
| ) |
Extract bytes from a byte string and convert to a uint32_t.
| res | Stores result |
| e | Endianness (BYTE_BIG_ENDIAN or BYTE_LITTLE_ENDIAN) |
| len | Number of bytes to extract (8 max) |
| bytes | Data to extract from |
Definition at line 143 of file util-byte.c.
References len.
| int WARN_UNUSED ByteExtractUint64 | ( | uint64_t * | res, |
| int | e, | ||
| uint16_t | len, | ||
| const uint8_t * | bytes | ||
| ) |
Extract bytes from a byte string and convert to a unint64_t.
| res | Stores result |
| e | Endianness (BYTE_BIG_ENDIAN or BYTE_LITTLE_ENDIAN) |
| len | Number of bytes to extract (8 max) |
| bytes | Data to extract from |
Definition at line 122 of file util-byte.c.
References len.
Referenced by DetectByteExtractDoMatch(), DetectBytejumpDoMatch(), DetectByteMathDoMatch(), and DetectBytetestDoMatch().

| void ByteRegisterTests | ( | void | ) |
Definition at line 1064 of file util-byte.c.
References UtRegisterTest().

| char * BytesToString | ( | const uint8_t * | bytes, |
| size_t | nbytes | ||
| ) |
Turn byte array into string.
All non-printables are copied over, except for '\0', which is turned into literal \0 in the string.
| bytes | byte array |
| nbytes | number of bytes |
Definition at line 41 of file util-byte.c.
| void BytesToStringBuffer | ( | const uint8_t * | bytes, |
| size_t | nbytes, | ||
| char * | outstr, | ||
| size_t | outlen | ||
| ) |
Turn byte array into string.
All non-printables are copied over, except for '\0', which is turned into literal \0 in the string.
| bytes | byte array |
| nbytes | number of bytes |
| outstr[out] | buffer to fill |
| outlen | size of outstr. Must be at least 2 * nbytes + 1 in size |
Definition at line 85 of file util-byte.c.
References DEBUG_VALIDATE_BUG_ON, dst, and strlcpy().

| int HexToRaw | ( | const uint8_t * | in, |
| size_t | ins, | ||
| uint8_t * | out, | ||
| size_t | outs | ||
| ) |
Definition at line 806 of file util-byte.c.
References SCLogError.
Referenced by DatajsonAddSerialized().

| int WARN_UNUSED StringParseI16RangeCheck | ( | int16_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| int16_t | min, | ||
| int16_t | max | ||
| ) |
Extract signed integer value from a string as int16_t strictly within the range.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 746 of file util-byte.c.
References ByteExtractStringSigned(), len, SCLogError, and str.

| int WARN_UNUSED StringParseI32RangeCheck | ( | int32_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| int32_t | min, | ||
| int32_t | max | ||
| ) |
Extract signed integer value from a string as int32_t strictly within the range.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 716 of file util-byte.c.
References ByteExtractStringSigned(), len, SCLogError, and str.

| int WARN_UNUSED StringParseI64RangeCheck | ( | int64_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| int64_t | min, | ||
| int64_t | max | ||
| ) |
Extract signed integer value from a string as int64_t strictly within the range.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 697 of file util-byte.c.
References ByteExtractStringSigned(), len, and str.

| int WARN_UNUSED StringParseI8RangeCheck | ( | int8_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| int8_t | min, | ||
| int8_t | max | ||
| ) |
Extract signed integer value from a string as int8_t strictly within the range.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 776 of file util-byte.c.
References ByteExtractStringSigned(), len, SCLogError, and str.

| int StringParseInt16 | ( | int16_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract signed integer value from a string as int16_t strictly.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 647 of file util-byte.c.
References ByteExtractStringSigned(), len, SCLogError, and str.

| int StringParseInt32 | ( | int32_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract signed integer value from a string as int32_t strictly.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 622 of file util-byte.c.
References ByteExtractStringSigned(), len, SCLogError, and str.
Referenced by SCKernelVersionIsAtLeast().


| int StringParseInt64 | ( | int64_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract signed integer value from a string as int64_t strictly.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 617 of file util-byte.c.
References ByteExtractStringSigned(), len, and str.
Referenced by UtilCpuGetNumProcessorsConfigured().


| int StringParseInt8 | ( | int8_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract signed integer value from a string as int8_t strictly.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 672 of file util-byte.c.
References ByteExtractStringSigned(), len, SCLogError, and str.

| int WARN_UNUSED StringParseU16RangeCheck | ( | uint16_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| uint16_t | min, | ||
| uint16_t | max | ||
| ) |
Extract unsigned integer value from a string as uint16_t strictly within the range.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 433 of file util-byte.c.
References ByteExtractString(), len, SCLogError, and str.

| int WARN_UNUSED StringParseU32RangeCheck | ( | uint32_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| uint32_t | min, | ||
| uint32_t | max | ||
| ) |
Extract unsigned integer value from a string as uint32_t strictly within the range.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 404 of file util-byte.c.
References ByteExtractString(), len, SCLogError, and str.

| int WARN_UNUSED StringParseU64RangeCheck | ( | uint64_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| uint64_t | min, | ||
| uint64_t | max | ||
| ) |
Extract unsigned integer value from a string as uint64_t strictly within the range.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 385 of file util-byte.c.
References ByteExtractString(), len, and str.

| int WARN_UNUSED StringParseU8RangeCheck | ( | uint8_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str, | ||
| uint8_t | min, | ||
| uint8_t | max | ||
| ) |
Extract unsigned integer value from a string as uint8_t strictly within the range.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 462 of file util-byte.c.
References ByteExtractString(), len, SCLogError, and str.
Referenced by SCRadix4AddKeyIPV4String(), and SCRadix6AddKeyIPV6String().


| int StringParseUint16 | ( | uint16_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract unsigned integer value from a string as uint16_t strictly.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 337 of file util-byte.c.
References ByteExtractString(), len, SCLogError, and str.
Referenced by FlowRateRegisterFlowStorage(), IPFWRegisterQueue(), OutputJsonInitCtx(), and PostConfLoadedSetup().


| int StringParseUint32 | ( | uint32_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract unsigned integer value from a string as uint32_t strictly.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 313 of file util-byte.c.
References ByteExtractString(), len, SCLogError, and str.
Referenced by BuildCpusetWithCallback(), DefragInitConfig(), DetectEngineMultiTenantSetup(), FlowInitConfig(), FlowInitFlowProto(), HostInitConfig(), HttpRangeContainersInit(), IPPairInitConfig(), SCClassConfAddClasstype(), and SCConfLogOpenGeneric().


| int StringParseUint64 | ( | uint64_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract unsigned integer value from a string as uint64_t strictly.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 308 of file util-byte.c.
References ByteExtractString(), len, and str.
Referenced by OutputJsonInitCtx().


| int StringParseUint8 | ( | uint8_t * | res, |
| int | base, | ||
| size_t | len, | ||
| const char * | str | ||
| ) |
Extract unsigned integer value from a string as uint8_t strictly.
| res | Stores result |
| base | Base of the number to extract |
| len | Number of bytes to extract (23 max or 0 for unbounded) |
| str | String to extract from |
Definition at line 361 of file util-byte.c.
References ByteExtractString(), len, SCLogError, and str.
Referenced by IPv4AddressStringIsValid().

