dissector_fuzz: removed printing opts to make for usage with diff
[netsniff-ng.git] / src / proto_struct.h
blob3d8e98aaefa9b25b6805a8798813233e9e65afd7
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>.
4 * Copyright (C) 2009, 2010 Daniel Borkmann
5 * Copyright (C) 2012 Christoph Jaeger <christoph@netsniff-ng.org>
6 * Subject to the GPL, version 2.
7 */
9 #ifndef PROTO_H
10 #define PROTO_H
12 #include <ctype.h>
13 #include <stdint.h>
15 #include "hash.h"
16 #include "tprintf.h"
18 /* necessary forward declarations */
19 struct pkt_buff;
20 static inline unsigned int pkt_len(struct pkt_buff *pkt);
21 static uint8_t *pkt_pull(struct pkt_buff *pkt, unsigned int len);
23 struct protocol {
24 /* Needs to be filled out by user */
25 unsigned int key;
26 void (*print_full)(struct pkt_buff *pkt);
27 void (*print_less)(struct pkt_buff *pkt);
28 /* Used by program logic */
29 struct protocol *next;
30 void (*process) (struct pkt_buff *pkt);
33 static inline void empty(struct pkt_buff *pkt) {}
35 static inline void _hex(uint8_t *ptr, size_t len)
37 if (!len)
38 return;
40 tprintf(" [ hex ");
41 for (; ptr && len-- > 0; ptr++)
42 tprintf(" %.2x", *ptr);
43 tprintf(" ]\n");
46 static inline void hex(struct pkt_buff *pkt)
48 size_t len = pkt_len(pkt);
50 if (!len)
51 return;
53 _hex(pkt_pull(pkt, len), len);
54 tprintf("\n");
57 static inline void _ascii(uint8_t *ptr, size_t len)
59 if (!len)
60 return;
62 tprintf(" [ chr ");
63 for (; ptr && len-- > 0; ptr++)
64 tprintf(" %c ", isprint(*ptr) ? *ptr : '.');
65 tprintf(" ]\n");
68 static inline void ascii(struct pkt_buff *pkt)
70 size_t len = pkt_len(pkt);
72 if (!len)
73 return;
75 _ascii(pkt_pull(pkt, len), len);
76 tprintf("\n");
79 static inline void hex_ascii(struct pkt_buff *pkt)
81 size_t len = pkt_len(pkt);
82 uint8_t *ptr = pkt_pull(pkt, len);
84 if (!len)
85 return;
87 _hex(ptr, len);
88 _ascii(ptr, len);
89 tprintf("\n");
92 #endif /* PROTO_H */