summaryrefslogtreecommitdiff
path: root/testing/misc_tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/misc_tools.c')
-rw-r--r--testing/misc_tools.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
index efe1a555..ad6b2bff 100644
--- a/testing/misc_tools.c
+++ b/testing/misc_tools.c
@@ -28,22 +28,28 @@
28#include <string.h> 28#include <string.h>
29#include <stdlib.h> 29#include <stdlib.h>
30#include <stdio.h> 30#include <stdio.h>
31#include <stdint.h>
31 32
32#ifdef DEBUG 33#ifdef DEBUG
33#include <assert.h> 34#include <assert.h>
34#endif // DEBUG 35#endif // DEBUG
35 36
36/* TODO: rewrite */ 37// You are responsible for freeing the return value!
37unsigned char *hex_string_to_bin(char hex_string[]) 38uint8_t *hex_string_to_bin(char *hex_string)
38{ 39{
39 size_t i, len = strlen(hex_string); 40 // byte is represented by exactly 2 hex digits, so lenth of binary string
40 unsigned char *val = malloc(len); 41 // is half of that of the hex one. only hex string with even length
42 // valid. the more proper implementation would be to check if strlen(hex_string)
43 // is odd and return error code if it is. we assume strlen is even. if it's not
44 // then the last byte just won't be written in 'ret'.
45 size_t i, len = strlen(hex_string) / 2;
46 uint8_t *ret = malloc(len);
41 char *pos = hex_string; 47 char *pos = hex_string;
42 48
43 for (i = 0; i < len; ++i, pos += 2) 49 for (i = 0; i < len; ++i, pos += 2)
44 sscanf(pos, "%2hhx", &val[i]); 50 sscanf(pos, "%2hhx", &ret[i]);
45 51
46 return val; 52 return ret;
47} 53}
48 54
49int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled) 55int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)