Packet Sniffer
-
This isn't a code fix really more a look for some advice.
Below is the code i have for my socket class. The aim will be to monitor traffic on a chosen interface. i have the list of interfaces listed in my mainwindow.cpp.
I would like to know if im heading in the right direction with the choice of functions and members or have i got it completely wrong. Im not sure QTcpSocket is what i should use, or should i look at the abstract socket. also i have heard about libpcap libraries and tcpdump but im not sure if thats the only option?
@#include "socket.h"
#include "QObject"
#include "QtCore"
#include "QNetworkConfigurationManager"
#include "QNetworkInterface"
#include "QHostAddress"
#include "QString"
#include "QFile"
#include "QLineEdit"
#include "QDir"
#include "QApplication"
#include "QMainWindow"
#include "mainwindow.h"
#include ""Socket::Socket(QObject *parent) :
QObject(parent),
ui(new Ui::Socket)
{
void Socket::test(){socket = new QTcpSocket(this); connect(socket,SIGNAL(connected()), this, SLOT(connected())); connect(socket,SIGNAL(disconnected()), this, SLOT(disconnected())); connect(socket,SIGNAL(readyRead()), this, SLOT(readyRead())); connect(socket,SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); ui->packet->show << "Connecting..."; socket->connectToInterface("comboBox_Interface",80); if (!socket->waitForConnected(3000)) { ui->packet->show << "Error" << socket->errorString(); } } void Socket::connected() { ui->packet->show << "Connected..."; } void Socket::disconnected() { ui->packet->show << "Disconnected..."; } void Socket::bytesWritten ( qint64 bytes ) { ui->packet->show << "We Wrote..." << bytes; } void Socket::readyRead() { ui->packet->show << "Reading..."; ui->packet->show << socket->readAll; }
}
}
@[edit: added missing coding tags @ SGaist]
-
Sorry that was poorly copied :P
@
#include "socket.h"
#include "QObject"
#include "QtCore"
#include "QNetworkConfigurationManager"
#include "QNetworkInterface"
#include "QHostAddress"
#include "QString"
#include "QFile"
#include "QLineEdit"
#include "QDir"
#include "QApplication"
#include "QMainWindow"
#include "mainwindow.h"
#include ""Socket::Socket(QObject *parent) :
QObject(parent),
ui(new Ui::Socket)
{
void Socket::test(){socket = new QTcpSocket(this); connect(socket,SIGNAL(connected()), this, SLOT(connected())); connect(socket,SIGNAL(disconnected()), this, SLOT(disconnected())); connect(socket,SIGNAL(readyRead()), this, SLOT(readyRead())); connect(socket,SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64))); ui->packet->show << "Connecting..."; socket->connectToInterface("comboBox_Interface",80); if (!socket->waitForConnected(3000)) { ui->packet->show << "Error" << socket->errorString(); } } void Socket::connected() { ui->packet->show << "Connected..."; } void Socket::disconnected() { ui->packet->show << "Disconnected..."; } void Socket::bytesWritten ( qint64 bytes ) { ui->packet->show << "We Wrote..." << bytes; } void Socket::readyRead() { ui->packet->show << "Reading..."; ui->packet->show << socket->readAll; }
}
}
@