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. QNetworkDatagram::setSender (Qt 5.13.1) not working on Windows 10
Forum Updated to NodeBB v4.3 + New Features

QNetworkDatagram::setSender (Qt 5.13.1) not working on Windows 10

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 512 Views 4 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.
  • S Offline
    S Offline
    skblackbeard
    wrote on last edited by
    #1

    Hi

    I have a small application as part of my MSc. that is receiving UDP packets from a requestor and essentially proxy'ing it out to the destination. The header of the UDP packet should get modified so that at the receiving end it sees the IP and port as the original values from the requestor so that we can reply directly back. I've been doing this currently by just modifying the sender field (setSender) in the QNetworkDatagram that we are sending but it would seem on Windows 10 that this doesn't do anything (the sender IP and port are still the middleman application and not the newly set values)? I haven't been able to find any existing issue like this so if there is a pre-existing post or weblink please fire it my way!

    Below are some extracts of code snippets (Using Qt 5.13.1 libraries, building with MSCV 2019)

    //UDP socket creation
    QUdpSocket* m_pSocket;
    m_pSocket = new QUdpSocket();
    m_pSocket->setSocketOption(QAbstractSocket::KeepAliveOption, true);
    m_pSocket->bind(QHostAddress::AnyIPv4, m_uServerPortNumber, QAbstractSocket::BindFlag::DontShareAddress)
    
    ...
    // Sending a request out
    QNetworkDatagram DirectReq;
    DirectReq.setDestination(QHostAddress(strTargetIP.c_str()), uTargetPort);
    DirectReq.setData(QByteArray(strPayload.c_str()));
    DirectReq.setSender(QHostAddress(strBypassedSourceIP.c_str()), uBypassedSourcePort);
    int result = m_pSocket->writeDatagram(DirectReq);
    m_pSocket->flush();
    
    
    raven-worxR 1 Reply Last reply
    0
    • S skblackbeard

      Hi

      I have a small application as part of my MSc. that is receiving UDP packets from a requestor and essentially proxy'ing it out to the destination. The header of the UDP packet should get modified so that at the receiving end it sees the IP and port as the original values from the requestor so that we can reply directly back. I've been doing this currently by just modifying the sender field (setSender) in the QNetworkDatagram that we are sending but it would seem on Windows 10 that this doesn't do anything (the sender IP and port are still the middleman application and not the newly set values)? I haven't been able to find any existing issue like this so if there is a pre-existing post or weblink please fire it my way!

      Below are some extracts of code snippets (Using Qt 5.13.1 libraries, building with MSCV 2019)

      //UDP socket creation
      QUdpSocket* m_pSocket;
      m_pSocket = new QUdpSocket();
      m_pSocket->setSocketOption(QAbstractSocket::KeepAliveOption, true);
      m_pSocket->bind(QHostAddress::AnyIPv4, m_uServerPortNumber, QAbstractSocket::BindFlag::DontShareAddress)
      
      ...
      // Sending a request out
      QNetworkDatagram DirectReq;
      DirectReq.setDestination(QHostAddress(strTargetIP.c_str()), uTargetPort);
      DirectReq.setData(QByteArray(strPayload.c_str()));
      DirectReq.setSender(QHostAddress(strBypassedSourceIP.c_str()), uBypassedSourcePort);
      int result = m_pSocket->writeDatagram(DirectReq);
      m_pSocket->flush();
      
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @skblackbeard
      the docs say:

      For outgoing datagrams, this function can be used to set the address the datagram should carry. The address address must usually be one of the local addresses assigned to this machine, which can be obtained using QNetworkInterface.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by
        #3

        Furthermore, what you are attempting to do is rewriting the UDP packet headers to forge a different sender. It is by design that this is a privileged function, and not normally done by user programs. It is possible, but may be outside of the intent of the Qt API.

        I light my way forward with the fires of all the bridges I've burned behind me.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          skblackbeard
          wrote on last edited by
          #4

          For outgoing datagrams, this function can be used to set the address the datagram should carry. The address address must usually be one of the local addresses assigned to this machine, which can be obtained using QNetworkInterface.

          Sigh I found this shortly after posting.

          It is possible, but may be outside of the intent of the Qt API.
          It would definitely seem so.

          Thanks so much for the replies

          Pablo J. RoginaP 1 Reply Last reply
          0
          • S skblackbeard

            For outgoing datagrams, this function can be used to set the address the datagram should carry. The address address must usually be one of the local addresses assigned to this machine, which can be obtained using QNetworkInterface.

            Sigh I found this shortly after posting.

            It is possible, but may be outside of the intent of the Qt API.
            It would definitely seem so.

            Thanks so much for the replies

            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @skblackbeard so is your issue solved? Please don't forget to mark your post as such!

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            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