suricata
util-byte.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Brian Rectanus <brectanu@gmail.com>
22  *
23  * Byte utility functions
24  */
25 
26 #include "suricata-common.h"
27 #include "util-byte.h"
28 #include "util-unittest.h"
29 #include "util-debug.h"
30 #include "util-validate.h"
31 
32 /** \brief Turn byte array into string.
33  *
34  * All non-printables are copied over, except for '\0', which is
35  * turned into literal \0 in the string.
36  *
37  * \param bytes byte array
38  * \param nbytes number of bytes
39  * \return string nul-terminated string or NULL on error
40  */
41 char *BytesToString(const uint8_t *bytes, size_t nbytes)
42 {
43  size_t n = nbytes + 1;
44  size_t nulls = 0;
45 
46  size_t u;
47  for (u = 0; u < nbytes; u++) {
48  if (bytes[u] == '\0')
49  nulls++;
50  }
51  n += nulls;
52 
53  char *string = SCCalloc(1, n);
54  if (string == NULL)
55  return NULL;
56 
57  if (nulls == 0) {
58  /* no nulls */
59  memcpy(string, bytes, nbytes);
60  } else {
61  /* nulls present */
62  char *dst = string;
63  for (u = 0; u < nbytes; u++) {
64  if (bytes[u] == '\0') {
65  *dst++ = '\\';
66  *dst++ = '0';
67  } else {
68  *dst++ = bytes[u];
69  }
70  }
71  }
72  return string;
73 }
74 
75 /** \brief Turn byte array into string.
76  *
77  * All non-printables are copied over, except for '\0', which is
78  * turned into literal \0 in the string.
79  *
80  * \param bytes byte array
81  * \param nbytes number of bytes
82  * \param outstr[out] buffer to fill
83  * \param outlen size of outstr. Must be at least 2 * nbytes + 1 in size
84  */
85 void BytesToStringBuffer(const uint8_t *bytes, size_t nbytes, char *outstr, size_t outlen)
86 {
87  DEBUG_VALIDATE_BUG_ON(outlen < (nbytes * 2 + 1));
88 
89  size_t n = nbytes + 1;
90  size_t nulls = 0;
91 
92  size_t u;
93  for (u = 0; u < nbytes; u++) {
94  if (bytes[u] == '\0')
95  nulls++;
96  }
97  n += nulls;
98 
99  char string[n];
100 
101  if (nulls == 0) {
102  /* no nulls */
103  memcpy(string, bytes, nbytes);
104  string[nbytes] = '\0';
105  } else {
106  /* nulls present */
107  char *dst = string;
108  for (u = 0; u < nbytes; u++) {
109  if (bytes[u] == '\0') {
110  *dst++ = '\\';
111  *dst++ = '0';
112  } else {
113  *dst++ = bytes[u];
114  }
115  }
116  *dst = '\0';
117  }
118 
119  strlcpy(outstr, string, outlen);
120 }
121 
122 int ByteExtractUint64(uint64_t *res, int e, uint16_t len, const uint8_t *bytes)
123 {
124  uint64_t i64;
125  int ret;
126 
127  /* Uint64 is limited to 8 bytes */
128  if (len > 8) {
129  /** \todo Need standard return values */
130  return -1;
131  }
132 
133  ret = ByteExtract(&i64, e, len, bytes);
134  if (ret <= 0) {
135  return ret;
136  }
137 
138  *res = (uint64_t)i64;
139 
140  return ret;
141 }
142 
143 int ByteExtractUint32(uint32_t *res, int e, uint16_t len, const uint8_t *bytes)
144 {
145  uint64_t i64;
146  int ret;
147 
148  /* Uint32 is limited to 4 bytes */
149  if (len > 4) {
150  /** \todo Need standard return values */
151  return -1;
152  }
153 
154  ret = ByteExtract(&i64, e, len, bytes);
155  if (ret <= 0) {
156  return ret;
157  }
158 
159  *res = (uint32_t)i64;
160 
161  return ret;
162 }
163 
164 int ByteExtractUint16(uint16_t *res, int e, uint16_t len, const uint8_t *bytes)
165 {
166  uint64_t i64;
167  int ret;
168 
169  /* Uint16 is limited to 2 bytes */
170  if (len > 2) {
171  /** \todo Need standard return values */
172  return -1;
173  }
174 
175  ret = ByteExtract(&i64, e, len, bytes);
176  if (ret <= 0) {
177  return ret;
178  }
179 
180  *res = (uint16_t)i64;
181 
182  return ret;
183 }
184 
185 int ByteExtractString(uint64_t *res, int base, uint16_t len, const char *str, bool strict)
186 {
187  const char *ptr = str;
188  char *endptr = NULL;
189 
190  /* 23 - This is the largest string (octal, with a zero prefix) that
191  * will not overflow uint64_t. The only way this length
192  * could be over 23 and still not overflow is if it were zero
193  * prefixed and we only support 1 byte of zero prefix for octal.
194  *
195  * "01777777777777777777777" = 0xffffffffffffffff
196  */
197  char strbuf[24];
198 
199  if (len > 23) {
200  SCLogDebug("len too large (23 max)");
201  return -1;
202  }
203 
204  if (len) {
205  /* Extract out the string so it can be null terminated */
206  memcpy(strbuf, str, len);
207  strbuf[len] = '\0';
208  ptr = strbuf;
209  }
210 
211  errno = 0;
212  *res = strtoull(ptr, &endptr, base);
213 
214  if (errno == ERANGE) {
215  SCLogDebug("numeric value out of range");
216  return -1;
217  /* If there is no numeric value in the given string then strtoull(), makes
218  endptr equals to ptr and return 0 as result */
219  } else if (endptr == ptr && *res == 0) {
220  SCLogDebug("no numeric value");
221  return -1;
222  } else if (endptr == ptr) {
223  SCLogDebug("invalid numeric value");
224  return -1;
225  }
226  else if (strict && len && *endptr != '\0') {
227  SCLogError(SC_ERR_INVALID_NUMERIC_VALUE, "Extra characters following numeric value");
228  return -1;
229  }
230 
231  return (endptr - ptr);
232 }
233 
234 int ByteExtractStringUint64(uint64_t *res, int base, uint16_t len, const char *str)
235 {
236  return ByteExtractString(res, base, len, str, false);
237 }
238 
239 int ByteExtractStringUint32(uint32_t *res, int base, uint16_t len, const char *str)
240 {
241  uint64_t i64;
242 
243  int ret = ByteExtractString(&i64, base, len, str, false);
244  if (ret <= 0) {
245  return ret;
246  }
247 
248  *res = (uint32_t)i64;
249 
250  if ((uint64_t)(*res) != i64) {
251  SCLogDebug("Numeric value out of range (%" PRIu64 " > %" PRIuMAX ")",
252  i64, (uintmax_t)UINT_MAX);
253  return -1;
254  }
255 
256  return ret;
257 }
258 
259 int ByteExtractStringUint16(uint16_t *res, int base, uint16_t len, const char *str)
260 {
261  uint64_t i64;
262 
263  int ret = ByteExtractString(&i64, base, len, str, false);
264  if (ret <= 0) {
265  return ret;
266  }
267 
268  *res = (uint16_t)i64;
269 
270  if ((uint64_t)(*res) != i64) {
271  SCLogDebug("Numeric value out of range (%" PRIu64 " > %" PRIuMAX ")",
272  i64, (uintmax_t)USHRT_MAX);
273  return -1;
274  }
275 
276  return ret;
277 }
278 
279 int ByteExtractStringUint8(uint8_t *res, int base, uint16_t len, const char *str)
280 {
281  uint64_t i64;
282 
283  int ret = ByteExtractString(&i64, base, len, str, false);
284  if (ret <= 0) {
285  return ret;
286  }
287 
288  *res = (uint8_t)i64;
289 
290  if ((uint64_t)(*res) != i64) {
291  SCLogDebug("Numeric value out of range (%" PRIu64 " > %" PRIuMAX ")",
292  i64, (uintmax_t)UCHAR_MAX);
293  return -1;
294  }
295 
296  return ret;
297 }
298 
299 int StringParseUint64(uint64_t *res, int base, uint16_t len, const char *str)
300 {
301  return ByteExtractString(res, base, len, str, true);
302 }
303 
304 int StringParseUint32(uint32_t *res, int base, uint16_t len, const char *str)
305 {
306  uint64_t i64;
307 
308  int ret = ByteExtractString(&i64, base, len, str, true);
309  if (ret <= 0) {
310  return ret;
311  }
312 
313  *res = (uint32_t)i64;
314 
315  if ((uint64_t)(*res) != i64) {
316  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range "
317  "(%" PRIu64 " > %" PRIuMAX ")", i64, (uintmax_t)UINT_MAX);
318  return -1;
319  }
320 
321  return ret;
322 }
323 
324 int StringParseUint16(uint16_t *res, int base, uint16_t len, const char *str)
325 {
326  uint64_t i64;
327 
328  int ret = ByteExtractString(&i64, base, len, str, true);
329  if (ret <= 0) {
330  return ret;
331  }
332 
333  *res = (uint16_t)i64;
334 
335  if ((uint64_t)(*res) != i64) {
336  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range "
337  "(%" PRIu64 " > %" PRIuMAX ")", i64, (uintmax_t)USHRT_MAX);
338  return -1;
339  }
340 
341  return ret;
342 }
343 
344 int StringParseUint8(uint8_t *res, int base, uint16_t len, const char *str)
345 {
346  uint64_t i64;
347 
348  int ret = ByteExtractString(&i64, base, len, str, true);
349  if (ret <= 0) {
350  return ret;
351  }
352 
353  *res = (uint8_t)i64;
354 
355  if ((uint64_t)(*res) != i64) {
356  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range "
357  "(%" PRIu64 " > %" PRIuMAX ")", i64, (uintmax_t)UCHAR_MAX);
358  return -1;
359  }
360 
361  return ret;
362 }
363 int ByteExtractStringSigned(int64_t *res, int base, uint16_t len, const char *str, bool strict)
364 {
365  const char *ptr = str;
366  char *endptr;
367 
368  /* 23 - This is the largest string (octal, with a zero prefix) that
369  * will not overflow int64_t. The only way this length
370  * could be over 23 and still not overflow is if it were zero
371  * prefixed and we only support 1 byte of zero prefix for octal.
372  *
373  * "-0777777777777777777777" = 0xffffffffffffffff
374  */
375  char strbuf[24];
376 
377  if (len > 23) {
378  SCLogError(SC_ERR_ARG_LEN_LONG, "len too large (23 max)");
379  return -1;
380  }
381 
382  if (len) {
383  /* Extract out the string so it can be null terminated */
384  memcpy(strbuf, str, len);
385  strbuf[len] = '\0';
386  ptr = strbuf;
387  }
388 
389  errno = 0;
390  *res = strtoll(ptr, &endptr, base);
391 
392  if (errno == ERANGE) {
393  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range");
394  return -1;
395  } else if (endptr == str) {
396  SCLogError(SC_ERR_INVALID_NUMERIC_VALUE, "Invalid numeric value");
397  return -1;
398  }
399  else if (strict && len && *endptr != '\0') {
400  SCLogError(SC_ERR_INVALID_NUMERIC_VALUE, "Extra characters following numeric value");
401  return -1;
402  }
403 
404  //fprintf(stderr, "ByteExtractStringSigned: Extracted base %d: 0x%" PRIx64 "\n", base, *res);
405 
406  return (endptr - ptr);
407 }
408 
409 int ByteExtractStringInt64(int64_t *res, int base, uint16_t len, const char *str)
410 {
411  return ByteExtractStringSigned(res, base, len, str, false);
412 }
413 
414 int ByteExtractStringInt32(int32_t *res, int base, uint16_t len, const char *str)
415 {
416  int64_t i64;
417  int ret;
418 
419  ret = ByteExtractStringSigned(&i64, base, len, str, false);
420  if (ret <= 0) {
421  return ret;
422  }
423 
424  *res = (int32_t)i64;
425 
426  if ((int64_t)(*res) != i64) {
427  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range "
428  "(%" PRIi64 " > %" PRIiMAX ")\n", i64, (intmax_t)INT_MAX);
429  return -1;
430  }
431 
432  return ret;
433 }
434 
435 int ByteExtractStringInt16(int16_t *res, int base, uint16_t len, const char *str)
436 {
437  int64_t i64;
438  int ret;
439 
440  ret = ByteExtractStringSigned(&i64, base, len, str, false);
441  if (ret <= 0) {
442  return ret;
443  }
444 
445  *res = (int16_t)i64;
446 
447  if ((int64_t)(*res) != i64) {
448  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range "
449  "(%" PRIi64 " > %" PRIiMAX ")\n", i64, (intmax_t)SHRT_MAX);
450  return -1;
451  }
452 
453  return ret;
454 }
455 
456 int ByteExtractStringInt8(int8_t *res, int base, uint16_t len, const char *str)
457 {
458  int64_t i64;
459  int ret;
460 
461  ret = ByteExtractStringSigned(&i64, base, len, str, false);
462  if (ret <= 0) {
463  return ret;
464  }
465 
466  *res = (int8_t)i64;
467 
468  if ((int64_t)(*res) != i64) {
469  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range "
470  "(%" PRIi64 " > %" PRIiMAX ")\n", i64, (intmax_t)CHAR_MAX);
471  return -1;
472  }
473 
474  return ret;
475 }
476 
477 int StringParseInt64(int64_t *res, int base, uint16_t len, const char *str)
478 {
479  return ByteExtractStringSigned(res, base, len, str, true);
480 }
481 
482 int StringParseInt32(int32_t *res, int base, uint16_t len, const char *str)
483 {
484  int64_t i64;
485  int ret;
486 
487  ret = ByteExtractStringSigned(&i64, base, len, str, true);
488  if (ret <= 0) {
489  return ret;
490  }
491 
492  *res = (int32_t)i64;
493 
494  if ((int64_t)(*res) != i64) {
495  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range "
496  "(%" PRIi64 " > %" PRIiMAX ")\n", i64, (intmax_t)INT_MAX);
497  return -1;
498  }
499 
500  return ret;
501 }
502 
503 int StringParseInt16(int16_t *res, int base, uint16_t len, const char *str)
504 {
505  int64_t i64;
506  int ret;
507 
508  ret = ByteExtractStringSigned(&i64, base, len, str, true);
509  if (ret <= 0) {
510  return ret;
511  }
512 
513  *res = (int16_t)i64;
514 
515  if ((int64_t)(*res) != i64) {
516  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range "
517  "(%" PRIi64 " > %" PRIiMAX ")\n", i64, (intmax_t)SHRT_MAX);
518  return -1;
519  }
520 
521  return ret;
522 }
523 
524 int StringParseInt8(int8_t *res, int base, uint16_t len, const char *str)
525 {
526  int64_t i64;
527  int ret;
528 
529  ret = ByteExtractStringSigned(&i64, base, len, str, true);
530  if (ret <= 0) {
531  return ret;
532  }
533 
534  *res = (int8_t)i64;
535 
536  if ((int64_t)(*res) != i64) {
537  SCLogError(SC_ERR_NUMERIC_VALUE_ERANGE, "Numeric value out of range "
538  "(%" PRIi64 " > %" PRIiMAX ")\n", i64, (intmax_t)CHAR_MAX);
539  return -1;
540  }
541 
542  return ret;
543 }
544 /* UNITTESTS */
545 #ifdef UNITTESTS
546 
547 static int ByteTest01 (void)
548 {
549  uint16_t val = 0x0102;
550  uint16_t i16 = 0xbfbf;
551  uint8_t bytes[2] = { 0x02, 0x01 };
552  int ret = ByteExtractUint16(&i16, BYTE_LITTLE_ENDIAN, sizeof(bytes), bytes);
553 
554  if ((ret == 2) && (i16 == val)) {
555  return 1;
556  }
557 
558  return 0;
559 }
560 
561 static int ByteTest02 (void)
562 {
563  uint16_t val = 0x0102;
564  uint16_t i16 = 0xbfbf;
565  uint8_t bytes[2] = { 0x01, 0x02 };
566  int ret = ByteExtractUint16(&i16, BYTE_BIG_ENDIAN, sizeof(bytes), bytes);
567 
568  if ((ret == 2) && (i16 == val)) {
569  return 1;
570  }
571 
572  return 0;
573 }
574 
575 static int ByteTest03 (void)
576 {
577  uint32_t val = 0x01020304;
578  uint32_t i32 = 0xbfbfbfbf;
579  uint8_t bytes[4] = { 0x04, 0x03, 0x02, 0x01 };
580  int ret = ByteExtractUint32(&i32, BYTE_LITTLE_ENDIAN, sizeof(bytes), bytes);
581 
582  if ((ret == 4) && (i32 == val)) {
583  return 1;
584  }
585 
586  return 0;
587 }
588 
589 static int ByteTest04 (void)
590 {
591  uint32_t val = 0x01020304;
592  uint32_t i32 = 0xbfbfbfbf;
593  uint8_t bytes[4] = { 0x01, 0x02, 0x03, 0x04 };
594  int ret = ByteExtractUint32(&i32, BYTE_BIG_ENDIAN, sizeof(bytes), bytes);
595 
596  if ((ret == 4) && (i32 == val)) {
597  return 1;
598  }
599 
600  return 0;
601 }
602 
603 static int ByteTest05 (void)
604 {
605  uint64_t val = 0x0102030405060708ULL;
606  uint64_t i64 = 0xbfbfbfbfbfbfbfbfULL;
607  uint8_t bytes[8] = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
608  int ret = ByteExtractUint64(&i64, BYTE_LITTLE_ENDIAN, sizeof(bytes), bytes);
609 
610  if ((ret == 8) && (i64 == val)) {
611  return 1;
612  }
613 
614  return 0;
615 }
616 
617 static int ByteTest06 (void)
618 {
619  uint64_t val = 0x0102030405060708ULL;
620  uint64_t i64 = 0xbfbfbfbfbfbfbfbfULL;
621  uint8_t bytes[8] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
622  int ret = ByteExtractUint64(&i64, BYTE_BIG_ENDIAN, sizeof(bytes), bytes);
623 
624  if ((ret == 8) && (i64 == val)) {
625  return 1;
626  }
627 
628  return 0;
629 }
630 
631 static int ByteTest07 (void)
632 {
633  const char *str = "1234567890";
634  uint64_t val = 1234567890;
635  uint64_t i64 = 0xbfbfbfbfbfbfbfbfULL;
636  int ret = ByteExtractStringUint64(&i64, 10, strlen(str), str);
637 
638  if ((ret == 10) && (i64 == val)) {
639  return 1;
640  }
641 
642  return 0;
643 }
644 
645 static int ByteTest08 (void)
646 {
647  const char *str = "1234567890";
648  uint32_t val = 1234567890;
649  uint32_t i32 = 0xbfbfbfbf;
650  int ret = ByteExtractStringUint32(&i32, 10, strlen(str), str);
651 
652  if ((ret == 10) && (i32 == val)) {
653  return 1;
654  }
655 
656  return 0;
657 }
658 
659 static int ByteTest09 (void)
660 {
661  const char *str = "12345";
662  uint16_t val = 12345;
663  uint16_t i16 = 0xbfbf;
664  int ret = ByteExtractStringUint16(&i16, 10, strlen(str), str);
665 
666  if ((ret == 5) && (i16 == val)) {
667  return 1;
668  }
669 
670  return 0;
671 }
672 
673 static int ByteTest10 (void)
674 {
675  const char *str = "123";
676  uint8_t val = 123;
677  uint8_t i8 = 0xbf;
678  int ret = ByteExtractStringUint8(&i8, 10, strlen(str), str);
679 
680  if ((ret == 3) && (i8 == val)) {
681  return 1;
682  }
683 
684  return 0;
685 }
686 
687 static int ByteTest11 (void)
688 {
689  const char *str = "-1234567890";
690  int64_t val = -1234567890;
691  int64_t i64 = 0xbfbfbfbfbfbfbfbfULL;
692  int ret = ByteExtractStringInt64(&i64, 10, strlen(str), str);
693 
694  if ((ret == 11) && (i64 == val)) {
695  return 1;
696  }
697 
698  return 0;
699 }
700 
701 static int ByteTest12 (void)
702 {
703  const char *str = "-1234567890";
704  int32_t val = -1234567890;
705  int32_t i32 = 0xbfbfbfbf;
706  int ret = ByteExtractStringInt32(&i32, 10, strlen(str), str);
707 
708  if ((ret == 11) && (i32 == val)) {
709  return 1;
710  }
711 
712  return 0;
713 }
714 
715 static int ByteTest13 (void)
716 {
717  const char *str = "-12345";
718  int16_t val = -12345;
719  int16_t i16 = 0xbfbf;
720  int ret = ByteExtractStringInt16(&i16, 10, strlen(str), str);
721 
722  if ((ret == 6) && (i16 == val)) {
723  return 1;
724  }
725 
726  return 0;
727 }
728 
729 static int ByteTest14 (void)
730 {
731  const char *str = "-123";
732  int8_t val = -123;
733  int8_t i8 = 0xbf;
734  int ret = ByteExtractStringInt8(&i8, 10, strlen(str), str);
735 
736  if ((ret == 4) && (i8 == val)) {
737  return 1;
738  }
739 
740  return 0;
741 }
742 
743 /** \test max u32 value */
744 static int ByteTest15 (void)
745 {
746  const char *str = "4294967295";
747  uint32_t val = 4294967295UL;
748  uint32_t u32 = 0xffffffff;
749 
750  int ret = ByteExtractStringUint32(&u32, 10, strlen(str), str);
751  if ((ret == 10) && (u32 == val)) {
752  return 1;
753  }
754 
755  return 0;
756 }
757 
758 /** \test max u32 value + 1 */
759 static int ByteTest16 (void)
760 {
761  const char *str = "4294967296";
762  uint32_t u32 = 0;
763 
764  int ret = ByteExtractStringUint32(&u32, 10, strlen(str), str);
765  if (ret != 0) {
766  return 1;
767  }
768 
769  return 0;
770 }
771 
773 {
774  UtRegisterTest("ByteTest01", ByteTest01);
775  UtRegisterTest("ByteTest02", ByteTest02);
776  UtRegisterTest("ByteTest03", ByteTest03);
777  UtRegisterTest("ByteTest04", ByteTest04);
778  UtRegisterTest("ByteTest05", ByteTest05);
779  UtRegisterTest("ByteTest06", ByteTest06);
780  UtRegisterTest("ByteTest07", ByteTest07);
781  UtRegisterTest("ByteTest08", ByteTest08);
782  UtRegisterTest("ByteTest09", ByteTest09);
783  UtRegisterTest("ByteTest10", ByteTest10);
784  UtRegisterTest("ByteTest11", ByteTest11);
785  UtRegisterTest("ByteTest12", ByteTest12);
786  UtRegisterTest("ByteTest13", ByteTest13);
787  UtRegisterTest("ByteTest14", ByteTest14);
788  UtRegisterTest("ByteTest15", ByteTest15);
789  UtRegisterTest("ByteTest16", ByteTest16);
790 }
791 #endif /* UNITTESTS */
792 
util-byte.h
len
uint8_t len
Definition: app-layer-dnp3.h:4
StringParseUint16
int StringParseUint16(uint16_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:324
StringParseInt8
int StringParseInt8(int8_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:524
ByteExtractUint64
int ByteExtractUint64(uint64_t *res, int e, uint16_t len, const uint8_t *bytes)
Definition: util-byte.c:122
BytesToString
char * BytesToString(const uint8_t *bytes, size_t nbytes)
Turn byte array into string.
Definition: util-byte.c:41
ByteExtractUint16
int ByteExtractUint16(uint16_t *res, int e, uint16_t len, const uint8_t *bytes)
Definition: util-byte.c:164
ByteExtractString
int ByteExtractString(uint64_t *res, int base, uint16_t len, const char *str, bool strict)
Definition: util-byte.c:185
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:335
ByteExtractStringInt16
int ByteExtractStringInt16(int16_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:435
StringParseInt32
int StringParseInt32(int32_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:482
ByteExtractStringInt32
int ByteExtractStringInt32(int32_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:414
util-unittest.h
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
ByteRegisterTests
void ByteRegisterTests(void)
Definition: util-byte.c:772
util-debug.h
res
PoolThreadReserved res
Definition: stream-tcp-private.h:60
ByteExtractUint32
int ByteExtractUint32(uint32_t *res, int e, uint16_t len, const uint8_t *bytes)
Definition: util-byte.c:143
BYTE_BIG_ENDIAN
#define BYTE_BIG_ENDIAN
Definition: util-byte.h:29
SCCalloc
#define SCCalloc(nm, a)
Definition: util-mem.h:253
StringParseInt16
int StringParseInt16(int16_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:503
ByteExtractStringInt64
int ByteExtractStringInt64(int64_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:409
StringParseUint64
int StringParseUint64(uint64_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:299
ByteExtractStringUint32
int ByteExtractStringUint32(uint32_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:239
ByteExtractStringSigned
int ByteExtractStringSigned(int64_t *res, int base, uint16_t len, const char *str, bool strict)
Definition: util-byte.c:363
StringParseInt64
int StringParseInt64(int64_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:477
StringParseUint32
int StringParseUint32(uint32_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:304
BYTE_LITTLE_ENDIAN
#define BYTE_LITTLE_ENDIAN
Definition: util-byte.h:30
suricata-common.h
ByteExtractStringInt8
int ByteExtractStringInt8(int8_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:456
SCLogError
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
Definition: util-debug.h:294
util-validate.h
ByteExtractStringUint8
int ByteExtractStringUint8(uint8_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:279
str
#define str(s)
Definition: suricata-common.h:256
SC_ERR_NUMERIC_VALUE_ERANGE
@ SC_ERR_NUMERIC_VALUE_ERANGE
Definition: util-error.h:91
BytesToStringBuffer
void BytesToStringBuffer(const uint8_t *bytes, size_t nbytes, char *outstr, size_t outlen)
Turn byte array into string.
Definition: util-byte.c:85
StringParseUint8
int StringParseUint8(uint8_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:344
ByteExtractStringUint64
int ByteExtractStringUint64(uint64_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:234
ByteExtractStringUint16
int ByteExtractStringUint16(uint16_t *res, int base, uint16_t len, const char *str)
Definition: util-byte.c:259
SC_ERR_ARG_LEN_LONG
@ SC_ERR_ARG_LEN_LONG
Definition: util-error.h:93
dst
uint16_t dst
Definition: app-layer-dnp3.h:6
SC_ERR_INVALID_NUMERIC_VALUE
@ SC_ERR_INVALID_NUMERIC_VALUE
Definition: util-error.h:90
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:111