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. IP address format
Forum Updated to NodeBB v4.3 + New Features

IP address format

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 6 Posters 937 Views 3 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.
  • sitesvS Offline
    sitesvS Offline
    sitesv
    wrote on last edited by
    #1

    Hi!
    QTcpSocket
    If I use "192.168.010.011" ip-address format, connection will not be complete...
    But if I use "192.168.10.11" connection success...
    Could anybody explain this behaviour?
    Thank you!

    K 1 Reply Last reply
    0
    • sitesvS sitesv

      Hi!
      QTcpSocket
      If I use "192.168.010.011" ip-address format, connection will not be complete...
      But if I use "192.168.10.11" connection success...
      Could anybody explain this behaviour?
      Thank you!

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @sitesv

      Both should work.

      You need to give more information on OS and Qt version.

      Alsoshowing the part of code where you are using the address to connect would help.

      Vote the answer(s) that helped you to solve your issue(s)

      sitesvS 1 Reply Last reply
      1
      • K koahnig

        @sitesv

        Both should work.

        You need to give more information on OS and Qt version.

        Alsoshowing the part of code where you are using the address to connect would help.

        sitesvS Offline
        sitesvS Offline
        sitesv
        wrote on last edited by sitesv
        #3

        @koahnig said in IP address format:

        @sitesv

        Both should work.

        You need to give more information on OS and Qt version.

        Alsoshowing the part of code where you are using the address to connect would help.

        Win10 x64, Qt 5.15.2 (msvc 2019 64 bit)

        QString ip = "192.168.010.011";
        QTcpSocket *sock = new QTcpSocket;
        sock->connectToHost(ip, 4321);
        if(sock->waitForConnected(3000)){
           //done
        }
        

        "waitForConnected" returns "Host not found" error

        raven-worxR KroMignonK 2 Replies Last reply
        0
        • sitesvS sitesv

          @koahnig said in IP address format:

          @sitesv

          Both should work.

          You need to give more information on OS and Qt version.

          Alsoshowing the part of code where you are using the address to connect would help.

          Win10 x64, Qt 5.15.2 (msvc 2019 64 bit)

          QString ip = "192.168.010.011";
          QTcpSocket *sock = new QTcpSocket;
          sock->connectToHost(ip, 4321);
          if(sock->waitForConnected(3000)){
             //done
          }
          

          "waitForConnected" returns "Host not found" error

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @sitesv
          try

          sock->connectToHost( QHostAddress(ip), 4321);
          

          in the hope it does better parsing.

          Edit: but it doesnt

          --- 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
          2
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by ChrisW67
            #5

            You may find that "192.168.010.011" is being treated as an IPv4 address with two components in decimal and the last two in octal due to the leading zero. 010 octal is 8 decimal, and 011 octal is 9 decimal, so the address being sought is 192.168.8.9, which evidently does not exist.

            You may also find you can specify the components in hex "0xC0.0xA8.0X0A.0x0B".

            Try this:

            QHostAddress blah("192.168.010.011");
            qDebug() << blah.toString();
            
            sitesvS 1 Reply Last reply
            3
            • C ChrisW67

              You may find that "192.168.010.011" is being treated as an IPv4 address with two components in decimal and the last two in octal due to the leading zero. 010 octal is 8 decimal, and 011 octal is 9 decimal, so the address being sought is 192.168.8.9, which evidently does not exist.

              You may also find you can specify the components in hex "0xC0.0xA8.0X0A.0x0B".

              Try this:

              QHostAddress blah("192.168.010.011");
              qDebug() << blah.toString();
              
              sitesvS Offline
              sitesvS Offline
              sitesv
              wrote on last edited by
              #6

              @ChrisW67 said in IP address format:

              You may find that "192.168.010.011" is being treated as an IPv4 address with two components in decimal and the last two in octal due to the leading zero. 010 octal is 8 decimal, and 011 octal is 9 decimal, so the address being sought is 192.168.8.9, which evidently does not exist.

              Hi!
              I see.
              Very strange behaviour...

              1 Reply Last reply
              0
              • sitesvS sitesv

                @koahnig said in IP address format:

                @sitesv

                Both should work.

                You need to give more information on OS and Qt version.

                Alsoshowing the part of code where you are using the address to connect would help.

                Win10 x64, Qt 5.15.2 (msvc 2019 64 bit)

                QString ip = "192.168.010.011";
                QTcpSocket *sock = new QTcpSocket;
                sock->connectToHost(ip, 4321);
                if(sock->waitForConnected(3000)){
                   //done
                }
                

                "waitForConnected" returns "Host not found" error

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by
                #7

                @sitesv said in IP address format:

                QString ip = "192.168.010.011";

                I am not sure if it is a problem, but I've got many years ago problems with parsing "0010" to int.
                Problem was very ugly, because atoi() decode 0010 as octal, so the parsed value is 8 and not 10!

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                JonBJ 1 Reply Last reply
                0
                • KroMignonK KroMignon

                  @sitesv said in IP address format:

                  QString ip = "192.168.010.011";

                  I am not sure if it is a problem, but I've got many years ago problems with parsing "0010" to int.
                  Problem was very ugly, because atoi() decode 0010 as octal, so the parsed value is 8 and not 10!

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @KroMignon said in IP address format:

                  Problem was very ugly, because atoi() decode 0010 as octal, so the parsed value is 8 and not 10!

                  This ought never be the case! While the strtol(), which atoi() calls, accepts a base of 0 to mean interpret string as C-type-string, where 0 would indicate octal, all the atoi()s I have been able to find are defined as:

                  strtol(nptr, NULL, 10);
                  

                  which should force base 10 always.....

                  KroMignonK 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @KroMignon said in IP address format:

                    Problem was very ugly, because atoi() decode 0010 as octal, so the parsed value is 8 and not 10!

                    This ought never be the case! While the strtol(), which atoi() calls, accepts a base of 0 to mean interpret string as C-type-string, where 0 would indicate octal, all the atoi()s I have been able to find are defined as:

                    strtol(nptr, NULL, 10);
                    

                    which should force base 10 always.....

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by
                    #9

                    @JonB said in IP address format:

                    This ought never be the case! While the strtol(), which atoi() calls, accepts a base of 0 to mean interpret string as C-type-string, where 0 would indicate octal, all the atoi()s I have been able to find are defined as:
                    strtol(nptr, NULL, 10);

                    which should force base 10 always.....

                    Sorry, my bad, it was not atoi() but sscanf()!

                    And, to be clear, this is not a bug, but the way sscanf() parse a decimal value:

                    • a string starting with 0 should be parsed as octal
                    • a string starting with x should be parsed as hexadecimal

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    1 Reply Last reply
                    3

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved