-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdissector.c
More file actions
50 lines (43 loc) · 1.34 KB
/
Copy pathdissector.c
File metadata and controls
50 lines (43 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include "dissector.h"
#define MAX_DISSECTORS 32
static dissector_entry_t registry[MAX_DISSECTORS];
static int registry_count = 0;
void dissector_register(uint8_t l4_proto, uint16_t port,
dissect_fn fn, const char *name, int ret_code)
{
if (registry_count >= MAX_DISSECTORS) {
fprintf(stderr, "dissector registry full, cannot register %s\n", name);
return;
}
registry[registry_count++] = (dissector_entry_t){
.l4_proto = l4_proto,
.port = port,
.fn = fn,
.name = name,
.ret_code = ret_code,
};
}
int dissector_run(const dissector_ctx_t *ctx)
{
int i;
for (i = 0; i < registry_count; i++) {
int ret;
const dissector_entry_t *e = ®istry[i];
if (e->l4_proto != 0 && e->l4_proto != ctx->proto_id_l3)
continue;
if (e->port != 0 &&
e->port != ctx->src_port &&
e->port != ctx->dst_port)
continue;
ret = e->fn(ctx);
if (ret == DISSECT_OK) {
printf("%s protocol FOUND and parsed\n", e->name);
return e->ret_code;
}
if (ret == DISSECT_ERR)
fprintf(stderr, "%s dissector error\n", e->name);
/* DISSECT_SKIP -> continue to next */
}
return 0; /* no dissector matched */
}