attr_dissector_fn_t
[wireshark-sm.git] / file_packet_provider.c
blobd061e3650e3cefab23d4e158af9229443eb6eaec
1 /* file_packet_provider_data.c
2 * Routines for a packet_provider_data for packets from a file.
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10 #include "config.h"
12 #include <stdint.h>
13 #include <glib.h>
14 #include "cfile.h"
16 const nstime_t *
17 cap_file_provider_get_frame_ts(struct packet_provider_data *prov, uint32_t frame_num)
19 const frame_data *fd = NULL;
21 if (prov->ref && prov->ref->num == frame_num) {
22 fd = prov->ref;
23 } else if (prov->prev_dis && prov->prev_dis->num == frame_num) {
24 fd = prov->prev_dis;
25 } else if (prov->prev_cap && prov->prev_cap->num == frame_num) {
26 fd = prov->prev_cap;
27 } else if (prov->frames) {
28 fd = frame_data_sequence_find(prov->frames, frame_num);
31 return (fd && fd->has_ts) ? &fd->abs_ts : NULL;
34 static int
35 frame_cmp(const void *a, const void *b, void *user_data _U_)
37 const frame_data *fdata1 = (const frame_data *) a;
38 const frame_data *fdata2 = (const frame_data *) b;
40 return (fdata1->num < fdata2->num) ? -1 :
41 (fdata1->num > fdata2->num) ? 1 :
45 const char *
46 cap_file_provider_get_interface_name(struct packet_provider_data *prov, uint32_t interface_id, unsigned section_number)
48 wtapng_iface_descriptions_t *idb_info;
49 wtap_block_t wtapng_if_descr = NULL;
50 char* interface_name;
52 idb_info = wtap_file_get_idb_info(prov->wth);
54 unsigned gbl_iface_id = wtap_file_get_shb_global_interface_id(prov->wth, section_number, interface_id);
56 if (gbl_iface_id < idb_info->interface_data->len)
57 wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, gbl_iface_id);
59 g_free(idb_info);
61 if (wtapng_if_descr) {
62 if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_NAME, &interface_name) == WTAP_OPTTYPE_SUCCESS)
63 return interface_name;
64 if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCRIPTION, &interface_name) == WTAP_OPTTYPE_SUCCESS)
65 return interface_name;
66 if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_HARDWARE, &interface_name) == WTAP_OPTTYPE_SUCCESS)
67 return interface_name;
69 return "unknown";
72 const char *
73 cap_file_provider_get_interface_description(struct packet_provider_data *prov, uint32_t interface_id, unsigned section_number)
75 wtapng_iface_descriptions_t *idb_info;
76 wtap_block_t wtapng_if_descr = NULL;
77 char* interface_name;
79 idb_info = wtap_file_get_idb_info(prov->wth);
81 interface_id = wtap_file_get_shb_global_interface_id(prov->wth, section_number, interface_id);
83 if (interface_id < idb_info->interface_data->len)
84 wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, interface_id);
86 g_free(idb_info);
88 if (wtapng_if_descr) {
89 if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCRIPTION, &interface_name) == WTAP_OPTTYPE_SUCCESS)
90 return interface_name;
92 return NULL;
95 wtap_block_t
96 cap_file_provider_get_modified_block(struct packet_provider_data *prov, const frame_data *fd)
98 if (prov->frames_modified_blocks)
99 return (wtap_block_t)g_tree_lookup(prov->frames_modified_blocks, fd);
101 /* ws_warning? */
102 return NULL;
105 void
106 cap_file_provider_set_modified_block(struct packet_provider_data *prov, frame_data *fd, const wtap_block_t new_block)
108 if (!prov->frames_modified_blocks)
109 prov->frames_modified_blocks = g_tree_new_full(frame_cmp, NULL, NULL, (GDestroyNotify)wtap_block_unref);
111 /* insert new packet block */
112 g_tree_replace(prov->frames_modified_blocks, fd, (void *)new_block);
114 fd->has_modified_block = 1;