2 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
3 * fmemdmp.c - tracing utilities
5 * Copyright (c) 1998-2001 R. Carbone <rocco@ntop.org>
6 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 * Operating System include files
36 # include <sys/time.h>
41 * Pretty print function.
43 * This function dumps a buffer in memory in the (pretty !!) format :
45 * off: printable hexadecimal notation
46 * --------------------------------------------------------------------------
48 * Dump of memory area at address 0x10000444 for 51 bytes
49 * 0: abcdefghijklmnop 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f 70
50 * 16: qrstuvzxyw012345 71 72 73 74 75 76 7a 78 79 77 30 31 32 33 34 35
51 * 32: 6789~!@#$%^&*()_ 36 37 38 39 7e 21 40 23 24 25 5e 26 2a 28 29 5f
54 * Dump of memory area at address 0x7fffbc03 for 16 bytes
55 * 0: rocco@tecsiel.it 72 6f 63 63 6f 40 74 65 63 73 69 65 6c 2e 69 74
57 void fmemdmp (FILE * fd, char * ptr, int size, char * text)
61 int bytes_in_a_line = 16;
64 if (! ptr || size <= 0)
68 fprintf (fd, "\"%s\" at address 0x%08x for %d bytes\n",
69 text, (unsigned int) ptr, size);
71 for (total = 0; total < size; total += bytes_in_a_line)
76 fprintf (fd, "%6d: ", offset);
78 * Print the bytes in a line (each byte in ASCII notation)
80 for (i = 0; i < bytes_in_a_line; i ++)
83 isprint (* (ptr + total + i) & 0x000000ff)
84 ? (* (ptr + total + i))
87 fprintf (fd, " "); /* 1 blank character */
93 * Print the bytes in a line (each byte in Hexadecimal notation)
95 for (i = 0; i < bytes_in_a_line && i < size; i ++)
98 * (ptr + total + i) & 0x000000ff);
100 fprintf (fd, " "); /* 3 more blanks characters */
103 offset += bytes_in_a_line;