Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Checksum calculation for UDP message which contains QHostAddress

Checksum calculation for UDP message which contains QHostAddress

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 2 Posters 2.2k Views
  • 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.
  • N Offline
    N Offline
    NarutoKun
    wrote on last edited by NarutoKun
    #1

    Hello All, I have just started learning QT. Part of my QT assignment I am trying to send UDP command to an IP Camera. I am using QHostAddress to assign the IP address of the camera. I would like to know if there is any option of calculating the checksum of the entire udp message in QT. My udp message contains the IP address and the camera specific commands.
    As of now I have calculated the checksum manually and have hard coded it. However I am trying to come up with software code which would do the checksum calculation by itself in QT.
    Also is there any way I could disintegrate the ip assigned using QHostAddress. ?Disintegrate it in bytes ?

    K 1 Reply Last reply
    0
    • N NarutoKun

      Hello All, I have just started learning QT. Part of my QT assignment I am trying to send UDP command to an IP Camera. I am using QHostAddress to assign the IP address of the camera. I would like to know if there is any option of calculating the checksum of the entire udp message in QT. My udp message contains the IP address and the camera specific commands.
      As of now I have calculated the checksum manually and have hard coded it. However I am trying to come up with software code which would do the checksum calculation by itself in QT.
      Also is there any way I could disintegrate the ip assigned using QHostAddress. ?Disintegrate it in bytes ?

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

      @NarutoKun

      Hi and welcome to devnet forum

      Checksum is not a single formula used. it is more generic term. It typically depends on specific definitions of algorithms. Therefore you need to more specific what you are using and look into the documentation of Qt.

      What do you mean with disintegration of the IP?

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

      N 1 Reply Last reply
      2
      • K koahnig

        @NarutoKun

        Hi and welcome to devnet forum

        Checksum is not a single formula used. it is more generic term. It typically depends on specific definitions of algorithms. Therefore you need to more specific what you are using and look into the documentation of Qt.

        What do you mean with disintegration of the IP?

        N Offline
        N Offline
        NarutoKun
        wrote on last edited by
        #3

        @koahnig

        Thank you for the warm welcome.
        In my application I am looking for 8Bit Checksum.

        I am assigning the IP add of the camera to a variable as below.
        IPCam_add = new QHostAddress ("192.168.1.110")

        UDP command that I need to write to the socket for message transmission is as follows. --
        0_1477227910830_upload-04c6f9d2-dfab-43e4-adab-d1b75ed37d43

        Now for 8Bit Checksum calculation I am planning to sum up all the bytes in the UDP message and then take 2'complement. Thought of using a For Loop for summation of all the bytes in the UDP message. However I am not sure how to disintegrate the IP address.
        By disintegrate IP I meant to break down the 4-Bytes IP address into single byte's. So that I can take each byte separately and sum it up, hence calculating the 8Bit Checksum.

        Hoping you understand my requirement if not please let me know.

        Thank you for your time.

        K 1 Reply Last reply
        0
        • N NarutoKun

          @koahnig

          Thank you for the warm welcome.
          In my application I am looking for 8Bit Checksum.

          I am assigning the IP add of the camera to a variable as below.
          IPCam_add = new QHostAddress ("192.168.1.110")

          UDP command that I need to write to the socket for message transmission is as follows. --
          0_1477227910830_upload-04c6f9d2-dfab-43e4-adab-d1b75ed37d43

          Now for 8Bit Checksum calculation I am planning to sum up all the bytes in the UDP message and then take 2'complement. Thought of using a For Loop for summation of all the bytes in the UDP message. However I am not sure how to disintegrate the IP address.
          By disintegrate IP I meant to break down the 4-Bytes IP address into single byte's. So that I can take each byte separately and sum it up, hence calculating the 8Bit Checksum.

          Hoping you understand my requirement if not please let me know.

          Thank you for your time.

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

          @NarutoKun

          For the checksum you could go for a QCryptographicHash, if you really like to dig as deep.
          Personally I would not go as far.

          In order to split the ip address into its components it is similar. You could use QHostAddress which allows to use a string as initialization. With toIPv4Address you can get a 4 byte number which you can split into single bytes by standard bit manipulation.

          You can use QString::split and use the dot as separator and form a QStringList. Each component may be transformed by toInt.

          At the day's end the question is if you really want to use Qt for it. Personally I am more a fan of reading from a std::istringstream.

          AFAIK there is no special Qt routine doing that already for you.

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

          N 2 Replies Last reply
          2
          • K koahnig

            @NarutoKun

            For the checksum you could go for a QCryptographicHash, if you really like to dig as deep.
            Personally I would not go as far.

            In order to split the ip address into its components it is similar. You could use QHostAddress which allows to use a string as initialization. With toIPv4Address you can get a 4 byte number which you can split into single bytes by standard bit manipulation.

            You can use QString::split and use the dot as separator and form a QStringList. Each component may be transformed by toInt.

            At the day's end the question is if you really want to use Qt for it. Personally I am more a fan of reading from a std::istringstream.

            AFAIK there is no special Qt routine doing that already for you.

            N Offline
            N Offline
            NarutoKun
            wrote on last edited by
            #5

            @koahnig
            I shall try building my application with your suggestions. Will keep you update on the outcome.

            Thanks you for your valuable inputs.

            1 Reply Last reply
            0
            • K koahnig

              @NarutoKun

              For the checksum you could go for a QCryptographicHash, if you really like to dig as deep.
              Personally I would not go as far.

              In order to split the ip address into its components it is similar. You could use QHostAddress which allows to use a string as initialization. With toIPv4Address you can get a 4 byte number which you can split into single bytes by standard bit manipulation.

              You can use QString::split and use the dot as separator and form a QStringList. Each component may be transformed by toInt.

              At the day's end the question is if you really want to use Qt for it. Personally I am more a fan of reading from a std::istringstream.

              AFAIK there is no special Qt routine doing that already for you.

              N Offline
              N Offline
              NarutoKun
              wrote on last edited by kshegunov
              #6

              @koahnig

              I did the following

              QHostAddress *IPCam_addr;
              int addr;
              ip_addr[4];
              
              IPCam_addr = new QHostAddress ("192.168.1.110")
              
              addr = IPCam_addr->toIPv4Address();
              
              ip_addr[0] = ((addr >> 24) & 0xFF);
              ip_addr[1] = ((addr >> 16) & 0xFF);
              ip_addr[2] = ((addr >> 8) & 0xFF);
              ip_addr[3] = (addr  & 0xFF);
              
              qDebug ("%d", ip_addr[0]);
              qDebug ("%d", ip_addr[1]);
              qDebug ("%d", ip_addr[2]);
              qDebug ("%d", ip_addr[3]);
              

              Output -
              192
              168
              1
              110

              So I am able to access each byte individually. Going forward I shall just sum them up and do a 2's complement to calculate the 8-bit checksum.

              Thank you for your support Koahnig. Good day!!

              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