From: James Yonan Date: Thu, 3 Mar 2016 08:19:00 +0000 (-0700) Subject: Added flags parameter to format_hex_ex. X-Git-Tag: v2.4_alpha1~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a6a80156ee60705f7856100da7a2a61f018e2a0;p=thirdparty%2Fopenvpn.git Added flags parameter to format_hex_ex. We add the flags parameter without changing the signature of the function by repurposing the space_break parameter into space_break_flags where the lower 8 bits are used for the previous space_break parameter and the higher bits are used for flag values. Added new flag FHE_CAPS that formats the generated hex string in upper case. Signed-off-by: James Yonan Acked-by: Steffan Karger Message-Id: <1456993146-63968-4-git-send-email-james@openvpn.net> URL: http://article.gmane.org/gmane.network.openvpn.devel/11275 Signed-off-by: Gert Doering --- diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index bc67d6503..52c6ab92f 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -435,18 +435,21 @@ gc_transfer (struct gc_arena *dest, struct gc_arena *src) char * format_hex_ex (const uint8_t *data, int size, int maxoutput, - int space_break, const char* separator, + unsigned int space_break_flags, const char* separator, struct gc_arena *gc) { struct buffer out = alloc_buf_gc (maxoutput ? maxoutput : - ((size * 2) + (size / space_break) * (int) strlen (separator) + 2), + ((size * 2) + (size / (space_break_flags & FHE_SPACE_BREAK_MASK)) * (int) strlen (separator) + 2), gc); int i; for (i = 0; i < size; ++i) { - if (separator && i && !(i % space_break)) + if (separator && i && !(i % (space_break_flags & FHE_SPACE_BREAK_MASK))) buf_printf (&out, "%s", separator); - buf_printf (&out, "%02x", data[i]); + if (space_break_flags & FHE_CAPS) + buf_printf (&out, "%02X", data[i]); + else + buf_printf (&out, "%02x", data[i]); } buf_catrunc (&out, "[more...]"); return (char *)out.data; diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index 24f52aa38..8070439a5 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -403,9 +403,11 @@ bool buf_parse (struct buffer *buf, const int delim, char *line, const int size) /* * Hex dump -- Output a binary buffer to a hex string and return it. */ +#define FHE_SPACE_BREAK_MASK 0xFF /* space_break parameter in lower 8 bits */ +#define FHE_CAPS 0x100 /* output hex in caps */ char * format_hex_ex (const uint8_t *data, int size, int maxoutput, - int space_break, const char* separator, + unsigned int space_break_flags, const char* separator, struct gc_arena *gc); static inline char *