2012-01-04 22:13:01 +00:00
|
|
|
/* packet_list_record.cpp
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2012-01-04 22:13:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "packet_list_record.h"
|
|
|
|
|
2014-05-31 01:56:35 +00:00
|
|
|
#include <file.h>
|
|
|
|
|
|
|
|
#include <epan/epan_dissect.h>
|
|
|
|
#include <epan/column-info.h>
|
|
|
|
#include <epan/column.h>
|
2015-02-24 01:56:14 +00:00
|
|
|
#include <epan/conversation.h>
|
2014-05-31 01:56:35 +00:00
|
|
|
|
2015-12-22 20:07:00 +00:00
|
|
|
#include <epan/color_filters.h>
|
2014-05-31 01:56:35 +00:00
|
|
|
#include "frame_tvbuff.h"
|
|
|
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
2014-10-05 19:23:33 +00:00
|
|
|
QMap<int, int> PacketListRecord::cinfo_column_;
|
2014-10-21 20:36:10 +00:00
|
|
|
unsigned PacketListRecord::col_data_ver_ = 1;
|
2014-05-31 01:56:35 +00:00
|
|
|
|
2012-10-13 01:37:48 +00:00
|
|
|
PacketListRecord::PacketListRecord(frame_data *frameData) :
|
2014-05-31 01:56:35 +00:00
|
|
|
fdata_(frameData),
|
2015-02-26 21:02:06 +00:00
|
|
|
lines_(1),
|
|
|
|
line_count_changed_(false),
|
2014-10-21 20:36:10 +00:00
|
|
|
data_ver_(0),
|
2015-02-24 01:56:14 +00:00
|
|
|
colorized_(false),
|
|
|
|
conv_(NULL)
|
2012-01-04 22:13:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:06:12 +00:00
|
|
|
// We might want to return a const char * instead. This would keep us from
|
|
|
|
// creating excessive QByteArrays, e.g. in PacketListModel::recordLessThan.
|
2015-08-27 00:14:39 +00:00
|
|
|
const QByteArray PacketListRecord::columnString(capture_file *cap_file, int column, bool colorized)
|
2012-01-04 22:13:01 +00:00
|
|
|
{
|
2014-05-31 01:56:35 +00:00
|
|
|
// packet_list_store.c:packet_list_get_value
|
2012-12-17 23:03:21 +00:00
|
|
|
g_assert(fdata_);
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2014-05-31 01:56:35 +00:00
|
|
|
if (!cap_file || column < 0 || column > cap_file->cinfo.num_cols) {
|
2015-08-27 00:14:39 +00:00
|
|
|
return QByteArray();
|
2014-05-31 01:56:35 +00:00
|
|
|
}
|
2012-01-04 22:13:01 +00:00
|
|
|
|
2015-08-27 00:14:39 +00:00
|
|
|
bool dissect_color = colorized && !colorized_;
|
2015-09-10 23:06:12 +00:00
|
|
|
if (column >= col_text_.size() || !col_text_[column] || data_ver_ != col_data_ver_ || dissect_color) {
|
2015-08-27 00:14:39 +00:00
|
|
|
dissect(cap_file, dissect_color);
|
2014-05-31 01:56:35 +00:00
|
|
|
}
|
2013-07-08 16:54:18 +00:00
|
|
|
|
2014-05-31 01:56:35 +00:00
|
|
|
return col_text_.value(column, QByteArray());
|
2012-01-04 22:13:01 +00:00
|
|
|
}
|
|
|
|
|
2014-05-31 01:56:35 +00:00
|
|
|
void PacketListRecord::resetColumns(column_info *cinfo)
|
|
|
|
{
|
2014-10-21 20:36:10 +00:00
|
|
|
col_data_ver_++;
|
|
|
|
|
2014-05-31 01:56:35 +00:00
|
|
|
if (!cinfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cinfo_column_.clear();
|
|
|
|
int i, j;
|
|
|
|
for (i = 0, j = 0; i < cinfo->num_cols; i++) {
|
|
|
|
if (!col_based_on_frame_data(cinfo, i)) {
|
|
|
|
cinfo_column_[i] = j;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-22 23:33:05 +00:00
|
|
|
void PacketListRecord::resetColorized()
|
|
|
|
{
|
|
|
|
colorized_ = false;
|
|
|
|
}
|
|
|
|
|
2014-05-31 01:56:35 +00:00
|
|
|
void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color)
|
|
|
|
{
|
|
|
|
// packet_list_store.c:packet_list_dissect_and_cache_record
|
|
|
|
epan_dissect_t edt;
|
|
|
|
column_info *cinfo = NULL;
|
|
|
|
gboolean create_proto_tree;
|
|
|
|
struct wtap_pkthdr phdr; /* Packet header */
|
|
|
|
Buffer buf; /* Packet data */
|
2014-10-21 20:36:10 +00:00
|
|
|
gboolean dissect_columns = col_text_.isEmpty() || data_ver_ != col_data_ver_;
|
2014-05-31 01:56:35 +00:00
|
|
|
|
|
|
|
if (!cap_file) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&phdr, 0, sizeof(struct wtap_pkthdr));
|
|
|
|
|
|
|
|
if (dissect_columns) {
|
|
|
|
cinfo = &cap_file->cinfo;
|
|
|
|
}
|
|
|
|
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_init(&buf, 1500);
|
2014-05-31 01:56:35 +00:00
|
|
|
if (!cf_read_record_r(cap_file, fdata_, &phdr, &buf)) {
|
|
|
|
/*
|
|
|
|
* Error reading the record.
|
|
|
|
*
|
|
|
|
* Don't set the color filter for now (we might want
|
|
|
|
* to colorize it in some fashion to warn that the
|
|
|
|
* row couldn't be filled in or colorized), and
|
|
|
|
* set the columns to placeholder values, except
|
|
|
|
* for the Info column, where we'll put in an
|
|
|
|
* error message.
|
|
|
|
*/
|
|
|
|
if (dissect_columns) {
|
|
|
|
col_fill_in_error(cinfo, fdata_, FALSE, FALSE /* fill_fd_columns */);
|
|
|
|
|
|
|
|
cacheColumnStrings(cinfo);
|
|
|
|
}
|
|
|
|
if (dissect_color) {
|
|
|
|
fdata_->color_filter = NULL;
|
2014-09-22 23:33:05 +00:00
|
|
|
colorized_ = true;
|
2014-05-31 01:56:35 +00:00
|
|
|
}
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_free(&buf);
|
2014-05-31 01:56:35 +00:00
|
|
|
return; /* error reading the record */
|
|
|
|
}
|
|
|
|
|
2016-02-03 22:10:40 +00:00
|
|
|
create_proto_tree = ((dissect_color && color_filters_used()) ||
|
|
|
|
(dissect_columns && (have_custom_cols(cinfo) ||
|
|
|
|
have_field_extractors())));
|
2014-05-31 01:56:35 +00:00
|
|
|
|
|
|
|
epan_dissect_init(&edt, cap_file->epan,
|
|
|
|
create_proto_tree,
|
|
|
|
FALSE /* proto_tree_visible */);
|
|
|
|
|
2016-01-10 17:07:24 +00:00
|
|
|
/* Re-color when the coloring rules are changed via the UI. */
|
|
|
|
if (dissect_color) {
|
2014-05-31 01:56:35 +00:00
|
|
|
color_filters_prime_edt(&edt);
|
2016-01-10 17:07:24 +00:00
|
|
|
fdata_->flags.need_colorize = 1;
|
|
|
|
}
|
2014-05-31 01:56:35 +00:00
|
|
|
if (dissect_columns)
|
|
|
|
col_custom_prime_edt(&edt, cinfo);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX - need to catch an OutOfMemoryError exception and
|
|
|
|
* attempt to recover from it.
|
|
|
|
*/
|
|
|
|
epan_dissect_run(&edt, cap_file->cd_t, &phdr, frame_tvbuff_new_buffer(fdata_, &buf), fdata_, cinfo);
|
|
|
|
|
|
|
|
if (dissect_columns) {
|
|
|
|
/* "Stringify" non frame_data vals */
|
|
|
|
epan_dissect_fill_in_columns(&edt, FALSE, FALSE /* fill_fd_columns */);
|
|
|
|
cacheColumnStrings(cinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dissect_color) {
|
|
|
|
colorized_ = true;
|
|
|
|
}
|
2014-10-21 20:36:10 +00:00
|
|
|
data_ver_ = col_data_ver_;
|
2014-05-31 01:56:35 +00:00
|
|
|
|
2015-02-24 01:56:14 +00:00
|
|
|
packet_info *pi = &edt.pi;
|
2016-01-24 03:40:51 +00:00
|
|
|
conv_ = find_conversation(pi->num, &pi->src, &pi->dst, pi->ptype,
|
2015-02-24 01:56:14 +00:00
|
|
|
pi->srcport, pi->destport, 0);
|
|
|
|
|
2014-05-31 01:56:35 +00:00
|
|
|
epan_dissect_cleanup(&edt);
|
2014-08-02 11:00:48 +00:00
|
|
|
ws_buffer_free(&buf);
|
2014-05-31 01:56:35 +00:00
|
|
|
}
|
|
|
|
|
2015-09-10 23:06:12 +00:00
|
|
|
// This assumes only one packet list. We might want to move this to
|
|
|
|
// PacketListModel (or replace this with a wmem allocator).
|
|
|
|
struct _GStringChunk *PacketListRecord::string_pool_ = g_string_chunk_new(1 * 1024 * 1024);
|
|
|
|
void PacketListRecord::clearStringPool()
|
|
|
|
{
|
|
|
|
g_string_chunk_clear(string_pool_);
|
|
|
|
}
|
|
|
|
|
2014-05-31 01:56:35 +00:00
|
|
|
//#define MINIMIZE_STRING_COPYING 1
|
|
|
|
void PacketListRecord::cacheColumnStrings(column_info *cinfo)
|
|
|
|
{
|
|
|
|
// packet_list_store.c:packet_list_change_record(PacketList *packet_list, PacketListRecord *record, gint col, column_info *cinfo)
|
|
|
|
if (!cinfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
col_text_.clear();
|
2015-02-26 21:02:06 +00:00
|
|
|
lines_ = 1;
|
|
|
|
line_count_changed_ = false;
|
2014-05-31 01:56:35 +00:00
|
|
|
|
|
|
|
for (int column = 0; column < cinfo->num_cols; ++column) {
|
2015-02-26 21:02:06 +00:00
|
|
|
int col_lines = 1;
|
2014-05-31 01:56:35 +00:00
|
|
|
|
|
|
|
#ifdef MINIMIZE_STRING_COPYING
|
|
|
|
int text_col = cinfo_column_.value(column, -1);
|
|
|
|
|
|
|
|
/* Column based on frame_data or it already contains a value */
|
|
|
|
if (text_col < 0) {
|
|
|
|
col_fill_in_frame_data(fdata_, cinfo, column, FALSE);
|
2015-06-27 03:00:33 +00:00
|
|
|
col_text_.append(cinfo->columns[column].col_data);
|
2014-05-31 01:56:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cinfo->col_fmt[column]) {
|
2015-07-21 21:46:03 +00:00
|
|
|
case COL_PROTOCOL:
|
|
|
|
case COL_INFO:
|
|
|
|
case COL_IF_DIR:
|
|
|
|
case COL_DCE_CALL:
|
|
|
|
case COL_8021Q_VLAN_ID:
|
|
|
|
case COL_EXPERT:
|
|
|
|
case COL_FREQ_CHAN:
|
|
|
|
if (cinfo->columns[column].col_data && cinfo->columns[column].col_data != cinfo->columns[column].col_buf) {
|
|
|
|
/* This is a constant string, so we don't have to copy it */
|
|
|
|
// XXX - ui/gtk/packet_list_store.c uses G_MAXUSHORT. We don't do proper UTF8
|
|
|
|
// truncation in either case.
|
|
|
|
int col_text_len = MIN(qstrlen(cinfo->col_data[column]) + 1, COL_MAX_INFO_LEN);
|
|
|
|
col_text_.append(QByteArray::fromRawData(cinfo->columns[column].col_data, col_text_len));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* !! FALL-THROUGH!! */
|
|
|
|
|
2014-05-31 01:56:35 +00:00
|
|
|
case COL_DEF_SRC:
|
|
|
|
case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
|
|
|
|
case COL_UNRES_SRC:
|
|
|
|
case COL_DEF_DL_SRC:
|
|
|
|
case COL_RES_DL_SRC:
|
|
|
|
case COL_UNRES_DL_SRC:
|
|
|
|
case COL_DEF_NET_SRC:
|
|
|
|
case COL_RES_NET_SRC:
|
|
|
|
case COL_UNRES_NET_SRC:
|
|
|
|
case COL_DEF_DST:
|
|
|
|
case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
|
|
|
|
case COL_UNRES_DST:
|
|
|
|
case COL_DEF_DL_DST:
|
|
|
|
case COL_RES_DL_DST:
|
|
|
|
case COL_UNRES_DL_DST:
|
|
|
|
case COL_DEF_NET_DST:
|
|
|
|
case COL_RES_NET_DST:
|
|
|
|
case COL_UNRES_NET_DST:
|
|
|
|
default:
|
|
|
|
if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) {
|
|
|
|
/* Use the unresolved value in col_expr_val */
|
|
|
|
// XXX Use QContiguousCache?
|
|
|
|
col_text_.append(cinfo->col_expr.col_expr_val[column]);
|
|
|
|
} else {
|
2015-06-27 03:00:33 +00:00
|
|
|
col_text_.append(cinfo->columns[column].col_data);
|
2014-05-31 01:56:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else // MINIMIZE_STRING_COPYING
|
2015-09-10 23:06:12 +00:00
|
|
|
const char *col_str;
|
2014-05-31 01:56:35 +00:00
|
|
|
if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) {
|
|
|
|
/* Use the unresolved value in col_expr_val */
|
2015-09-10 23:06:12 +00:00
|
|
|
col_str = cinfo->col_expr.col_expr_val[column];
|
2014-05-31 01:56:35 +00:00
|
|
|
} else {
|
|
|
|
int text_col = cinfo_column_.value(column, -1);
|
|
|
|
|
|
|
|
if (text_col < 0) {
|
|
|
|
col_fill_in_frame_data(fdata_, cinfo, column, FALSE);
|
|
|
|
}
|
2015-09-10 23:06:12 +00:00
|
|
|
col_str = cinfo->columns[column].col_data;
|
|
|
|
}
|
|
|
|
// g_string_chunk_insert_const manages a hash table of pointers to
|
|
|
|
// strings:
|
|
|
|
// https://git.gnome.org/browse/glib/tree/glib/gstringchunk.c
|
|
|
|
// We might be better off adding the equivalent functionality to
|
|
|
|
// wmem_tree.
|
|
|
|
col_text_.append(g_string_chunk_insert_const(string_pool_, col_str));
|
|
|
|
for (int i = 0; col_str[i]; i++) {
|
|
|
|
if (col_str[i] == '\n') col_lines++;
|
2015-02-26 21:02:06 +00:00
|
|
|
}
|
|
|
|
if (col_lines > lines_) {
|
|
|
|
lines_ = col_lines;
|
|
|
|
line_count_changed_ = true;
|
2014-05-31 01:56:35 +00:00
|
|
|
}
|
|
|
|
#endif // MINIMIZE_STRING_COPYING
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-04 08:18:31 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|