mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-09 00:27:08 +02:00
MINOR: buffer_dump with ASCII
Improve the buffer_dump function with ASCII output.
This commit is contained in:
parent
00bf1dee9c
commit
be0efd884d
36
src/buffer.c
36
src/buffer.c
@ -10,6 +10,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -198,23 +199,32 @@ void buffer_bounce_realign(struct buffer *buf)
|
|||||||
void buffer_dump(FILE *o, struct buffer *b, int from, int to)
|
void buffer_dump(FILE *o, struct buffer *b, int from, int to)
|
||||||
{
|
{
|
||||||
fprintf(o, "Dumping buffer %p\n", b);
|
fprintf(o, "Dumping buffer %p\n", b);
|
||||||
fprintf(o, " data=%p o=%d i=%d p=%p\n",
|
fprintf(o, " data=%p o=%d i=%d p=%p\n"
|
||||||
b->data, b->o, b->i, b->p);
|
" relative: p=0x%04x\n",
|
||||||
|
b->data, b->o, b->i, b->p, (unsigned int)(b->p - b->data));
|
||||||
if (!to || to > buffer_len(b))
|
|
||||||
to = buffer_len(b);
|
|
||||||
|
|
||||||
fprintf(o, "Dumping contents from byte %d to byte %d\n", from, to);
|
fprintf(o, "Dumping contents from byte %d to byte %d\n", from, to);
|
||||||
for (; from < to; from++) {
|
fprintf(o, " 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
|
||||||
if ((from & 15) == 0)
|
/* dump hexa */
|
||||||
fprintf(o, " %04x: ", from);
|
while (from < to) {
|
||||||
fprintf(o, "%02x ", b->data[from]);
|
int i;
|
||||||
if ((from & 15) == 7)
|
|
||||||
fprintf(o, "- ");
|
fprintf(o, " %04x: ", from);
|
||||||
else if (((from & 15) == 15) && (from != to-1))
|
for (i = 0; ((from + i) < to) && (i < 16) ; i++) {
|
||||||
fprintf(o, "\n");
|
fprintf(o, "%02x ", (unsigned char)b->data[from + i]);
|
||||||
|
if (((from + i) & 15) == 7)
|
||||||
|
fprintf(o, "- ");
|
||||||
|
}
|
||||||
|
fprintf(o, " ");
|
||||||
|
for (i = 0; (from + i < to) && (i < 16) ; i++) {
|
||||||
|
fprintf(o, "%c", isprint(b->data[from + i]) ? b->data[from + i] : '.') ;
|
||||||
|
if ((((from + i) & 15) == 15) && ((from + i) != to-1))
|
||||||
|
fprintf(o, "\n");
|
||||||
|
}
|
||||||
|
from += i;
|
||||||
}
|
}
|
||||||
fprintf(o, "\n--\n");
|
fprintf(o, "\n--\n");
|
||||||
|
fflush(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user