promote hex_dump() to fko_util

This commit is contained in:
Michael Rash
2015-12-16 19:28:10 -08:00
parent 998fb96f0b
commit 2fad399db3
5 changed files with 42 additions and 47 deletions
-2
View File
@@ -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);
+41
View File
@@ -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<size; i++)
{
if((i % ASCII_LEN) == 0)
{
printf(" %s\n 0x%.4x: ", ascii_str, i);
memset(ascii_str, 0x0, ASCII_LEN-1);
j = 0;
}
printf("%.2x ", data[i]);
ascii_str[j++] = (data[i] < 0x20 || data[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
+1
View File
@@ -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,
-44
View File
@@ -33,50 +33,6 @@
#include "fw_util.h"
#include "cmd_cycle.h"
#include <stdarg.h>
#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<size; i++)
{
if((i % ASCII_LEN) == 0)
{
printf(" %s\n 0x%.4x: ", ascii_str, i);
memset(ascii_str, 0x0, ASCII_LEN-1);
j = 0;
}
printf("%.2x ", data[i]);
ascii_str[j++] = (data[i] < 0x20 || data[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).
*/
-1
View File
@@ -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);