Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Packet Sniffer
Forum Update on Monday, May 27th 2025

Packet Sniffer

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davidrhcp
    wrote on last edited by
    #1

    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]

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davidrhcp
      wrote on last edited by
      #2

      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;
      }
      

      }
      }
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved