-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprotocol.h
More file actions
106 lines (90 loc) · 3.3 KB
/
Copy pathprotocol.h
File metadata and controls
106 lines (90 loc) · 3.3 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* libcap_utils - DPMI capture utilities
* Copyright (C) 2003-2014 (see AUTHORS)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef CAPUTILS_PROTOCOL_H
#define CAPUTILS_PROTOCOL_H
#include <caputils/capture.h>
#ifdef CAPUTILS_EXPORT
#pragma GCC visibility push(default)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
enum caputils_protocol_type {
PROTOCOL_UNKNOWN = 0, /* unknown or invalid protocol */
PROTOCOL_DONE, /* no more headers, shouldn't be any more payload */
PROTOCOL_DATA, /* no more headers, payload is data */
PROTOCOL_ARP = 3,
PROTOCOL_BACNET,
PROTOCOL_CDP,
PROTOCOL_DNS,
PROTOCOL_ETHERNET,
PROTOCOL_GRE,
PROTOCOL_GTP,
PROTOCOL_ICMP,
PROTOCOL_IGMP,
PROTOCOL_IPV4,
PROTOCOL_IPV6,
PROTOCOL_MPLS,
PROTOCOL_OSPF,
PROTOCOL_PTPv2,
PROTOCOL_LLDP,
PROTOCOL_PW,
PROTOCOL_SCTP,
PROTOCOL_STP,
PROTOCOL_TCP,
PROTOCOL_UDP,
PROTOCOL_VLAN,
PROTOCOL_CP,
PROTOCOL_CLP,
PROTOCOL_TG,
PROTOCOL_MARKER,
PROTOCOL_VRRP,
PROTOCOL_HTTP,
IPPROTO_VRRP = 112,
PROTOCOL_NUM_AVAILABLE,
};
struct header_chunk;
typedef size_t (*size_callback)(const struct header_chunk* header, const char* ptr);
typedef enum caputils_protocol_type (*payload_callback)(struct header_chunk*, const char* ptr, const char** out);
typedef void (*format_callback)(FILE* fp, const struct header_chunk* header, const char* ptr, unsigned int flags);
typedef void (*dump_callback)(FILE* fp, const struct header_chunk* header, const char* ptr, const char* prefix, int flags);
struct caputils_protocol {
enum caputils_protocol_type type; /* type id */
const char* name; /* human-readable name of this protocol */
size_t size; /* (min) number of bytes required to parse this header (if set to 0 it will always parse, giving you the opportunity to parse as much as possible) */
size_callback size_dyn; /* optional function to calculate the actual size of this header. If set it has precedence over static size */
int partial_print; /* if non-zero the format- and dump-functions is supported even for truncated packets */
payload_callback next_payload; /* get pointer to next payload */
format_callback format; /* print representation of this header chunk */
dump_callback dump; /* dump all fields in this header chunk */
};
/**
* Get a protocol descriptor from type name.
*/
struct caputils_protocol* protocol_get(enum caputils_protocol_type type);
#ifdef __cplusplus
}
#endif
#ifdef CAPUTILS_EXPORT
#pragma GCC visibility pop
#endif
#endif /* CAPUTILS_PACKET_H */