epl: Fix Dead Store (Dead assignement/Dead increment) Warning found by Clang
[metze/wireshark/wip.git] / cfile.c
1 /* cfile.c
2  * capture_file GUI-independent manipulation
3  * Vassilii Khachaturov <vassilii@tarunz.org>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include <config.h>
25
26 #include <glib.h>
27
28 #include <epan/packet.h>
29 #include <wiretap/pcapng.h>
30
31 #include "cfile.h"
32
33 const char *
34 cap_file_get_interface_name(void *data, guint32 interface_id)
35 {
36   capture_file *cf = (capture_file *) data;
37   wtapng_iface_descriptions_t *idb_info;
38   wtap_block_t wtapng_if_descr = NULL;
39   char* interface_name;
40
41   idb_info = wtap_file_get_idb_info(cf->wth);
42
43   if (interface_id < idb_info->interface_data->len)
44     wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, interface_id);
45
46   g_free(idb_info);
47
48   if (wtapng_if_descr) {
49     if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_NAME, &interface_name) == WTAP_OPTTYPE_SUCCESS)
50       return interface_name;
51     if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &interface_name) == WTAP_OPTTYPE_SUCCESS)
52       return interface_name;
53   }
54   return "unknown";
55 }
56
57 const char *
58 cap_file_get_interface_description(void *data, guint32 interface_id)
59 {
60   capture_file *cf = (capture_file *) data;
61   wtapng_iface_descriptions_t *idb_info;
62   wtap_block_t wtapng_if_descr = NULL;
63   char* interface_name;
64
65   idb_info = wtap_file_get_idb_info(cf->wth);
66
67   if (interface_id < idb_info->interface_data->len)
68     wtapng_if_descr = g_array_index(idb_info->interface_data, wtap_block_t, interface_id);
69
70   g_free(idb_info);
71
72   if (wtapng_if_descr) {
73     if (wtap_block_get_string_option_value(wtapng_if_descr, OPT_IDB_DESCR, &interface_name) == WTAP_OPTTYPE_SUCCESS)
74       return interface_name;
75   }
76   return NULL;
77 }
78
79 void
80 cap_file_init(capture_file *cf)
81 {
82   /* Initialize the capture file struct */
83   memset(cf, 0, sizeof(capture_file));
84 }
85
86 /*
87  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
88  *
89  * Local Variables:
90  * c-basic-offset: 2
91  * tab-width: 8
92  * indent-tabs-mode: nil
93  * End:
94  *
95  * ex: set shiftwidth=2 tabstop=8 expandtab:
96  * :indentSize=2:tabSize=8:noTabs=true:
97  */