summaryrefslogtreecommitdiff
path: root/lib/frrstr.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@nvidia.com>2021-08-10 11:42:19 -0400
committerQuentin Young <qlyoung@nvidia.com>2021-08-12 16:25:57 -0400
commit0c0830c599d61bcbb45a6a7ef6b6dea5b77f957b (patch)
treede08c016fd167e23142e4833fad6725e5d65908b /lib/frrstr.c
parent6a9ac96f2c9ed43eeb061259081275451f4a788c (diff)
lib: add frrstr_hex to hexdump buffers
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
Diffstat (limited to 'lib/frrstr.c')
-rw-r--r--lib/frrstr.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/frrstr.c b/lib/frrstr.c
index 7ef5fffd12..1b98b224cc 100644
--- a/lib/frrstr.c
+++ b/lib/frrstr.c
@@ -18,9 +18,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
+#include "zebra.h"
#include <string.h>
#include <ctype.h>
@@ -217,3 +215,21 @@ int all_digit(const char *str)
return 0;
return 1;
}
+
+
+char *frrstr_hex(char *buff, size_t bufsiz, const uint8_t *str, size_t num)
+{
+ if (bufsiz == 0)
+ return buff;
+
+ char tmp[3];
+
+ buff[0] = '\0';
+
+ for (size_t i = 0; i < num; i++) {
+ snprintf(tmp, sizeof(tmp), "%02x", (unsigned char)str[i]);
+ strlcat(buff, tmp, bufsiz);
+ }
+
+ return buff;
+}