send a full frame containing only zeroes instead of a zero-byte frame
[hmcfgusb] / hexdump.h
1 /* simple hexdumper
2 *
3 * Copyright (c) 2004-2013 Michael Gernoth <michael@gernoth.net>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 static void asciishow(unsigned char *buf, int len)
25 {
26 int i;
27
28 fprintf(stderr, " ");
29 for (i = 0; i < len; i++) {
30 if ((buf[i] >=32) && (buf[i] <=126)) {
31 fprintf(stderr, "%c", buf[i]);
32 } else {
33 fprintf(stderr, ".");
34 }
35 }
36 }
37
38 static void hexdump(unsigned char *buf, int len, char *prefix)
39 {
40 int i, j;
41
42 fprintf(stderr, "\n%s", prefix);
43 for (i = 0; i < len; i++) {
44 if((i%16) == 0) {
45 fprintf(stderr, "0x%04x: ", i);
46 }
47 fprintf(stderr, "%02x ", buf[i]);
48 if ((i%16) == 15) {
49 asciishow(buf+i-15, 16);
50 if (i != (len-1))
51 fprintf(stderr, "\n%s", prefix);
52 }
53 }
54 for (j = (i%16); j < 16; j++)
55 fprintf(stderr, " ");
56 asciishow(buf+i-(i%16), (i%16));
57 fprintf(stderr, "\n");
58 }
Impressum, Datenschutz