]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
tests: fix SNMP tests
authorVincent Bernat <vincent@bernat.im>
Sun, 4 Oct 2015 00:32:19 +0000 (02:32 +0200)
committerVincent Bernat <vincent@bernat.im>
Sun, 4 Oct 2015 00:32:19 +0000 (02:32 +0200)
Restore the `tohex()` function in `check_snmp.c`. Use a simpler version
in `decode.c`.

tests/check_snmp.c
tests/common.c
tests/common.h
tests/decode.c

index 5e81df266451d19da8377480ca53b53d69ba59de..7ff6d1340cae6221d6f877240a06f194b2642f2a 100644 (file)
@@ -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)
 {
index 01dc04050405855f3a384f1ad7a91c5bf19da36b..95ec6f4b7f2e954152ea3ddf9026fa31ada9a21f 100644 (file)
@@ -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];
-}
index 5be4b5eb2da73ae392e2e49eda024aaf692ca51b..a3d7e33f0dfc134d1f6a49dd7e7f3f83b87fabf6 100644 (file)
@@ -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;
index f1183ed7e2d5e089aa280ae6095897a95ed5d8b8..91074c8250c9072c6d04cdd613880cf57612070a 100644 (file)
@@ -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", \