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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
/** @file
*
* text_import.h
* State machine for text import
* November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
* Modified February 2021, Paul Weiß
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* Based on text2pcap.h by Ashok Narayanan <ashokn@cisco.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later*
*******************************************************************************/
#ifndef __TEXT_IMPORT_H__
#define __TEXT_IMPORT_H__
#include <stdio.h>
#include <wireshark.h>
#include <wiretap/wtap.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/* The parameter interface */
enum offset_type
{
OFFSET_NONE = 0,
OFFSET_HEX,
OFFSET_OCT,
OFFSET_DEC
};
enum data_encoding {
ENCODING_PLAIN_HEX,
ENCODING_PLAIN_OCT,
ENCODING_PLAIN_BIN,
ENCODING_BASE64
};
enum dummy_header_type
{
HEADER_NONE,
HEADER_ETH,
HEADER_IPV4,
HEADER_UDP,
HEADER_TCP,
HEADER_SCTP,
HEADER_SCTP_DATA,
HEADER_EXPORT_PDU
};
enum text_import_mode {
TEXT_IMPORT_HEXDUMP,
TEXT_IMPORT_REGEX
};
typedef struct
{
/* Input info */
// TODO: add const, as this way string constants can't be used
// BUT: the other way clang-check complaines when you free them
/* const */ char *import_text_filename;
char *output_filename;
enum text_import_mode mode;
struct {
FILE *import_text_FILE;
enum offset_type offset_type;
gboolean has_direction;
gboolean identify_ascii;
} hexdump;
struct {
GMappedFile* import_text_GMappedFile;
/* const */ GRegex* format;
enum data_encoding encoding;
/* const */ gchar* in_indication;
/* const */ gchar* out_indication;
} regex;
const char* timestamp_format;
/* Import info */
/* Wiretap encapsulation type; see wiretap/wtap.h for details */
guint encapsulation;
wtap_dumper* wdh;
/* Dummy header info (if encapsulation == 1) */
enum dummy_header_type dummy_header_type;
guint pid;
gboolean ipv6;
union {
ws_in4_addr ipv4;
ws_in6_addr ipv6;
} ip_src_addr;
union {
ws_in4_addr ipv4;
ws_in6_addr ipv6;
} ip_dest_addr;
guint protocol;
guint src_port;
guint dst_port;
guint tag;
guint ppi;
/* const */ gchar* payload;
guint max_frame_length;
/* Output info */
guint num_packets_read;
guint num_packets_written;
} text_import_info_t;
int text_import(text_import_info_t * const info);
/* Write the SHB and IDB to the wtap_dump_params before opening the wtap dump
* file. While dummy headers can be written automatically, this writes out
* some extra information including an optional interface name.
*
* NOTE: The caller will be responsible for freeing params->idb_inf after
* finished with the wtap_dumper to avoid a memory leak. wtap_dump_close
* does not free it.
*/
int
text_import_pre_open(wtap_dump_params * const params, int file_type_subtype, const char* const input_filename, const char* const interface_name);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __TEXT_IMPORT_H__ */
|