-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendpacketwindow.cpp
80 lines (74 loc) · 2.65 KB
/
sendpacketwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "sendpacketwindow.h"
#include "ui_sendpacketwindow.h"
#include "paquet.h"
#include <stdio.h>
#include <string.h>
#include <QtDebug>
SendPacketWindow::SendPacketWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::SendPacketWindow)
{
ui->setupUi(this);
newPaquet = 1;
}
SendPacketWindow::~SendPacketWindow()
{
delete ui;
}
void SendPacketWindow::fromPaquet(paquet* model)
{
_model = model;
newPaquet = 0;
ui->packetSourceIp->setText(QString::fromStdString(model->source));
ui->packetSourcePort->setText(QString::fromStdString(model->sourcePort));
ui->packetDestinationIp->setText(QString::fromStdString(model->destination));
ui->packetDestinationPort->setText(QString::fromStdString(model->destinationPort));
if (model->type == "tcp")
ui->packetType->setCurrentIndex(0);
else if (model->type == "udp")
ui->packetType->setCurrentIndex(1);
else if (model->type == "icmp")
ui->packetType->setCurrentIndex(2);
}
void SendPacketWindow::on_buttonBox_accepted()
{
// QString type = ui->packetType->itemData(ui->packetType->currentIndex());
QString type = ui->packetType->currentText();
QString sourceIp = ui->packetSourceIp->text();
QString sourcePort = ui->packetSourcePort->text();
QString destinationIp = ui->packetDestinationIp->text();
QString destinationPort = ui->packetDestinationPort->text();
QString data = ui->packetData->toPlainText();
QString number = ui->PacketNumber->text();
qDebug("On button send packet");
qDebug() << type;
qDebug() << sourceIp;
qDebug() << sourcePort;
qDebug() << destinationIp;
qDebug() << destinationPort;
qDebug() << data;
paquet *crafted;
if (newPaquet == 0 )
crafted = new paquet(type.toStdString(),
sourceIp.toStdString(),
sourcePort.toStdString(),
destinationIp.toStdString(),
destinationPort.toStdString(),
data.toStdString());
else if (type.toStdString() != _model->type)
crafted = new paquet(type.toStdString(),
sourceIp.toStdString(),
sourcePort.toStdString(),
destinationIp.toStdString(),
destinationPort.toStdString(),
data.toStdString());
else
{
crafted = _model;
}
crafted->send(atoi(number.toStdString().c_str()));
qDebug() << "Packet send to " << destinationIp << ":" << destinationPort;
}
void SendPacketWindow::on_buttonBox_rejected()
{
}