From 069acc41a58b3d14d87f1bbe798ea5c7f0bbbbd5 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 4 Oct 2015 02:32:19 +0200 Subject: [PATCH] tests: fix SNMP tests Restore the `tohex()` function in `check_snmp.c`. Use a simpler version in `decode.c`. --- tests/check_snmp.c | 14 ++++++++++++++ tests/common.c | 13 ------------- tests/common.h | 1 - tests/decode.c | 11 +++++++++++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tests/check_snmp.c b/tests/check_snmp.c index 5e81df26..7ff6d134 100644 --- a/tests/check_snmp.c +++ b/tests/check_snmp.c @@ -844,6 +844,20 @@ struct tree_node snmp_tree[] = { #endif }; +char* +tohex(char *str, size_t len) +{ + static char *hex[] = { NULL, NULL }; + static int which = 0; + free(hex[which]); hex[which] = NULL; + hex[which] = malloc(len * 3 + 1); + fail_unless(hex[which] != NULL, "Not enough memory?"); + for (size_t i = 0; i < len; i++) + snprintf(hex[which] + 3*i, 4, "%02X ", (unsigned char)str[i]); + which = 1 - which; + return hex[1 - which]; +} + int snmp_is_prefix_of(struct variable8 *vp, struct tree_node *n, char *repr) { diff --git a/tests/common.c b/tests/common.c index 01dc0405..95ec6f4b 100644 --- a/tests/common.c +++ b/tests/common.c @@ -147,16 +147,3 @@ pcap_teardown() filename = NULL; } } - -char* -tohex(char *str, size_t len) -{ - static char *hex[] = { NULL, NULL }; - static int which = 0; - free(hex[which]); hex[which] = NULL; - if ((hex[which] = malloc(len * 3 + 1)) == NULL) return NULL; - for (size_t i = 0; i < len; i++) - snprintf(hex[which] + 3*i, 4, "%02X ", (unsigned char)str[i]); - which = 1 - which; - return hex[1 - which]; -} diff --git a/tests/common.h b/tests/common.h index 5be4b5eb..a3d7e33f 100644 --- a/tests/common.h +++ b/tests/common.h @@ -51,7 +51,6 @@ extern int dump; /* Dump file descriptor in pcap format */ extern char filenameprefix[]; /* Prefix for filename dumping */ extern char *filename; /* Filename we are dumping to */ extern char macaddress[]; /* MAC address we use to send */ -extern char *tohex(char *, size_t); extern struct pkts_t pkts; /* List of sent packets */ extern struct lldpd_hardware hardware; diff --git a/tests/decode.c b/tests/decode.c index f1183ed7..91074c82 100644 --- a/tests/decode.c +++ b/tests/decode.c @@ -40,6 +40,17 @@ usage(void) exit(1); } +char* +tohex(char *str, size_t len) +{ + static char *hex = NULL; + free(hex); hex = NULL; + if ((hex = malloc(len * 3 + 1)) == NULL) return NULL; + for (size_t i = 0; i < len; i++) + snprintf(hex + 3*i, 4, "%02X ", (unsigned char)str[i]); + return hex; +} + /* We need an assert macro which doesn't abort */ #define assert(x) while (!(x)) { \ fprintf(stderr, "%s:%d: %s: Assertion `%s' failed.\n", \ -- 2.39.5