|
|
|
@ -887,61 +887,73 @@ static ares_status_t ares__buf_append_str(ares__buf_t *buf, const char *str) |
|
|
|
|
return ares__buf_append(buf, (const unsigned char *)str, ares_strlen(str)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ares_status_t ares__buf_hexdump(ares__buf_t *buf, const unsigned char *data, |
|
|
|
|
size_t len) |
|
|
|
|
static ares_status_t ares__buf_hexdump_line(ares__buf_t *buf, |
|
|
|
|
size_t idx, |
|
|
|
|
const unsigned char *data, |
|
|
|
|
size_t len) |
|
|
|
|
{ |
|
|
|
|
size_t i; |
|
|
|
|
ares_status_t status; |
|
|
|
|
/* Each line is 16 bytes */ |
|
|
|
|
for (i = 0; i < len; i += 16) { |
|
|
|
|
size_t j; |
|
|
|
|
|
|
|
|
|
/* Address */ |
|
|
|
|
status = ares__buf_append_num_hex(buf, i, 6); |
|
|
|
|
/* Address */ |
|
|
|
|
status = ares__buf_append_num_hex(buf, idx, 6); |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* | */ |
|
|
|
|
status = ares__buf_append_str(buf, " | "); |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++) { |
|
|
|
|
if (i >= len) { |
|
|
|
|
status = ares__buf_append_str(buf, " "); |
|
|
|
|
} else { |
|
|
|
|
status = ares__buf_append_num_hex(buf, data[i], 2); |
|
|
|
|
} |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* | */ |
|
|
|
|
status = ares__buf_append_str(buf, " | "); |
|
|
|
|
status = ares__buf_append_byte(buf, ' '); |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (j = i; j < i + 16; j++) { |
|
|
|
|
if (j >= len) { |
|
|
|
|
status = ares__buf_append_str(buf, " "); |
|
|
|
|
} else { |
|
|
|
|
status = ares__buf_append_num_hex(buf, data[j], 2); |
|
|
|
|
} |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
/* | */ |
|
|
|
|
status = ares__buf_append_str(buf, " | "); |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
status = ares__buf_append_byte(buf, ' '); |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
for (i = 0; i < 16; i++) { |
|
|
|
|
if (i >= len) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* | */ |
|
|
|
|
status = ares__buf_append_str(buf, " | "); |
|
|
|
|
status = |
|
|
|
|
ares__buf_append_byte(buf, ares__isprint(data[i]) ? data[i] : '.'); |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (j = i; j < i + 16; j++) { |
|
|
|
|
if (j >= len) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
status = |
|
|
|
|
ares__buf_append_byte(buf, ares__isprint(data[j]) ? data[j] : '.'); |
|
|
|
|
if (status != ARES_SUCCESS) { |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return ares__buf_append_byte(buf, '\n'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ares__buf_append_byte(buf, '\n'); |
|
|
|
|
ares_status_t ares__buf_hexdump(ares__buf_t *buf, const unsigned char *data, |
|
|
|
|
size_t len) |
|
|
|
|
{ |
|
|
|
|
size_t i; |
|
|
|
|
|
|
|
|
|
/* Each line is 16 bytes */ |
|
|
|
|
for (i = 0; i < len; i += 16) { |
|
|
|
|
ares_status_t status; |
|
|
|
|
status = ares__buf_hexdump_line(buf, i, data + i, len - i); |
|
|
|
|
if (status != ARES_SUCCESS) |
|
|
|
|
return status; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ARES_SUCCESS; |
|
|
|
|