AUTHORS: Add Hisao Tanabe for his contribution
[netsniff-ng-new.git] / proto_none.c
blob6b3696258df5d9d0ab7ef46df54874598139bfa3
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Subject to the GPL, version 2.
5 */
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <ctype.h>
11 #include "proto.h"
12 #include "protos.h"
13 #include "pkt_buff.h"
15 void empty(struct pkt_buff *pkt __maybe_unused) {}
17 void _hex(uint8_t *ptr, size_t len)
19 if (!len)
20 return;
22 tprintf(" [ Hex ");
23 for (; ptr && len-- > 0; ptr++)
24 tprintf(" %.2x", *ptr);
25 tprintf(" ]\n");
28 void hex(struct pkt_buff *pkt)
30 size_t len = pkt_len(pkt);
32 if (!len)
33 return;
35 _hex(pkt_pull(pkt, len), len);
36 tprintf("\n");
39 void _ascii(uint8_t *ptr, size_t len)
41 if (!len)
42 return;
44 tprintf(" [ Chr ");
45 for (; ptr && len-- > 0; ptr++)
46 tprintf("%c", isprint(*ptr) ? *ptr : '.');
47 tprintf(" ]\n");
50 void ascii(struct pkt_buff *pkt)
52 size_t len = pkt_len(pkt);
54 if (!len)
55 return;
57 _ascii(pkt_pull(pkt, len), len);
58 tprintf("\n");
61 void hex_ascii(struct pkt_buff *pkt)
63 size_t len = pkt_len(pkt);
64 uint8_t *ptr = pkt_pull(pkt, len);
66 if (len) {
67 _ascii(ptr, len);
68 _hex(ptr, len);
71 tprintf("\n");
74 static void none_less(struct pkt_buff *pkt __maybe_unused)
76 tprintf("\n");
79 struct protocol none_ops = {
80 .key = 0x01,
81 .print_full = hex_ascii,
82 .print_less = none_less,