Kerberos: add kerberos_inject_longterm_key() helper function
[wireshark-sm.git] / ui / qt / sctp_graph_byte_dialog.cpp
blob2250112cf6ff9acbd9551e752ec0c05bf4f3be71
1 /* sctp_graph_byte_dialog.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include "sctp_graph_byte_dialog.h"
11 #include <ui_sctp_graph_byte_dialog.h>
13 #include <file.h>
14 #include <math.h>
15 #include <epan/dissectors/packet-sctp.h>
16 #include "epan/packet.h"
18 #include "ui/tap-sctp-analysis.h"
20 #include <ui/qt/utils/qt_ui_utils.h>
21 #include <ui/qt/widgets/qcustomplot.h>
22 #include "sctp_graph_dialog.h"
23 #include "sctp_assoc_analyse_dialog.h"
25 SCTPGraphByteDialog::SCTPGraphByteDialog(QWidget *parent, const sctp_assoc_info_t *assoc,
26 capture_file *cf, int dir) :
27 QDialog(parent),
28 ui(new Ui::SCTPGraphByteDialog),
29 cap_file_(cf),
30 frame_num(0),
31 direction(dir)
33 Q_ASSERT(assoc);
34 selected_assoc_id = assoc->assoc_id;
36 ui->setupUi(this);
37 Qt::WindowFlags flags = Qt::Window | Qt::WindowSystemMenuHint
38 | Qt::WindowMinimizeButtonHint
39 | Qt::WindowMaximizeButtonHint
40 | Qt::WindowCloseButtonHint;
41 this->setWindowFlags(flags);
42 this->setWindowTitle(tr("SCTP Data and Adv. Rec. Window over Time: %1 Port1 %2 Port2 %3")
43 .arg(gchar_free_to_qstring(cf_get_display_name(cap_file_))).arg(assoc->port1).arg(assoc->port2));
44 if ((direction == 1 && assoc->n_array_tsn1 == 0) || (direction == 2 && assoc->n_array_tsn2 == 0)) {
45 QMessageBox msgBox;
46 msgBox.setText(tr("No Data Chunks sent"));
47 msgBox.exec();
48 return;
49 } else {
50 drawGraph();
54 SCTPGraphByteDialog::~SCTPGraphByteDialog()
56 delete ui;
60 void SCTPGraphByteDialog::drawBytesGraph(const sctp_assoc_info_t *selected_assoc)
62 GList *listTSN = Q_NULLPTR, *tlist = Q_NULLPTR;
63 tsn_t *tsn = Q_NULLPTR;
64 uint8_t type;
65 uint32_t maxBytes;
66 uint64_t sumBytes = 0;
68 if (direction == 1) {
69 maxBytes = selected_assoc->n_data_bytes_ep1;
70 listTSN = g_list_last(selected_assoc->tsn1);
71 } else {
72 maxBytes = selected_assoc->n_data_bytes_ep2;
73 listTSN = g_list_last(selected_assoc->tsn2);
77 while (listTSN) {
78 tsn = gxx_list_data(tsn_t*, listTSN);
79 tlist = g_list_first(tsn->tsns);
80 uint16_t length;
81 while (tlist)
83 type = gxx_list_data(struct chunk_header *, tlist)->type;
84 if (type == SCTP_DATA_CHUNK_ID || type == SCTP_I_DATA_CHUNK_ID) {
85 length = g_ntohs(gxx_list_data(struct data_chunk_header *, tlist)->length);
86 if (type == SCTP_DATA_CHUNK_ID)
87 length -= DATA_CHUNK_HEADER_LENGTH;
88 else
89 length -= I_DATA_CHUNK_HEADER_LENGTH;
90 sumBytes += length;
91 yb.append(sumBytes);
92 xb.append(tsn->secs + tsn->usecs/1000000.0);
93 fb.append(tsn->frame_number);
95 tlist = gxx_list_next(tlist);
97 listTSN = gxx_list_previous(listTSN);
101 QCPScatterStyle myScatter;
102 myScatter.setShape(QCPScatterStyle::ssCircle);
103 myScatter.setSize(3);
105 // create graph and assign data to it:
107 // Add Bytes graph
108 if (xb.size() > 0) {
109 QCPGraph *gr = ui->sctpPlot->addGraph(ui->sctpPlot->xAxis, ui->sctpPlot->yAxis);
110 gr->setName(tr("Bytes"));
111 myScatter.setPen(QPen(Qt::red));
112 myScatter.setBrush(Qt::red);
113 ui->sctpPlot->graph(0)->setScatterStyle(myScatter);
114 ui->sctpPlot->graph(0)->setLineStyle(QCPGraph::lsNone);
115 ui->sctpPlot->graph(0)->setData(xb, yb);
117 ui->sctpPlot->xAxis->setLabel(tr("time [secs]"));
118 ui->sctpPlot->yAxis->setLabel(tr("Received Bytes"));
120 // set axes ranges, so we see all data:
121 QCPRange myXByteRange(0, (selected_assoc->max_secs+1));
122 QCPRange myYByteRange(0, maxBytes);
123 ui->sctpPlot->xAxis->setRange(myXByteRange);
124 ui->sctpPlot->yAxis->setRange(myYByteRange);
128 void SCTPGraphByteDialog::drawGraph()
130 const sctp_assoc_info_t* selected_assoc = SCTPAssocAnalyseDialog::findAssoc(this, selected_assoc_id);
131 if (!selected_assoc) return;
133 ui->sctpPlot->clearGraphs();
134 drawBytesGraph(selected_assoc);
135 ui->sctpPlot->setInteractions(QCP::iRangeZoom | QCP::iRangeDrag | QCP::iSelectPlottables);
136 connect(ui->sctpPlot, &QCustomPlot::plottableClick, this, &SCTPGraphByteDialog::graphClicked);
137 ui->sctpPlot->replot();
141 void SCTPGraphByteDialog::on_pushButton_4_clicked()
143 const sctp_assoc_info_t* selected_assoc = SCTPAssocAnalyseDialog::findAssoc(this, selected_assoc_id);
144 if (!selected_assoc) return;
146 ui->sctpPlot->xAxis->setRange(selected_assoc->min_secs+selected_assoc->min_usecs/1000000.0, selected_assoc->max_secs+selected_assoc->max_usecs/1000000.0);
147 if (direction == 1) {
148 ui->sctpPlot->yAxis->setRange(0, selected_assoc->n_data_bytes_ep1);
149 } else {
150 ui->sctpPlot->yAxis->setRange(0, selected_assoc->n_data_bytes_ep2);
152 ui->sctpPlot->replot();
155 void SCTPGraphByteDialog::graphClicked(QCPAbstractPlottable* plottable, int, QMouseEvent* event)
157 if (plottable->name().contains(tr("Bytes"), Qt::CaseInsensitive)) {
158 double bytes = ui->sctpPlot->yAxis->pixelToCoord(event->pos().y());
159 int i;
160 for (i = 0; i < yb.size(); i++) {
161 if (bytes <= yb.value(i)) {
162 frame_num = fb.at(i);
163 break;
166 if (cap_file_ && frame_num > 0) {
167 cf_goto_frame(cap_file_, frame_num, false);
170 ui->hintLabel->setText(tr("<small><i>Graph %1: Received bytes=%2 Time=%3 secs </i></small>")
171 .arg(plottable->name())
172 .arg(yb.value(i))
173 .arg(xb.value(i)));
178 void SCTPGraphByteDialog::on_saveButton_clicked()
180 SCTPGraphDialog::save_graph(this, ui->sctpPlot);