2005-12-03 22:38:50 +00:00
|
|
|
/* capture_info.c
|
|
|
|
* capture info functions
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2005-12-03 22:38:50 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2005-12-03 22:38:50 +00:00
|
|
|
*/
|
|
|
|
|
2014-08-22 21:13:05 +00:00
|
|
|
#include <config.h>
|
2005-12-03 22:38:50 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBPCAP
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
2013-12-21 17:23:17 +00:00
|
|
|
#include <wiretap/wtap.h>
|
|
|
|
|
2005-12-03 22:38:50 +00:00
|
|
|
#include "capture_info.h"
|
|
|
|
|
2015-12-13 04:38:21 +00:00
|
|
|
#include <epan/capture_dissectors.h>
|
2005-12-04 02:04:18 +00:00
|
|
|
|
2015-12-15 00:25:31 +00:00
|
|
|
static void
|
2015-12-19 15:11:40 +00:00
|
|
|
capture_info_packet(info_data_t* cap_info, gint wtap_linktype, const guchar *pd, guint32 caplen, union wtap_pseudo_header *pseudo_header)
|
2015-12-15 00:25:31 +00:00
|
|
|
{
|
|
|
|
capture_packet_info_t cpinfo;
|
|
|
|
|
|
|
|
/* Setup the capture packet structure */
|
2015-12-19 15:11:40 +00:00
|
|
|
cpinfo.counts = cap_info->counts.counts_hash;
|
2015-12-15 00:25:31 +00:00
|
|
|
|
2015-12-19 15:11:40 +00:00
|
|
|
cap_info->counts.total++;
|
2015-12-15 00:25:31 +00:00
|
|
|
if (!try_capture_dissector("wtap_encap", wtap_linktype, pd, 0, caplen, &cpinfo, pseudo_header))
|
2015-12-19 15:11:40 +00:00
|
|
|
cap_info->counts.other++;
|
2015-12-15 00:25:31 +00:00
|
|
|
}
|
2005-12-04 02:04:18 +00:00
|
|
|
|
2014-05-23 10:50:02 +00:00
|
|
|
/* new packets arrived */
|
2019-04-07 01:35:00 +00:00
|
|
|
void capture_info_new_packets(int to_read, wtap *wth, info_data_t* cap_info)
|
2005-12-04 02:04:18 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
gchar *err_info;
|
2006-11-05 22:46:44 +00:00
|
|
|
gint64 data_offset;
|
2019-04-05 01:56:27 +00:00
|
|
|
wtap_rec rec;
|
|
|
|
Buffer buf;
|
2005-12-04 02:04:18 +00:00
|
|
|
union wtap_pseudo_header *pseudo_header;
|
|
|
|
int wtap_linktype;
|
|
|
|
|
2015-12-17 04:15:03 +00:00
|
|
|
cap_info->ui.new_packets = to_read;
|
2014-05-23 10:50:02 +00:00
|
|
|
|
2005-12-04 02:04:18 +00:00
|
|
|
/*g_warning("new packets: %u", to_read);*/
|
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
wtap_rec_init(&rec);
|
2019-04-06 21:02:49 +00:00
|
|
|
ws_buffer_init(&buf, 1514);
|
2011-05-19 04:56:04 +00:00
|
|
|
while (to_read > 0) {
|
2019-04-07 01:35:00 +00:00
|
|
|
wtap_cleareof(wth);
|
|
|
|
if (wtap_read(wth, &rec, &buf, &err, &err_info, &data_offset)) {
|
2019-04-05 01:56:27 +00:00
|
|
|
if (rec.rec_type == REC_TYPE_PACKET) {
|
|
|
|
pseudo_header = &rec.rec_header.packet_header.pseudo_header;
|
|
|
|
wtap_linktype = rec.rec_header.packet_header.pkt_encap;
|
2011-05-19 04:56:04 +00:00
|
|
|
|
2019-04-05 01:56:27 +00:00
|
|
|
capture_info_packet(cap_info, wtap_linktype,
|
|
|
|
ws_buffer_start_ptr(&buf),
|
|
|
|
rec.rec_header.packet_header.caplen,
|
|
|
|
pseudo_header);
|
2011-05-19 04:56:04 +00:00
|
|
|
|
2018-02-09 00:19:12 +00:00
|
|
|
/*g_warning("new packet");*/
|
|
|
|
to_read--;
|
|
|
|
}
|
2011-05-19 04:56:04 +00:00
|
|
|
}
|
2005-12-04 02:04:18 +00:00
|
|
|
}
|
2019-04-05 01:56:27 +00:00
|
|
|
wtap_rec_cleanup(&rec);
|
|
|
|
ws_buffer_free(&buf);
|
2005-12-04 02:04:18 +00:00
|
|
|
|
2015-12-17 04:15:03 +00:00
|
|
|
capture_info_ui_update(&cap_info->ui);
|
2005-12-04 02:04:18 +00:00
|
|
|
}
|
|
|
|
|
2005-12-03 22:38:50 +00:00
|
|
|
#endif /* HAVE_LIBPCAP */
|
2014-10-12 18:56:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|