dcerpc-netlogon: improve NetrLogonGetCapabilities dissection
[wireshark-sm.git] / wiretap / eri_enb_log.c
bloba4f02ce003c3a236268a900181751db107c52612
1 /* eri_enb_log.c
3 * Ericsson eNode-B raw log file format decoder for the Wiretap library.
5 * Wiretap Library
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include "eri_enb_log.h"
12 #include <string.h>
14 #include "file_wrappers.h"
15 #include "wtap-int.h"
17 static const char eri_enb_log_magic[] = "com_ericsson";
19 static int eri_enb_log_file_type_subtype = -1;
21 void register_eri_enb_log(void);
23 #define MAX_LINE_LENGTH 131072
25 static bool eri_enb_log_get_packet(FILE_T fh, wtap_rec* rec,
26 Buffer* buf, int* err _U_, char** err_info _U_)
28 static char line[MAX_LINE_LENGTH];
29 /* Read in a line */
30 int64_t pos_before = file_tell(fh);
32 while (file_gets(line, sizeof(line), fh) != NULL)
34 nstime_t packet_time;
35 int length;
36 /* Set length (avoiding strlen()) and offset.. */
37 length = (int)(file_tell(fh) - pos_before);
39 /* ...but don't want to include newline in line length */
40 if (length > 0 && line[length - 1] == '\n') {
41 line[length - 1] = '\0';
42 length = length - 1;
44 /* Nor do we want '\r' (as will be written when log is created on windows) */
45 if (length > 0 && line[length - 1] == '\r') {
46 line[length - 1] = '\0';
47 length = length - 1;
50 if (NULL != iso8601_to_nstime(&packet_time, line+1, ISO8601_DATETIME)) {
51 rec->ts.secs = packet_time.secs;
52 rec->ts.nsecs = packet_time.nsecs;
53 rec->presence_flags |= WTAP_HAS_TS;
54 } else {
55 rec->ts.secs = 0;
56 rec->ts.nsecs = 0;
57 rec->presence_flags = 0; /* no time stamp, no separate "on the wire" length */
59 /* We've got a full packet! */
60 rec->rec_type = REC_TYPE_PACKET;
61 rec->block = wtap_block_create(WTAP_BLOCK_PACKET);
62 rec->rec_header.packet_header.caplen = length;
63 rec->rec_header.packet_header.len = length;
65 *err = 0;
67 /* Make sure we have enough room for the packet */
68 ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen);
69 memcpy(ws_buffer_start_ptr(buf), line, rec->rec_header.packet_header.caplen);
71 return true;
74 return false;
77 /* Find the next packet and parse it; called from wtap_read(). */
78 static bool eri_enb_log_read(wtap* wth, wtap_rec* rec, Buffer* buf,
79 int* err, char** err_info, int64_t* data_offset)
81 *data_offset = file_tell(wth->fh);
83 return eri_enb_log_get_packet(wth->fh, rec, buf, err, err_info);
86 /* Used to read packets in random-access fashion */
87 static bool eri_enb_log_seek_read(wtap* wth, int64_t seek_off,
88 wtap_rec* rec, Buffer* buf, int* err, char** err_info)
90 if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
92 return false;
95 return eri_enb_log_get_packet(wth->random_fh, rec, buf, err, err_info);
98 wtap_open_return_val
99 eri_enb_log_open(wtap *wth, int *err, char **err_info)
101 char line1[64];
103 /* Look for Gammu DCT3 trace header */
104 if (file_gets(line1, sizeof(line1), wth->fh) == NULL)
106 *err = file_error(wth->fh, err_info);
107 if (*err != 0 && *err != WTAP_ERR_SHORT_READ)
108 return WTAP_OPEN_ERROR;
109 return WTAP_OPEN_NOT_MINE;
112 if (g_strstr_len(line1, sizeof(line1), eri_enb_log_magic) == NULL)
114 return WTAP_OPEN_NOT_MINE;
117 if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
118 return WTAP_OPEN_ERROR;
120 wth->file_type_subtype = eri_enb_log_file_type_subtype;
121 wth->file_encap = WTAP_ENCAP_ERI_ENB_LOG;
122 wth->file_tsprec = WTAP_TSPREC_NSEC;
123 wth->subtype_read = eri_enb_log_read;
124 wth->subtype_seek_read = eri_enb_log_seek_read;
125 wth->snapshot_length = 0;
127 return WTAP_OPEN_MINE;
130 static const struct supported_block_type eri_enb_log_blocks_supported[] = {
132 * This is a file format that we dissect, so we provide
133 * only one "packet" with the file's contents, and don't
134 * support any options.
136 { WTAP_BLOCK_PACKET, MULTIPLE_BLOCKS_SUPPORTED, NO_OPTIONS_SUPPORTED }
139 static const struct file_type_subtype_info eri_enb_log_info = {
140 "Ericsson eNode-B raw log", "eri_enb_log", "eri_enb_log", NULL,
141 false, BLOCKS_SUPPORTED(eri_enb_log_blocks_supported),
142 NULL, NULL, NULL
145 void register_eri_enb_log(void)
147 eri_enb_log_file_type_subtype = wtap_register_file_type_subtype(&eri_enb_log_info);
150 * Register name for backwards compatibility with the
151 * wtap_filetypes table in Lua.
153 //wtap_register_backwards_compatibility_lua_name("MP4",
154 // eri_enb_log_file_type_subtype);
158 * Editor modelines - https://www.wireshark.org/tools/modelines.html
160 * Local variables:
161 * c-basic-offset: 8
162 * tab-width: 8
163 * indent-tabs-mode: t
164 * End:
166 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
167 * :indentSize=8:tabSize=8:noTabs=false: