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. QNetworkAccessManager with Socks5Proxy with HostNameLookupCapability error
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager with Socks5Proxy with HostNameLookupCapability error

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 690 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.
  • G Offline
    G Offline
    ggeorge82
    wrote on last edited by ggeorge82
    #1

    I'm trying to use this way:
    QNetworkAccessManager *manager = new QNetworkAccessManager();
    QNetworkProxy proxy;
    proxy.setType(QNetworkProxy::Socks5Proxy);
    proxy.setHostName("127.0.0.1");
    proxy.setPort(1111);
    manager->setProxy(proxy)
    auto req = QNetworkRequest(url);
    manager->get(req);
    manager emits signal QNetworkAccessManager::finished with error:
    "SOCKS version 5 protocol error"
    and debug message
    "skipping hostname of len 11"
    11 - is len of hostname in my url
    Socks5 server working good and return right answer, curl with same url and proxy settings return correct answer
    I found this debug message in qt sources:
    https://github.com/qt/qtbase/blob/5.15.2/src/network/socket/qsocks5socketengine.cpp#L248
    in this "if" branch hostname just skipped, and no "ret" value was set, "ret" stays -1, and this value mean error
    How it was supposed to work?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I wonder if you may have found an issue.

      Can you build just the qtbase module with that possibly missing line added to check if it does work ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        ggeorge82
        wrote on last edited by ggeorge82
        #3

        I tried to fix it, build with ret =1, it not helps, another error appear, QHostAddress *pAddress should contain valid value but it can handle only ip4 or ip6, not string hostname

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I just realized, are you sure that 127.0.0.1 is a valid value ? Wouldn't localhost be better ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          G 1 Reply Last reply
          0
          • SGaistS SGaist

            I just realized, are you sure that 127.0.0.1 is a valid value ? Wouldn't localhost be better ?

            G Offline
            G Offline
            ggeorge82
            wrote on last edited by ggeorge82
            #5

            @SGaist i tried localhost too, it doesn't matter, 127.0.0.1 valid value, i tried same params with curl, curl return correct answer, as I wrote before. Firefox with this proxy params working good too. I tried to debug inside private qt network classes, proxy return correct answer with string hostname but it could not be stored in QHostAddress, qt network use it later to retireve connection.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Did you already check the bug report system to see if there's something related to that ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              G 1 Reply Last reply
              0
              • SGaistS SGaist

                Did you already check the bug report system to see if there's something related to that ?

                G Offline
                G Offline
                ggeorge82
                wrote on last edited by
                #7

                @SGaist Yes, found nothnig.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  ggeorge82
                  wrote on last edited by ggeorge82
                  #8

                  Fake Server to reproduce. curl with params running ok "curl --socks5-hostname 127.0.0.1:80 http://domain/ --verbose --include"

                  #include <QCoreApplication>
                  #include <QTcpServer>
                  #include <QTcpSocket>
                  #include <QRunnable>
                  #include <QThreadPool>
                  #include <QNetworkAccessManager>
                  #include <QNetworkProxy>
                  #include <QNetworkReply>
                  class FakeSocks5Proxy : public QRunnable {
                  void run() override {
                  QTcpServer server;
                  server.listen(QHostAddress::Any, 80);
                  while (true) {
                  server.waitForNewConnection();
                  QTcpSocket* client = server.nextPendingConnection();
                  if (client) {
                  client->waitForReadyRead();
                  client->readAll();
                  client->write("\x05\x00", 2);
                  client->flush();
                  client->waitForReadyRead();
                  client->readAll();
                  client->write("\x05\x00\x00\x03\x06""domain\x00\x50", 13);
                  client->flush();
                  client->waitForReadyRead();
                  client->readAll();
                  client->write("HTTP/1.1 200 OK\r\n\r\n");
                  client->flush();
                  client->close();
                  delete client;
                  }
                  }
                  }
                  };

                  int main(int argc, char *argv[])
                  {
                  QCoreApplication a(argc, argv);

                  FakeSocks5Proxy s;
                  QThreadPool::globalInstance()->start(&s);
                  
                  QNetworkAccessManager *manager = new QNetworkAccessManager();
                  QNetworkProxy proxy;
                  proxy.setType(QNetworkProxy::Socks5Proxy);
                  proxy.setHostName("127.0.0.1");
                  proxy.setPort(80);
                  manager->setProxy(proxy);
                  QObject::connect(manager, &QNetworkAccessManager::finished, [=](QNetworkReply *reply){
                      qDebug() << reply->errorString();
                  });
                  manager->get(QNetworkRequest(QUrl("http://domain/")));
                  
                  return a.exec();
                  

                  }

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Since you already built your own version of Qt, did you try to do it with QSOCKS5SOCKETLAYER_DEBUG defined to get more details about what is happening ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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