1 | #include <assert.h> |
---|
2 | #include "libtrace.h" |
---|
3 | #include "libpacketdump.h" |
---|
4 | |
---|
5 | #include <libwandder_etsili.h> |
---|
6 | |
---|
7 | DLLEXPORT void decode(int link_type UNUSED, const char *packet, unsigned len) { |
---|
8 | |
---|
9 | char linespace[4096]; |
---|
10 | char namesp[1024]; |
---|
11 | int i; |
---|
12 | uint8_t *cchdr = NULL; |
---|
13 | uint8_t *iricontents = NULL; |
---|
14 | uint8_t ident; |
---|
15 | uint32_t rem = len; |
---|
16 | wandder_etsispec_t *dec; |
---|
17 | wandder_decoder_t *basedec = NULL; |
---|
18 | int lastlevel = 0; |
---|
19 | |
---|
20 | dec = wandder_create_etsili_decoder(); |
---|
21 | wandder_attach_etsili_buffer(dec, (uint8_t *)packet, len, false); |
---|
22 | |
---|
23 | basedec = wandder_get_etsili_base_decoder(dec); |
---|
24 | while (wandder_etsili_get_next_fieldstr(dec, linespace, 4096)) { |
---|
25 | printf(" ETSILI: "); |
---|
26 | for (i = 0; i < wandder_get_level(basedec); i++) { |
---|
27 | printf(" "); |
---|
28 | lastlevel = i + 1; |
---|
29 | } |
---|
30 | printf("%s\n", linespace); |
---|
31 | } |
---|
32 | |
---|
33 | cchdr = wandder_etsili_get_cc_contents(dec, &rem, namesp, 1024); |
---|
34 | |
---|
35 | if (cchdr) { |
---|
36 | printf(" ETSILI: "); |
---|
37 | for (i = 0; i < lastlevel + 1; i++) { |
---|
38 | printf(" "); |
---|
39 | } |
---|
40 | printf("%s: ...\n", namesp); |
---|
41 | wandder_free_etsili_decoder(dec); |
---|
42 | /* XXX What if there is an IPv7?? */ |
---|
43 | decode_next((const char *)cchdr, rem, "eth", |
---|
44 | ((*cchdr) & 0xf0) == 0x40 ? TRACE_ETHERTYPE_IP : |
---|
45 | TRACE_ETHERTYPE_IPV6); |
---|
46 | return; |
---|
47 | } |
---|
48 | |
---|
49 | iricontents = wandder_etsili_get_iri_contents(dec, &rem, &ident, |
---|
50 | namesp, 1024); |
---|
51 | if (iricontents) { |
---|
52 | printf(" ETSILI: "); |
---|
53 | /* hard-coded indentation, but easier than introducing |
---|
54 | * yet another parameter to get_iri_contents() |
---|
55 | */ |
---|
56 | for (i = 0; i < 7; i++) { |
---|
57 | printf(" "); |
---|
58 | } |
---|
59 | printf("%s: ...\n", namesp); |
---|
60 | wandder_free_etsili_decoder(dec); |
---|
61 | if (ident == WANDDER_IRI_CONTENT_IP) { |
---|
62 | decode_next((const char *)iricontents, rem, "eth", |
---|
63 | ((*iricontents) & 0xf0) == 0x40 ? |
---|
64 | TRACE_ETHERTYPE_IP : |
---|
65 | TRACE_ETHERTYPE_IPV6); |
---|
66 | } else if (ident == WANDDER_IRI_CONTENT_SIP) { |
---|
67 | decode_next((const char *)iricontents, rem, "udp", |
---|
68 | 5060); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | return; |
---|
73 | } |
---|