Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Stuffing four byte octets into a dword.

Stuffing four byte octets into a dword.

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 Posters 0 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.
  • E Offline
    E Offline
    esepich
    wrote on last edited by
    #1

    I have four octets of an ip stored as follows. byte octet1,octet2,octet3,octet4 IPAddressCtrl.GetAddress(octet1,octet2,octet3,octet4); What I need to do is get those four bytes into a DWORD in the propor byte order so I can store that DWORD in an SOCKADDR_IN structure like this SOCKADDR_IN saDest; saDest.sin_addr.s_addr = /*Somehow stuff octet1,2,3,4 in*/ Does anyone know how this can be done? Thank you

    L A 2 Replies Last reply
    0
    • E esepich

      I have four octets of an ip stored as follows. byte octet1,octet2,octet3,octet4 IPAddressCtrl.GetAddress(octet1,octet2,octet3,octet4); What I need to do is get those four bytes into a DWORD in the propor byte order so I can store that DWORD in an SOCKADDR_IN structure like this SOCKADDR_IN saDest; saDest.sin_addr.s_addr = /*Somehow stuff octet1,2,3,4 in*/ Does anyone know how this can be done? Thank you

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Look at the MAKELONG macro.

      S 1 Reply Last reply
      0
      • L Lost User

        Look at the MAKELONG macro.

        S Offline
        S Offline
        Stefan Pedersen
        wrote on last edited by
        #3

        ...and if you are messing with network parameters don't forget that it uses network byte order (big endian). Use htonl() and ntohl() to convert between network and host byte order.

        1 Reply Last reply
        0
        • E esepich

          I have four octets of an ip stored as follows. byte octet1,octet2,octet3,octet4 IPAddressCtrl.GetAddress(octet1,octet2,octet3,octet4); What I need to do is get those four bytes into a DWORD in the propor byte order so I can store that DWORD in an SOCKADDR_IN structure like this SOCKADDR_IN saDest; saDest.sin_addr.s_addr = /*Somehow stuff octet1,2,3,4 in*/ Does anyone know how this can be done? Thank you

          A Offline
          A Offline
          Abin
          wrote on last edited by
          #4

          int CIPAddressCtrl::GetAddress( DWORD& dwAddress );

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups