docs: short description for authors
[netsniff-ng.git] / src / proto_none.c
blobaa1a9b6805da2f88d1822ab1a557a447802d342c
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 #include <stdio.h>
9 #include <stdint.h>
10 #include <ctype.h>
12 #include "proto.h"
13 #include "protos.h"
14 #include "pkt_buff.h"
16 void empty(struct pkt_buff *pkt) {}
18 static void _hex(uint8_t *ptr, size_t len)
20 if (!len)
21 return;
23 tprintf(" [ hex ");
24 for (; ptr && len-- > 0; ptr++)
25 tprintf(" %.2x", *ptr);
26 tprintf(" ]\n");
29 void hex(struct pkt_buff *pkt)
31 size_t len = pkt_len(pkt);
33 if (!len)
34 return;
36 _hex(pkt_pull(pkt, len), len);
37 tprintf("\n");
40 static void _ascii(uint8_t *ptr, size_t len)
42 if (!len)
43 return;
45 tprintf(" [ chr ");
46 for (; ptr && len-- > 0; ptr++)
47 tprintf("%c", isprint(*ptr) ? *ptr : '.');
48 tprintf(" ]\n");
51 void ascii(struct pkt_buff *pkt)
53 size_t len = pkt_len(pkt);
55 if (!len)
56 return;
58 _ascii(pkt_pull(pkt, len), len);
59 tprintf("\n");
62 void hex_ascii(struct pkt_buff *pkt)
64 size_t len = pkt_len(pkt);
65 uint8_t *ptr = pkt_pull(pkt, len);
67 if (len) {
68 _ascii(ptr, len);
69 _hex(ptr, len);
72 tprintf("\n");
75 static void none_less(struct pkt_buff *pkt)
77 tprintf("\n");
80 struct protocol none_ops = {
81 .key = 0x01,
82 .print_full = hex_ascii,
83 .print_less = none_less,
86 EXPORT_SYMBOL(none_ops);