tshark: remove redundant casts.
[metze/wireshark/wip.git] / capture_info.c
1 /* capture_info.c
2  * capture info functions
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  */
10
11 #include <config.h>
12
13 #ifdef HAVE_LIBPCAP
14
15 #include <glib.h>
16
17 #include <epan/packet.h>
18 #include <wiretap/wtap.h>
19
20 #include "capture_info.h"
21
22 #include <epan/capture_dissectors.h>
23
24 static void
25 capture_info_packet(info_data_t* cap_info, gint wtap_linktype, const guchar *pd, guint32 caplen, union wtap_pseudo_header *pseudo_header)
26 {
27     capture_packet_info_t cpinfo;
28
29     /* Setup the capture packet structure */
30     cpinfo.counts = cap_info->counts.counts_hash;
31
32     cap_info->counts.total++;
33     if (!try_capture_dissector("wtap_encap", wtap_linktype, pd, 0, caplen, &cpinfo, pseudo_header))
34         cap_info->counts.other++;
35 }
36
37 /* new packets arrived */
38 void capture_info_new_packets(int to_read, info_data_t* cap_info)
39 {
40     int err;
41     gchar *err_info;
42     gint64 data_offset;
43     wtap_rec *rec;
44     union wtap_pseudo_header *pseudo_header;
45     int wtap_linktype;
46     const guchar *buf;
47
48
49     cap_info->ui.new_packets = to_read;
50
51     /*g_warning("new packets: %u", to_read);*/
52
53     while (to_read > 0) {
54         wtap_cleareof(cap_info->wtap);
55         if (wtap_read(cap_info->wtap, &err, &err_info, &data_offset)) {
56             rec = wtap_get_rec(cap_info->wtap);
57             if (rec->rec_type == REC_TYPE_PACKET) {
58                 pseudo_header = &rec->rec_header.packet_header.pseudo_header;
59                 wtap_linktype = rec->rec_header.packet_header.pkt_encap;
60                 buf = wtap_get_buf_ptr(cap_info->wtap);
61
62                 capture_info_packet(cap_info, wtap_linktype, buf, rec->rec_header.packet_header.caplen, pseudo_header);
63
64                 /*g_warning("new packet");*/
65                 to_read--;
66             }
67         }
68     }
69
70     capture_info_ui_update(&cap_info->ui);
71 }
72
73 #endif /* HAVE_LIBPCAP */
74
75 /*
76  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
77  *
78  * Local variables:
79  * c-basic-offset: 4
80  * tab-width: 8
81  * indent-tabs-mode: nil
82  * End:
83  *
84  * vi: set shiftwidth=4 tabstop=8 expandtab:
85  * :indentSize=4:tabSize=8:noTabs=true:
86  */