QString &PacketList::getFilterFromRowAndColumn() { frame_data *fdata; QString &filter = *new QString(); int row = currentIndex().row(); if (!cap_file_ || !packet_list_model_ || ctx_column_ < 0 || ctx_column_ >= cap_file_->cinfo.num_cols) return filter; fdata = packet_list_model_->getRowFdata(row); if (fdata != NULL) { epan_dissect_t edt; if (!cf_read_record(cap_file_, fdata)) return filter; /* error reading the record */ /* proto tree, visible. We need a proto tree if there's custom columns */ epan_dissect_init(&edt, cap_file_->epan, have_custom_cols(&cap_file_->cinfo), FALSE); col_custom_prime_edt(&edt, &cap_file_->cinfo); epan_dissect_run(&edt, cap_file_->cd_t, &cap_file_->phdr, frame_tvbuff_new_buffer(fdata, &cap_file_->buf), fdata, &cap_file_->cinfo); epan_dissect_fill_in_columns(&edt, TRUE, TRUE); if ((cap_file_->cinfo.col_custom_occurrence[ctx_column_]) || (strchr (cap_file_->cinfo.col_expr.col_expr_val[ctx_column_], ',') == NULL)) { /* Only construct the filter when a single occurrence is displayed * otherwise we might end up with a filter like "ip.proto==1,6". * * Or do we want to be able to filter on multiple occurrences so that * the filter might be calculated as "ip.proto==1 && ip.proto==6" * instead? */ if (strlen(cap_file_->cinfo.col_expr.col_expr[ctx_column_]) != 0 && strlen(cap_file_->cinfo.col_expr.col_expr_val[ctx_column_]) != 0) { /* leak a little but safer than ep_ here */ if (cap_file_->cinfo.col_fmt[ctx_column_] == COL_CUSTOM) { header_field_info *hfi = proto_registrar_get_byname(cap_file_->cinfo.col_custom_field[ctx_column_]); if (hfi->parent == -1) { /* Protocol only */ filter.append(cap_file_->cinfo.col_expr.col_expr[ctx_column_]); } else if (hfi->type == FT_STRING) { /* Custom string, add quotes */ filter.append(QString("%1 == \"%2\"") .arg(cap_file_->cinfo.col_expr.col_expr[ctx_column_]) .arg(cap_file_->cinfo.col_expr.col_expr_val[ctx_column_])); } } if (filter.isEmpty()) { filter.append(QString("%1 == %2") .arg(cap_file_->cinfo.col_expr.col_expr[ctx_column_]) .arg(cap_file_->cinfo.col_expr.col_expr_val[ctx_column_])); } } } epan_dissect_cleanup(&edt); } return filter; }
static gboolean process_record(capture_file *cf, frame_data *frame, column_info *cinfo, ph_stats_t* ps) { epan_dissect_t edt; struct wtap_pkthdr phdr; Buffer buf; double cur_time; wtap_phdr_init(&phdr); /* Load the record from the capture file */ ws_buffer_init(&buf, 1500); if (!cf_read_record_r(cf, frame, &phdr, &buf)) return FALSE; /* failure */ /* Dissect the record tree not visible */ epan_dissect_init(&edt, cf->epan, TRUE, FALSE); /* Don't fake protocols. We need them for the protocol hierarchy */ epan_dissect_fake_protocols(&edt, FALSE); epan_dissect_run(&edt, cf->cd_t, &phdr, frame_tvbuff_new_buffer(frame, &buf), frame, cinfo); /* Get stats from this protocol tree */ process_tree(edt.tree, ps, frame->pkt_len); if (frame->flags.has_ts) { /* Update times */ cur_time = nstime_to_sec(&frame->abs_ts); if (cur_time < ps->first_time) ps->first_time = cur_time; if (cur_time > ps->last_time) ps->last_time = cur_time; } /* Free our memory. */ epan_dissect_cleanup(&edt); wtap_phdr_cleanup(&phdr); ws_buffer_free(&buf); return TRUE; /* success */ }
static gboolean process_record(capture_file *cf, frame_data *frame, column_info *cinfo, wtap_rec *rec, Buffer *buf, ph_stats_t* ps) { epan_dissect_t edt; double cur_time; /* Load the record from the capture file */ if (!cf_read_record(cf, frame, rec, buf)) return FALSE; /* failure */ /* Dissect the record tree not visible */ epan_dissect_init(&edt, cf->epan, TRUE, FALSE); /* Don't fake protocols. We need them for the protocol hierarchy */ epan_dissect_fake_protocols(&edt, FALSE); epan_dissect_run(&edt, cf->cd_t, rec, frame_tvbuff_new_buffer(&cf->provider, frame, buf), frame, cinfo); /* Get stats from this protocol tree */ process_tree(edt.tree, ps); if (frame->has_ts) { /* Update times */ cur_time = nstime_to_sec(&frame->abs_ts); if (cur_time < ps->first_time) ps->first_time = cur_time; if (cur_time > ps->last_time) ps->last_time = cur_time; } /* Free our memory. */ epan_dissect_cleanup(&edt); return TRUE; /* success */ }
QVariant PacketListModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); PacketListRecord *record = static_cast<PacketListRecord*>(index.internalPointer()); if (!record) return QVariant(); frame_data *fdata = record->getFdata(); if (!fdata) return QVariant(); switch (role) { case Qt::FontRole: return wsApp->monospaceFont(); case Qt::TextAlignmentRole: switch(recent_get_column_xalign(index.column())) { case COLUMN_XALIGN_RIGHT: return Qt::AlignRight; break; case COLUMN_XALIGN_CENTER: return Qt::AlignCenter; break; case COLUMN_XALIGN_LEFT: return Qt::AlignLeft; break; case COLUMN_XALIGN_DEFAULT: default: if (right_justify_column(index.column(), cap_file_)) { return Qt::AlignRight; } break; } return Qt::AlignLeft; case Qt::BackgroundRole: const color_t *color; if (fdata->flags.ignored) { color = &prefs.gui_ignored_bg; } else if (fdata->flags.marked) { color = &prefs.gui_marked_bg; } else if (fdata->color_filter) { const color_filter_t *color_filter = (const color_filter_t *) fdata->color_filter; color = &color_filter->bg_color; } else { return QVariant(); } // g_log(NULL, G_LOG_LEVEL_DEBUG, "i: %d m: %d cf: %p bg: %d %d %d", fdata->flags.ignored, fdata->flags.marked, fdata->color_filter, color->red, color->green, color->blue); return QColor(color->red >> 8, color->green >> 8, color->blue >> 8); case Qt::ForegroundRole: if (fdata->flags.ignored) { color = &prefs.gui_ignored_fg; } else if (fdata->flags.marked) { color = &prefs.gui_marked_fg; } else if (fdata->color_filter) { const color_filter_t *color_filter = (const color_filter_t *) fdata->color_filter; color = &color_filter->fg_color; } else { return QVariant(); } return QColor(color->red >> 8, color->green >> 8, color->blue >> 8); case Qt::DisplayRole: // Need packet data -- fall through break; default: return QVariant(); } int col_num = index.column(); // g_log(NULL, G_LOG_LEVEL_DEBUG, "showing col %d", col_num); if (!cap_file_ || col_num > cap_file_->cinfo.num_cols) return QVariant(); epan_dissect_t edt; column_info *cinfo; gboolean create_proto_tree; struct wtap_pkthdr phdr; /* Packet header */ Buffer buf; /* Packet data */ gboolean dissect_columns = TRUE; // XXX - Currently only a placeholder if (dissect_columns && cap_file_) cinfo = &cap_file_->cinfo; else cinfo = NULL; buffer_init(&buf, 1500); if (!cap_file_ || !cf_read_frame_r(cap_file_, fdata, &phdr, &buf)) { /* * Error reading the frame. * * 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 */); // for(gint col = 0; col < cinfo->num_cols; ++col) { // /* Skip columns based on frame_data because we already store those. */ // if (!col_based_on_frame_data(cinfo, col)) // packet_list_change_record(packet_list, record->physical_pos, col, cinfo); // } // record->columnized = TRUE; } if (enable_color_) { fdata->color_filter = NULL; // record->colorized = TRUE; } buffer_free(&buf); return QVariant(); /* error reading the frame */ } create_proto_tree = (color_filters_used() && enable_color_) || (have_custom_cols(cinfo) && dissect_columns); epan_dissect_init(&edt, cap_file_->epan, create_proto_tree, FALSE /* proto_tree_visible */); if (enable_color_) color_filters_prime_edt(&edt); if (dissect_columns) col_custom_prime_edt(&edt, cinfo); epan_dissect_run(&edt, &phdr, frame_tvbuff_new_buffer(fdata, &buf), fdata, cinfo); if (enable_color_) fdata->color_filter = color_filters_colorize_packet(&edt); if (dissect_columns) { /* "Stringify" non frame_data vals */ epan_dissect_fill_in_columns(&edt, FALSE, FALSE /* fill_fd_columns */); // for(col = 0; col < cinfo->num_cols; ++col) { // /* Skip columns based on frame_data because we already store those. */ // if (!col_based_on_frame_data(cinfo, col)) // packet_list_change_record(packet_list, record->physical_pos, col, cinfo); // } // g_log(NULL, G_LOG_LEVEL_DEBUG, "d_c %d: %s", col_num, cinfo->col_data[col_num]); } // if (dissect_columns) // record->columnized = TRUE; // if (enable_color_) // record->colorized = TRUE; epan_dissect_cleanup(&edt); buffer_free(&buf); switch (role) { case Qt::DisplayRole: return record->data(col_num, cinfo); break; default: break; } return QVariant(); }
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 */ gboolean dissect_columns = col_text_.isEmpty() || data_ver_ != col_data_ver_; if (!cap_file) { return; } memset(&phdr, 0, sizeof(struct wtap_pkthdr)); if (dissect_columns) { cinfo = &cap_file->cinfo; } ws_buffer_init(&buf, 1500); 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; colorized_ = true; } ws_buffer_free(&buf); return; /* error reading the record */ } create_proto_tree = (dissect_color && color_filters_used()) || (dissect_columns && have_custom_cols(cinfo)); epan_dissect_init(&edt, cap_file->epan, create_proto_tree, FALSE /* proto_tree_visible */); /* Re-color when the coloring rules are changed via the UI. */ if (dissect_color) { color_filters_prime_edt(&edt); fdata_->flags.need_colorize = 1; } 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; } data_ver_ = col_data_ver_; packet_info *pi = &edt.pi; conv_ = find_conversation(pi->num, &pi->src, &pi->dst, pi->ptype, pi->srcport, pi->destport, 0); epan_dissect_cleanup(&edt); ws_buffer_free(&buf); }
Iax2AnalysisDialog::Iax2AnalysisDialog(QWidget &parent, CaptureFile &cf) : WiresharkDialog(parent, cf), ui(new Ui::Iax2AnalysisDialog), port_src_fwd_(0), port_dst_fwd_(0), port_src_rev_(0), port_dst_rev_(0) { ui->setupUi(this); setWindowSubtitle(tr("IAX2 Stream Analysis")); // XXX Use recent settings instead resize(parent.width() * 4 / 5, parent.height() * 4 / 5); ui->progressFrame->hide(); stream_ctx_menu_.addAction(ui->actionGoToPacket); stream_ctx_menu_.addAction(ui->actionNextProblem); stream_ctx_menu_.addSeparator(); stream_ctx_menu_.addAction(ui->actionSaveAudio); stream_ctx_menu_.addAction(ui->actionSaveForwardAudio); stream_ctx_menu_.addAction(ui->actionSaveReverseAudio); stream_ctx_menu_.addSeparator(); stream_ctx_menu_.addAction(ui->actionSaveCsv); stream_ctx_menu_.addAction(ui->actionSaveForwardCsv); stream_ctx_menu_.addAction(ui->actionSaveReverseCsv); stream_ctx_menu_.addSeparator(); stream_ctx_menu_.addAction(ui->actionSaveGraph); ui->forwardTreeWidget->installEventFilter(this); ui->forwardTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->forwardTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showStreamMenu(QPoint))); ui->reverseTreeWidget->installEventFilter(this); ui->reverseTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->reverseTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showStreamMenu(QPoint))); connect(ui->streamGraph, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(graphClicked(QMouseEvent*))); graph_ctx_menu_.addAction(ui->actionSaveGraph); QStringList header_labels; for (int i = 0; i < ui->forwardTreeWidget->columnCount(); i++) { header_labels << ui->forwardTreeWidget->headerItem()->text(i); } ui->reverseTreeWidget->setHeaderLabels(header_labels); memset(&src_fwd_, 0, sizeof(address)); memset(&dst_fwd_, 0, sizeof(address)); memset(&src_rev_, 0, sizeof(address)); memset(&dst_rev_, 0, sizeof(address)); QList<QCheckBox *> graph_cbs = QList<QCheckBox *>() << ui->fJitterCheckBox << ui->fDiffCheckBox << ui->rJitterCheckBox << ui->rDiffCheckBox; for (int i = 0; i < num_graphs_; i++) { QCPGraph *graph = ui->streamGraph->addGraph(); graph->setPen(QPen(ColorUtils::graph_colors_[i])); graph->setName(graph_cbs[i]->text()); graphs_ << graph; graph_cbs[i]->setChecked(true); graph_cbs[i]->setIcon(StockIcon::colorIcon(ColorUtils::graph_colors_[i], QPalette::Text)); } ui->streamGraph->xAxis->setLabel("Arrival Time"); ui->streamGraph->yAxis->setLabel("Value (ms)"); // We keep our temp files open for the lifetime of the dialog. The GTK+ // UI opens and closes at various points. QString tempname = QString("%1/wireshark_iax2_f").arg(QDir::tempPath()); fwd_tempfile_ = new QTemporaryFile(tempname, this); fwd_tempfile_->open(); tempname = QString("%1/wireshark_iax2_r").arg(QDir::tempPath()); rev_tempfile_ = new QTemporaryFile(tempname, this); rev_tempfile_->open(); if (fwd_tempfile_->error() != QFile::NoError || rev_tempfile_->error() != QFile::NoError) { err_str_ = tr("Unable to save RTP data."); ui->actionSaveAudio->setEnabled(false); ui->actionSaveForwardAudio->setEnabled(false); ui->actionSaveReverseAudio->setEnabled(false); } QMenu *save_menu = new QMenu(); save_menu->addAction(ui->actionSaveAudio); save_menu->addAction(ui->actionSaveForwardAudio); save_menu->addAction(ui->actionSaveReverseAudio); save_menu->addSeparator(); save_menu->addAction(ui->actionSaveCsv); save_menu->addAction(ui->actionSaveForwardCsv); save_menu->addAction(ui->actionSaveReverseCsv); save_menu->addSeparator(); save_menu->addAction(ui->actionSaveGraph); ui->buttonBox->button(QDialogButtonBox::Save)->setMenu(save_menu); const gchar *filter_text = "iax2 && (ip || ipv6)"; dfilter_t *sfcode; gchar *err_msg; if (!dfilter_compile(filter_text, &sfcode, &err_msg)) { QMessageBox::warning(this, tr("No IAX2 packets found"), QString("%1").arg(err_msg)); g_free(err_msg); close(); } if (!cap_file_.capFile() || !cap_file_.capFile()->current_frame) close(); frame_data *fdata = cap_file_.capFile()->current_frame; if (!cf_read_record(cap_file_.capFile(), fdata)) close(); epan_dissect_t edt; epan_dissect_init(&edt, cap_file_.capFile()->epan, TRUE, FALSE); epan_dissect_prime_dfilter(&edt, sfcode); epan_dissect_run(&edt, cap_file_.capFile()->cd_t, &cap_file_.capFile()->phdr, frame_tvbuff_new_buffer(fdata, &cap_file_.capFile()->buf), fdata, NULL); // This shouldn't happen (the menu item should be disabled) but check anyway if (!dfilter_apply_edt(sfcode, &edt)) { epan_dissect_cleanup(&edt); dfilter_free(sfcode); err_str_ = tr("Please select an IAX2 packet"); updateWidgets(); return; } dfilter_free(sfcode); /* ok, it is a IAX2 frame, so let's get the ip and port values */ COPY_ADDRESS(&(src_fwd_), &(edt.pi.src)); COPY_ADDRESS(&(dst_fwd_), &(edt.pi.dst)); port_src_fwd_ = edt.pi.srcport; port_dst_fwd_ = edt.pi.destport; /* assume the inverse ip/port combination for the reverse direction */ COPY_ADDRESS(&(src_rev_), &(edt.pi.dst)); COPY_ADDRESS(&(dst_rev_), &(edt.pi.src)); port_src_rev_ = edt.pi.destport; port_dst_rev_ = edt.pi.srcport; #if 0 /* check if it is Voice or MiniPacket */ bool ok; getIntFromProtoTree(edt.tree, "iax2", "iax2.call", &ok); if (!ok) { err_str_ = tr("Please select an IAX2 packet."); updateWidgets(); return; } #endif #ifdef IAX2_RTP_STREAM_CHECK rtpstream_tapinfot tapinfo; /* Register the tap listener */ memset(&tapinfo, 0, sizeof(rtpstream_tapinfot)); tapinfo.tap_data = this; tapinfo.mode = TAP_ANALYSE; // register_tap_listener_rtp_stream(&tapinfo, NULL); /* Scan for RTP streams (redissect all packets) */ rtpstream_scan(&tapinfo, cap_file_.capFile(), NULL); int num_streams = 0; GList *filtered_list = NULL; for (GList *strinfo_list = g_list_first(tapinfo.strinfo_list); strinfo_list; strinfo_list = g_list_next(strinfo_list)) { rtp_stream_info_t * strinfo = (rtp_stream_info_t*)(strinfo_list->data); << address_to_qstring(&strinfo->dest_addr) << address_to_qstring(&src_rev_) << address_to_qstring(&dst_rev_); if (ADDRESSES_EQUAL(&(strinfo->src_addr), &(src_fwd_)) && (strinfo->src_port == port_src_fwd_) && (ADDRESSES_EQUAL(&(strinfo->dest_addr), &(dst_fwd_))) && (strinfo->dest_port == port_dst_fwd_)) { ++num_streams; filtered_list = g_list_prepend(filtered_list, strinfo); } if (ADDRESSES_EQUAL(&(strinfo->src_addr), &(src_rev_)) && (strinfo->src_port == port_src_rev_) && (ADDRESSES_EQUAL(&(strinfo->dest_addr), &(dst_rev_))) && (strinfo->dest_port == port_dst_rev_)) { ++num_streams; filtered_list = g_list_append(filtered_list, strinfo); } }
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; wtap_rec rec; /* Record metadata */ Buffer buf; /* Record data */ if (!col_text_) col_text_ = new ColumnTextList; gboolean dissect_columns = col_text_->isEmpty() || data_ver_ != col_data_ver_; if (!cap_file) { return; } memset(&rec, 0, sizeof rec); if (dissect_columns) { cinfo = &cap_file->cinfo; } ws_buffer_init(&buf, 1500); if (!cf_read_record_r(cap_file, fdata_, &rec, &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; colorized_ = true; } ws_buffer_free(&buf); return; /* error reading the record */ } /* * Determine whether we need to create a protocol tree. * We do if: * * we're going to apply a color filter to this packet; * * we're need to fill in the columns and we have custom columns * (which require field values, which currently requires that * we build a protocol tree). * * XXX - field extractors? (Not done for GTK+....) */ create_proto_tree = ((dissect_color && color_filters_used()) || (dissect_columns && (have_custom_cols(cinfo) || have_field_extractors()))); epan_dissect_init(&edt, cap_file->epan, create_proto_tree, FALSE /* proto_tree_visible */); /* Re-color when the coloring rules are changed via the UI. */ if (dissect_color) { color_filters_prime_edt(&edt); fdata_->flags.need_colorize = 1; } 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, &rec, frame_tvbuff_new_buffer(&cap_file->provider, 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; } data_ver_ = col_data_ver_; packet_info *pi = &edt.pi; conv_ = find_conversation_pinfo(pi, 0); epan_dissect_cleanup(&edt); ws_buffer_free(&buf); }