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. Creating and sending crafted packets
Qt 6.11 is out! See what's new in the release blog

Creating and sending crafted packets

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 4.4k Views 1 Watching
  • 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.
  • Q Offline
    Q Offline
    QTDavid
    wrote on last edited by
    #1

    Hello,

    I have been writing an application that creates a QByteArray representing a packet of data that I carefully craft in order to control the parameters present in a UDP Header (according to http://en.wikipedia.org/wiki/User_Datagram_Protocol#IPv4_Pseudo_Header)

    I was wondering if Qt allows me to simply send a QByteArray without asking for any binding, source/destination port or address, etc.
    Long story short, I want to be able to control every single bit (at least up to the Internet Layer) within a packet that is sent from the socket.

    Ideally, I'd like to have something like this:

    @
    QAbstractSocket *testSocket;
    testSocket = new QAbstractSocket(QAbstractSocket::UdpSocket, this);

    testSocket->write(dataPacket); // where dataPacket is a QByteArray
    //containing the packet crafted
    @

    Anyone knows something about it?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      No, you can send arbitrary data, but the tcp/ip stack adds its own headers.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        QTDavid
        wrote on last edited by
        #3

        Ok, thanks a lot.
        I'll try some more C++ standard stuff.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tobias.hunger
          wrote on last edited by
          #4

          I doubt that you will find anything in the standards... you will need OS-functionality or a special purpose library for this.

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            QTDavid
            wrote on last edited by
            #5

            I'll have a look at that thank you.
            With OS-functionality do you mean that crafting packets can only be done by the OS, or the application requires root (or administrator) permissions?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tobias.hunger
              wrote on last edited by
              #6

              Most likely both:-) You will need some special OS functions to send crafted packages, and you will most likely also need elevated privileges to be allowed to use them.

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                QTDavid
                wrote on last edited by
                #7

                Well, I already have some experience in programming with raw C/C++, so I thought I could use a generic socket coming from:

                @#include <sys/socket.h> // or #include "sys/socket.h", don't really remember right now :P@

                And either use the ip packet struct to send exactly what I want, or send a packet formed of an array of char[].
                This is all theoretic, I did not get to try any of this...yet :P

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tobias.hunger
                  wrote on last edited by
                  #8

                  I do not think that will work: They will do the IP for you, too, just like the Qt classes built on top of them.

                  Basically you can not use anything that requires an IP address to create;) That is a strong indication that the TCP/IP headers will be handled for you.

                  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