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. Convert a in_addr to an IPAddr

Convert a in_addr to an IPAddr

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestion
5 Posts 2 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.
  • I Offline
    I Offline
    I am BATMAN
    wrote on last edited by
    #1

    In my code I'm trying to call SendARP to get the MAC address of a computer on the local network. I have their IP address in the in_addr data format, but SendARP takes it as an IPAddr. I looked on MSDN and they don't offer any explicit ways to convert between the two and google searches so far have not proven fruitful. Anyone done this before?

    L 1 Reply Last reply
    0
    • I I am BATMAN

      In my code I'm trying to call SendARP to get the MAC address of a computer on the local network. I have their IP address in the in_addr data format, but SendARP takes it as an IPAddr. I looked on MSDN and they don't offer any explicit ways to convert between the two and google searches so far have not proven fruitful. Anyone done this before?

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      I am BATMAN wrote:

      In my code I'm trying to call SendARP to get the MAC address of a computer on the local network. I have their IP address in the in_addr data format, but SendARP takes it as an IPAddr. I looked on MSDN and they don't offer any explicit ways to convert between the two and google searches so far have not proven fruitful. Anyone done this before?

      Have you looked at the two definitions? IPAddr and in_addr?

      I 2 Replies Last reply
      0
      • L led mike

        I am BATMAN wrote:

        In my code I'm trying to call SendARP to get the MAC address of a computer on the local network. I have their IP address in the in_addr data format, but SendARP takes it as an IPAddr. I looked on MSDN and they don't offer any explicit ways to convert between the two and google searches so far have not proven fruitful. Anyone done this before?

        Have you looked at the two definitions? IPAddr and in_addr?

        I Offline
        I Offline
        I am BATMAN
        wrote on last edited by
        #3

        yes, that was sort of vague...are you talking about how it says you can cast an IPAddr to an in_addr? I tried casting the other direction (in_addr to IPAddr) but it throws errors. Forgive me, this is basically the beginning of my windows C++ programming, up until now it's all been command line linux code. Is there a special way to cast with the win API or something?

        L 1 Reply Last reply
        0
        • L led mike

          I am BATMAN wrote:

          In my code I'm trying to call SendARP to get the MAC address of a computer on the local network. I have their IP address in the in_addr data format, but SendARP takes it as an IPAddr. I looked on MSDN and they don't offer any explicit ways to convert between the two and google searches so far have not proven fruitful. Anyone done this before?

          Have you looked at the two definitions? IPAddr and in_addr?

          I Offline
          I Offline
          I am BATMAN
          wrote on last edited by
          #4

          Oh ok, it worked when I saved the variable as a IPAddr the same way I was originally saving the in_addr instead of trying to cast between the two. Thanks anyways

          1 Reply Last reply
          0
          • I I am BATMAN

            yes, that was sort of vague...are you talking about how it says you can cast an IPAddr to an in_addr? I tried casting the other direction (in_addr to IPAddr) but it throws errors. Forgive me, this is basically the beginning of my windows C++ programming, up until now it's all been command line linux code. Is there a special way to cast with the win API or something?

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            I am BATMAN wrote:

            Forgive me, this is basically the beginning of my windows C++ programming, up until now it's all been command line linux code. Is there a special way to cast with the win API or something?

            Then you need to study beginners material of the language since you need to understand types, structures and unions as well as many, many other things. Trying to explain them to you in a forum is not appropriate.

            typedef struct in_addr {
            union {
            struct { UCHAR s_b1,s_b2,s_b3,s_b4; } S_un_b;
            struct { USHORT s_w1,s_w2; } S_un_w;
            ULONG S_addr;
            } S_un;

            The S_addr member of the union is the same type as IPAddr.

            //
            // IP type definitions.
            //
            typedef ULONG IPAddr; // An IP address.

            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