43 size_t n = nbytes + 1;
47 for (u = 0; u < nbytes; u++) {
59 memcpy(
string, bytes, nbytes);
63 for (u = 0; u < nbytes; u++) {
64 if (bytes[u] ==
'\0') {
89 size_t n = nbytes + 1;
93 for (u = 0; u < nbytes; u++) {
103 memcpy(
string, bytes, nbytes);
104 string[nbytes] =
'\0';
108 for (u = 0; u < nbytes; u++) {
109 if (bytes[u] ==
'\0') {
119 strlcpy(outstr,
string, outlen);
133 ret = ByteExtract(&i64, e,
len, bytes);
138 *res = (uint64_t)i64;
154 ret = ByteExtract(&i64, e,
len, bytes);
159 *res = (uint32_t)i64;
175 ret = ByteExtract(&i64, e,
len, bytes);
180 *res = (uint16_t)i64;
187 const char *ptr =
str;
212 *res = strtoull(ptr, &endptr, base);
214 if (errno == ERANGE) {
219 }
else if (endptr == ptr && *res == 0) {
222 }
else if (endptr == ptr) {
226 else if (strict && *endptr !=
'\0') {
227 SCLogError(
"Extra characters following numeric value");
231 return (endptr - ptr);
247 if (i64 > UINT32_MAX) {
251 *res = (uint32_t)i64;
253 if ((uint64_t)(*res) != i64) {
254 SCLogDebug(
"Numeric value out of range (%" PRIu64
" > %" PRIuMAX
")",
255 i64, (uintmax_t)UINT_MAX);
270 if (i64 > UINT16_MAX) {
274 *res = (uint16_t)i64;
276 if ((uint64_t)(*res) != i64) {
277 SCLogDebug(
"Numeric value out of range (%" PRIu64
" > %" PRIuMAX
")",
278 i64, (uintmax_t)USHRT_MAX);
293 if (i64 > UINT8_MAX) {
299 if ((uint64_t)(*res) != i64) {
300 SCLogDebug(
"Numeric value out of range (%" PRIu64
" > %" PRIuMAX
")",
301 i64, (uintmax_t)UCHAR_MAX);
321 if (i64 > UINT32_MAX) {
325 *res = (uint32_t)i64;
327 if ((uint64_t)(*res) != i64) {
329 "(%" PRIu64
" > %" PRIuMAX
")",
330 i64, (uintmax_t)UINT_MAX);
345 if (i64 > UINT16_MAX) {
349 *res = (uint16_t)i64;
351 if ((uint64_t)(*res) != i64) {
353 "(%" PRIu64
" > %" PRIuMAX
")",
354 i64, (uintmax_t)USHRT_MAX);
369 if (i64 > UINT8_MAX) {
375 if ((uint64_t)(*res) != i64) {
377 "(%" PRIu64
" > %" PRIuMAX
")",
378 i64, (uintmax_t)UCHAR_MAX);
386 uint64_t *res,
int base,
size_t len,
const char *
str, uint64_t min, uint64_t max)
397 if (*res < min || *res > max) {
405 uint32_t *res,
int base,
size_t len,
const char *
str, uint32_t min, uint32_t max)
413 if (u64 > UINT32_MAX) {
417 *res = (uint32_t)u64;
419 if (*res < min || *res > max) {
423 if ((uint64_t)(*res) != u64) {
425 "(%" PRIu64
" > %" PRIuMAX
")",
426 u64, (uintmax_t)UINT_MAX);
434 uint16_t *res,
int base,
size_t len,
const char *
str, uint16_t min, uint16_t max)
442 if (u64 > UINT16_MAX) {
446 *res = (uint16_t)u64;
448 if (*res < min || *res > max) {
452 if ((uint64_t)(*res) != u64) {
454 "(%" PRIu64
" > %" PRIuMAX
")",
455 u64, (uintmax_t)USHRT_MAX);
463 uint8_t *res,
int base,
size_t len,
const char *
str, uint8_t min, uint8_t max)
471 if (u64 > UINT8_MAX) {
477 if (*res < min || *res > max) {
481 if ((uint64_t)(*res) != u64) {
483 "(%" PRIu64
" > %" PRIuMAX
")",
484 u64, (uintmax_t)UCHAR_MAX);
493 const char *ptr =
str;
518 *res = strtoll(ptr, &endptr, base);
520 if (errno == ERANGE) {
523 }
else if (endptr ==
str) {
527 else if (strict &&
len && *endptr !=
'\0') {
528 SCLogError(
"Extra characters following numeric value");
534 return (endptr - ptr);
551 if (i64 < INT32_MIN || i64 > INT32_MAX) {
557 if ((int64_t)(*res) != i64) {
559 "(%" PRIi64
" > %" PRIiMAX
")\n",
560 i64, (intmax_t)INT_MAX);
576 if (i64 < INT16_MIN || i64 > INT16_MAX) {
582 if ((int64_t)(*res) != i64) {
584 "(%" PRIi64
" > %" PRIiMAX
")\n",
585 i64, (intmax_t)SHRT_MAX);
601 if (i64 < INT8_MIN || i64 > INT8_MAX) {
607 if ((int64_t)(*res) != i64) {
609 "(%" PRIi64
" > %" PRIiMAX
")\n",
610 i64, (intmax_t)CHAR_MAX);
631 if (i64 < INT32_MIN || i64 > INT32_MAX) {
637 if ((int64_t)(*res) != i64) {
639 "(%" PRIi64
" > %" PRIiMAX
")\n",
640 i64, (intmax_t)INT_MAX);
656 if (i64 < INT16_MIN || i64 > INT16_MAX) {
662 if ((int64_t)(*res) != i64) {
664 "(%" PRIi64
" > %" PRIiMAX
")\n",
665 i64, (intmax_t)SHRT_MAX);
681 if (i64 < INT8_MIN || i64 > INT8_MAX) {
687 if ((int64_t)(*res) != i64) {
689 "(%" PRIi64
" > %" PRIiMAX
")\n",
690 i64, (intmax_t)CHAR_MAX);
698 int64_t *res,
int base,
size_t len,
const char *
str, int64_t min, int64_t max)
709 if (*res < min || *res > max) {
717 int32_t *res,
int base,
size_t len,
const char *
str, int32_t min, int32_t max)
726 if (i64 < INT32_MIN || i64 > INT32_MAX) {
732 if (*res < min || *res > max) {
736 if ((int64_t)(*res) != i64) {
738 "(%" PRIi64
" > %" PRIiMAX
")\n",
739 i64, (intmax_t)INT_MAX);
747 int16_t *res,
int base,
size_t len,
const char *
str, int16_t min, int16_t max)
756 if (i64 < INT16_MIN || i64 > INT16_MAX) {
762 if (*res < min || *res > max) {
766 if ((int64_t)(*res) != i64) {
768 "(%" PRIi64
" > %" PRIiMAX
")\n",
769 i64, (intmax_t)SHRT_MAX);
777 int8_t *res,
int base,
size_t len,
const char *
str, int8_t min, int8_t max)
786 if (i64 < INT8_MIN || i64 > INT8_MAX) {
792 if (*res < min || *res > max) {
796 if ((int64_t)(*res) != i64) {
798 "(%" PRIi64
" > %" PRIiMAX
")\n",
799 i64, (intmax_t)CHAR_MAX);
809 static int ByteTest01 (
void)
811 uint16_t val = 0x0102;
812 uint16_t i16 = 0xbfbf;
813 uint8_t bytes[2] = { 0x02, 0x01 };
816 if ((ret == 2) && (i16 == val)) {
823 static int ByteTest02 (
void)
825 uint16_t val = 0x0102;
826 uint16_t i16 = 0xbfbf;
827 uint8_t bytes[2] = { 0x01, 0x02 };
830 if ((ret == 2) && (i16 == val)) {
837 static int ByteTest03 (
void)
839 uint32_t val = 0x01020304;
840 uint32_t i32 = 0xbfbfbfbf;
841 uint8_t bytes[4] = { 0x04, 0x03, 0x02, 0x01 };
844 if ((ret == 4) && (i32 == val)) {
851 static int ByteTest04 (
void)
853 uint32_t val = 0x01020304;
854 uint32_t i32 = 0xbfbfbfbf;
855 uint8_t bytes[4] = { 0x01, 0x02, 0x03, 0x04 };
858 if ((ret == 4) && (i32 == val)) {
865 static int ByteTest05 (
void)
867 uint64_t val = 0x0102030405060708ULL;
868 uint64_t i64 = 0xbfbfbfbfbfbfbfbfULL;
869 uint8_t bytes[8] = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
872 if ((ret == 8) && (i64 == val)) {
879 static int ByteTest06 (
void)
881 uint64_t val = 0x0102030405060708ULL;
882 uint64_t i64 = 0xbfbfbfbfbfbfbfbfULL;
883 uint8_t bytes[8] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
886 if ((ret == 8) && (i64 == val)) {
893 static int ByteTest07 (
void)
895 const char str[] =
"1234567890";
896 uint64_t val = 1234567890;
897 uint64_t i64 = 0xbfbfbfbfbfbfbfbfULL;
900 if ((ret == 10) && (i64 == val)) {
907 static int ByteTest08 (
void)
909 const char str[] =
"1234567890";
910 uint32_t val = 1234567890;
911 uint32_t i32 = 0xbfbfbfbf;
914 if ((ret == 10) && (i32 == val)) {
921 static int ByteTest09 (
void)
923 const char str[] =
"12345";
924 uint16_t val = 12345;
925 uint16_t i16 = 0xbfbf;
928 if ((ret == 5) && (i16 == val)) {
935 static int ByteTest10 (
void)
937 const char str[] =
"123";
942 if ((ret == 3) && (i8 == val)) {
949 static int ByteTest11 (
void)
951 const char str[] =
"-1234567890";
952 int64_t val = -1234567890;
953 int64_t i64 = 0xbfbfbfbfbfbfbfbfULL;
956 if ((ret == 11) && (i64 == val)) {
963 static int ByteTest12 (
void)
965 const char str[] =
"-1234567890";
966 int32_t val = -1234567890;
967 int32_t i32 = 0xbfbfbfbf;
970 if ((ret == 11) && (i32 == val)) {
977 static int ByteTest13 (
void)
979 const char str[] =
"-12345";
980 int16_t val = -12345;
981 int16_t i16 = 0xbfbf;
984 if ((ret == 6) && (i16 == val)) {
991 static int ByteTest14 (
void)
993 const char str[] =
"-123";
998 if ((ret == 4) && (i8 == val)) {
1006 static int ByteTest15 (
void)
1008 const char str[] =
"4294967295";
1009 uint32_t val = 4294967295UL;
1010 uint32_t u32 = 0xffffffff;
1013 if ((ret == 10) && (u32 == val)) {
1021 static int ByteTest16 (
void)
1023 const char str[] =
"4294967296";