wiretap: use SPDX identifiers (partial work).
[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+
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     struct wtap_pkthdr *phdr;
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             phdr = wtap_phdr(cap_info->wtap);
57             pseudo_header = &phdr->pseudo_header;
58             wtap_linktype = phdr->pkt_encap;
59             buf = wtap_buf_ptr(cap_info->wtap);
60
61             capture_info_packet(cap_info, wtap_linktype, buf, phdr->caplen, pseudo_header);
62
63             /*g_warning("new packet");*/
64             to_read--;
65         }
66     }
67
68     capture_info_ui_update(&cap_info->ui);
69 }
70
71
72 /* close the info */
73 void capture_info_close(info_data_t* cap_info)
74 {
75     capture_info_ui_destroy(&cap_info->ui);
76     if(cap_info->wtap)
77         wtap_close(cap_info->wtap);
78 }
79
80 #endif /* HAVE_LIBPCAP */
81
82 /*
83  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
84  *
85  * Local variables:
86  * c-basic-offset: 4
87  * tab-width: 8
88  * indent-tabs-mode: nil
89  * End:
90  *
91  * vi: set shiftwidth=4 tabstop=8 expandtab:
92  * :indentSize=4:tabSize=8:noTabs=true:
93  */