proto_ip_authentication_hdr.h:Usable with pkt_buff
[netsniff-ng.git] / src / dissector.c
blob124cafcf40c030e4d07705a6b949f9a61ec3d41d
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * By Daniel Borkmann <daniel@netsniff-ng.org>
4 * Copyright 2009, 2010, 2011, 2012 Daniel Borkmann.
5 * Subject to the GPL, version 2.
6 */
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include <unistd.h>
12 #include "built_in.h"
13 #include "tprintf.h"
14 #include "dissector.h"
15 #include "dissector_eth.h"
16 #include "pkt_buff.h"
17 #include "proto_struct.h"
19 int dissector_set_print_type(void *ptr, int type)
21 struct protocol *proto = (struct protocol *) ptr;
23 while (proto != NULL) {
24 switch (type) {
25 case FNTTYPE_PRINT_NORM:
26 proto->process = proto->print_full;
27 break;
28 case FNTTYPE_PRINT_LESS:
29 proto->process = proto->print_less;
30 break;
31 default:
32 case FNTTYPE_PRINT_NONE:
33 proto->process = NULL;
34 break;
37 proto = proto->next;
40 return 0;
43 static void dissector_main(struct pkt_buff *pkt, struct protocol *start,
44 struct protocol *end)
46 struct protocol *proto;
48 for (pkt->proto = start; pkt->proto != NULL;) {
49 if (unlikely(!pkt->proto->process))
50 break;
52 proto = pkt->proto;
53 pkt->proto = NULL;
54 proto->process(pkt);
57 if (end != NULL)
58 if (likely(end->process))
59 end->process(pkt);
61 tprintf_flush();
64 void dissector_entry_point(uint8_t *packet, size_t len, int linktype, int mode)
66 struct protocol *proto_start = NULL;
67 struct protocol *proto_end = NULL;
68 struct pkt_buff *pkt = NULL;
70 if (mode == FNTTYPE_PRINT_NONE)
71 return;
73 pkt = pkt_alloc(packet, len);
75 switch (linktype) {
76 case LINKTYPE_EN10MB:
77 proto_start = dissector_get_ethernet_entry_point();
78 proto_end = dissector_get_ethernet_exit_point();
79 break;
80 default:
81 panic("Linktype not supported!\n");
84 dissector_main(pkt, proto_start, proto_end);
86 pkt_free(pkt);
89 void dissector_init_all(int fnttype)
91 dissector_init_ethernet(fnttype);
94 void dissector_cleanup_all(void)
96 dissector_cleanup_ethernet();