trafgen: moved cleanup into parser
[netsniff-ng-old.git] / src / proto_none.h
blob424c922dbaef7029086a85c2d61f7706e4ce7c9f
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 PROTO_NONE_H
9 #define PROTO_NONE_H
11 #include <stdio.h>
12 #include <stdint.h>
13 #include <ctype.h>
15 #include "proto_struct.h"
16 #include "pkt_buff.h"
18 static inline void empty(struct pkt_buff *pkt) {}
20 static inline void _hex(uint8_t *ptr, size_t len)
22 if (!len)
23 return;
25 tprintf(" [ hex ");
26 for (; ptr && len-- > 0; ptr++)
27 tprintf(" %.2x", *ptr);
28 tprintf(" ]\n");
31 static inline void hex(struct pkt_buff *pkt)
33 size_t len = pkt_len(pkt);
35 if (!len)
36 return;
38 _hex(pkt_pull(pkt, len), len);
39 tprintf("\n");
42 static inline void _ascii(uint8_t *ptr, size_t len)
44 if (!len)
45 return;
47 tprintf(" [ chr ");
48 for (; ptr && len-- > 0; ptr++)
49 tprintf(" %c ", isprint(*ptr) ? *ptr : '.');
50 tprintf(" ]\n");
53 static inline void ascii(struct pkt_buff *pkt)
55 size_t len = pkt_len(pkt);
57 if (!len)
58 return;
60 _ascii(pkt_pull(pkt, len), len);
61 tprintf("\n");
64 static inline void hex_ascii(struct pkt_buff *pkt)
66 size_t len = pkt_len(pkt);
67 uint8_t *ptr = pkt_pull(pkt, len);
69 if (len) {
70 _hex(ptr, len);
71 _ascii(ptr, len);
74 tprintf("\n");
77 #ifndef __without_ops
78 static inline void none_less(struct pkt_buff *pkt)
80 tprintf("\n");
83 struct protocol none_ops = {
84 .key = 0x01,
85 .print_full = hex_ascii,
86 .print_less = none_less,
88 #endif /* __without_ops */
89 #endif /* PROTO_NONE_H */