void dump_buffer(const char * buffer, int size)
{
if (size > 0 && buffer != NULL) {
int i = 0;
char *dump_buffer = (char *)malloc(size * 5);
for (i = 0; i < size; i++) {
unsigned char c = buffer[i];
sprintf(dump_buffer + i * 5, "%02x/%c ", c, isprint(c) ? c : '.');
}
dump_buffer[size * 5 - 1]='\0';
printf("dumpbuffer size=%d, buffer=[%s]", size, dump_buffer);
free(dump_buffer);
}
}
网友评论