ring: built_in: fix if cacheline_aligned is not defined
[netsniff-ng.git] / src / proto_hex.h
blobcb7797145d0e7cd045de0fc3b8d8b4bdc04e1ac2
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010 Daniel Borkmann.
5 * Subject to the GPL, version 2.
6 */
8 #ifndef HEX_H
9 #define HEX_H
11 #include <stdio.h>
12 #include <stdint.h>
13 #include <ctype.h>
15 #include "proto_struct.h"
16 #include "dissector_eth.h"
18 static inline void hex_pay(uint8_t *packet, size_t len)
20 size_t plen = len;
21 uint8_t *buff;
23 if (len == 0)
24 return;
25 tprintf(" [ Payload hex ");
26 for (buff = packet, plen = len; plen-- > 0; buff++)
27 tprintf("%.2x ", *buff);
28 tprintf("]\n");
29 tprintf(" [ Payload chr ");
30 for (buff = packet, plen = len; plen-- > 0; buff++)
31 tprintf("%c ", isprint(*buff) ? *buff : '.');
32 tprintf("]\n\n");
35 static inline void hex_none_newline(uint8_t *packet, size_t len)
37 tprintf("\n");
40 static inline void hex_hex(uint8_t *packet, size_t len)
42 uint8_t *buff;
43 tprintf(" ");
44 for (buff = packet; len-- > 0; buff++)
45 tprintf("%.2x ", *buff);
46 tprintf("\n\n");
49 static inline void hex_all(uint8_t *packet, size_t len)
51 hex(packet, len);
52 tprintf("\n\n");
55 static inline void hex_ascii(uint8_t *packet, size_t len)
57 uint8_t *buff;
58 tprintf(" ");
59 for (buff = packet; len-- > 0; buff++)
60 tprintf("%c ", isprint(*buff) ? *buff : '.');
61 tprintf("\n\n");
64 struct protocol hex_ops = {
65 .key = 0x01,
66 .offset = 0,
67 .print_full = hex_pay,
68 .print_less = hex_none_newline,
69 .print_pay_ascii = hex_ascii,
70 .print_pay_hex = hex_hex,
71 .print_pay_none = hex_none_newline,
72 .print_all_hex = hex_all,
73 .proto_next = NULL,
76 #endif /* HEX_H */