Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Packet Sniffer

    General and Desktop
    1
    2
    2906
    Loading More Posts
    • 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
      davidrhcp last edited by

      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 Reply Quote 0
      • D
        davidrhcp last edited by

        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 Reply Quote 0
        • First post
          Last post