Creating and sending crafted packets



  • 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?


  • Moderators

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



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


  • Moderators

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



  • 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?


  • Moderators

    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.



  • 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


  • Moderators

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.