From 2fad399db3d85667dfec6fb081a1b6e80549c23f Mon Sep 17 00:00:00 2001 From: Michael Rash Date: Wed, 16 Dec 2015 19:28:10 -0800 Subject: [PATCH] promote hex_dump() to fko_util --- client/utils.h | 2 -- common/fko_util.c | 41 +++++++++++++++++++++++++++++++++++++++++ common/fko_util.h | 1 + server/utils.c | 44 -------------------------------------------- server/utils.h | 1 - 5 files changed, 42 insertions(+), 47 deletions(-) diff --git a/client/utils.h b/client/utils.h index 6866146b..ae218aa3 100644 --- a/client/utils.h +++ b/client/utils.h @@ -53,8 +53,6 @@ /* Prototypes */ -void hex_dump(const unsigned char *data, const int size); -int set_file_perms(const char *file); int verify_file_perms_ownership(const char *file); int resolve_dst_addr(const char *dns_str, struct addrinfo *hints, char *ip_str, size_t ip_bufsize, fko_cli_options_t *opts); diff --git a/common/fko_util.c b/common/fko_util.c index 81722d94..40ddaf5d 100644 --- a/common/fko_util.c +++ b/common/fko_util.c @@ -738,6 +738,47 @@ free_argv(char **argv_new, int *argc_new) return; } +#define ASCII_LEN 16 + +/* Generic hex dump function. +*/ +void +hex_dump(const unsigned char *data, const int size) +{ + int ln=0, i=0, j=0; + char ascii_str[ASCII_LEN+1] = {0}; + + for(i=0; i 0x7e) ? '.' : data[i]; + + if(j == 8) + printf(" "); + } + + /* Remainder... + */ + ln = strlen(ascii_str); + if(ln > 0) + { + for(i=0; i < ASCII_LEN-ln; i++) + printf(" "); + if(ln < 8) + printf(" "); + + printf(" %s\n\n", ascii_str); + } + return; +} /** * @brief Dump a FKO context to a buffer diff --git a/common/fko_util.h b/common/fko_util.h index ad697293..dfe2a2fd 100644 --- a/common/fko_util.h +++ b/common/fko_util.h @@ -42,6 +42,7 @@ int is_valid_encoded_msg_len(const int len); int is_valid_pt_msg_len(const int len); int is_valid_ipv4_addr(const char * const ip_str); int is_base64(const unsigned char * const buf, const unsigned short int len); +void hex_dump(const unsigned char *data, const int size); int enc_mode_strtoint(const char *enc_mode_str); short enc_mode_inttostr(int enc_mode, char* enc_mode_str, size_t enc_mode_size); int strtol_wrapper(const char * const str, const int min, diff --git a/server/utils.c b/server/utils.c index 4d63c381..63b46e49 100644 --- a/server/utils.c +++ b/server/utils.c @@ -33,50 +33,6 @@ #include "fw_util.h" #include "cmd_cycle.h" -#include - -#define ASCII_LEN 16 - -/* Generic hex dump function. -*/ -void -hex_dump(const unsigned char *data, const int size) -{ - int ln=0, i=0, j=0; - char ascii_str[ASCII_LEN+1] = {0}; - - for(i=0; i 0x7e) ? '.' : data[i]; - - if(j == 8) - printf(" "); - } - - /* Remainder... - */ - ln = strlen(ascii_str); - if(ln > 0) - { - for(i=0; i < ASCII_LEN-ln; i++) - printf(" "); - if(ln < 8) - printf(" "); - - printf(" %s\n\n", ascii_str); - } - return; -} - /* Basic directory/binary checks (stat() and whether the path is actually * a directory or an executable). */ diff --git a/server/utils.h b/server/utils.h index 73a7cf2c..3915c4ae 100644 --- a/server/utils.h +++ b/server/utils.h @@ -60,7 +60,6 @@ /* Prototypes */ -void hex_dump(const unsigned char *data, const int size); char* dump_ctx(fko_ctx_t ctx); int is_valid_dir(const char *path); int is_valid_exe(const char *path);