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. Windows Development
  4. How to check retrived IP address from DHCP server for conflict ?

How to check retrived IP address from DHCP server for conflict ?

Scheduled Pinned Locked Moved Windows Development
tutorialcomsysadminhelpquestion
13 Posts 3 Posters 42 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
    Eugene Pustovoyt
    wrote on last edited by
    #1

    I'm debugging the client's DHСP code on winsock and after receiving DHCPACK I want to check the received IP for a conflict. But I don't know how to. Could someone help with example?

    Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

    D L 2 Replies Last reply
    0
    • E Eugene Pustovoyt

      I'm debugging the client's DHСP code on winsock and after receiving DHCPACK I want to check the received IP for a conflict. But I don't know how to. Could someone help with example?

      Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      That would probably depend on what you mean by "conflict"?

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      E 1 Reply Last reply
      0
      • D Dave Kreskowiak

        That would probably depend on what you mean by "conflict"?

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        E Offline
        E Offline
        Eugene Pustovoyt
        wrote on last edited by
        #3

        I mean to check retrieved from DHCP server IP address is exist a some device in local network with same IP address or not. If exist I have to send DHCPDECLINE to DHCP server and request another IP address

        Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

        D 1 Reply Last reply
        0
        • E Eugene Pustovoyt

          I mean to check retrieved from DHCP server IP address is exist a some device in local network with same IP address or not. If exist I have to send DHCPDECLINE to DHCP server and request another IP address

          Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          What are you writing? This is all handled by the network stack, so a normal application wouldn't even know this was going on. If the IP is already bound to the adapter, you have no way of knowing that because if you try to ping it using the easy and normal methods, you'll only get a response from your own machine, like "ping localhost". If you try to do this before the IP is bound to the adapter, you don't have an IP yet, so you can't use the easy and normal methods here either because they rely on the IP already being set. So the only way to do this would be digging deeper into the network stack and crafting your own packets, and that take admin permissions to be able to do that. A normal user wouldn't be able to do that. In the real world, DHCP servers can be setup to do this themselves, and it's also managed by reserving ranges of IP addresses for static allocation, "ad-hoc allocation", and other ranges for dynamic allocation. Today, you would be hard pressed to get an IP that was in use already from the server.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
          Dave Kreskowiak

          E 1 Reply Last reply
          0
          • D Dave Kreskowiak

            What are you writing? This is all handled by the network stack, so a normal application wouldn't even know this was going on. If the IP is already bound to the adapter, you have no way of knowing that because if you try to ping it using the easy and normal methods, you'll only get a response from your own machine, like "ping localhost". If you try to do this before the IP is bound to the adapter, you don't have an IP yet, so you can't use the easy and normal methods here either because they rely on the IP already being set. So the only way to do this would be digging deeper into the network stack and crafting your own packets, and that take admin permissions to be able to do that. A normal user wouldn't be able to do that. In the real world, DHCP servers can be setup to do this themselves, and it's also managed by reserving ranges of IP addresses for static allocation, "ad-hoc allocation", and other ranges for dynamic allocation. Today, you would be hard pressed to get an IP that was in use already from the server.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            E Offline
            E Offline
            Eugene Pustovoyt
            wrote on last edited by
            #5

            I'm writing a dhcp-client code for my embedded application on cortex. Just I'm writing and debugging code on Windows. I'm testing how dhcp-requests are creating and how responces are handling. After that I'm porting this code to my embedded application For example: https://cdn1.radikalno.ru/uploads/2020/8/2/75f89f33473f9ebdf71927b46ac31262-full.jpg[^]

            Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

            D 1 Reply Last reply
            0
            • E Eugene Pustovoyt

              I'm writing a dhcp-client code for my embedded application on cortex. Just I'm writing and debugging code on Windows. I'm testing how dhcp-requests are creating and how responces are handling. After that I'm porting this code to my embedded application For example: https://cdn1.radikalno.ru/uploads/2020/8/2/75f89f33473f9ebdf71927b46ac31262-full.jpg[^]

              Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Well, that changes thing just a bit. You cannot use a PING to see if something else is using the address. It requires a local IP address to work. After all, where would the target machine send the reply packet to if there's no IP? I don't know how you're going to reliably do this. An ARP query is about the only way you can determine if an address is in use, but that's not guaranteed.

              Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
              Dave Kreskowiak

              E 1 Reply Last reply
              0
              • D Dave Kreskowiak

                Well, that changes thing just a bit. You cannot use a PING to see if something else is using the address. It requires a local IP address to work. After all, where would the target machine send the reply packet to if there's no IP? I don't know how you're going to reliably do this. An ARP query is about the only way you can determine if an address is in use, but that's not guaranteed.

                Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                Dave Kreskowiak

                E Offline
                E Offline
                Eugene Pustovoyt
                wrote on last edited by
                #7

                Thanks. ARP is working!

                Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

                D L 2 Replies Last reply
                0
                • E Eugene Pustovoyt

                  Thanks. ARP is working!

                  Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Like I said, it's not guaranteed to work in all cases. For example, if the other device that has the IP Address doesn't talk to anything before you get the same address, the ARP request can fail to tell you the IP is being used.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                  Dave Kreskowiak

                  1 Reply Last reply
                  0
                  • E Eugene Pustovoyt

                    Thanks. ARP is working!

                    Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

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

                    If you read the DHCP RFC document (https://tools.ietf.org/html/rfc2131[^]) you will see that the server is required to keep track of which IP addresses are in use.

                    1 Reply Last reply
                    0
                    • E Eugene Pustovoyt

                      I'm debugging the client's DHСP code on winsock and after receiving DHCPACK I want to check the received IP for a conflict. But I don't know how to. Could someone help with example?

                      Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

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

                      Hi, I have worked with and implemented a system service with the DHCP protocol. After you have received the DHCPACK you need to broadcast an ARP and make sure that no other node on the network has a claim to the address. You can use either the SendArp[^] or ResolveIpNetEntry2 function[^] to accomplish this. I have a very complete understanding of the DHCP standards so if you have any questions feel free to contact me. Best Wishes, -David Delaune

                      E 1 Reply Last reply
                      0
                      • L Lost User

                        Hi, I have worked with and implemented a system service with the DHCP protocol. After you have received the DHCPACK you need to broadcast an ARP and make sure that no other node on the network has a claim to the address. You can use either the SendArp[^] or ResolveIpNetEntry2 function[^] to accomplish this. I have a very complete understanding of the DHCP standards so if you have any questions feel free to contact me. Best Wishes, -David Delaune

                        E Offline
                        E Offline
                        Eugene Pustovoyt
                        wrote on last edited by
                        #11

                        Thanks. I've used the SendArp function

                        Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

                        L 1 Reply Last reply
                        0
                        • E Eugene Pustovoyt

                          Thanks. I've used the SendArp function

                          Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

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

                          Eugene Pustovoyt wrote:

                          Thanks. I've used the SendArp function

                          Nice. Remember that DHCP is an honor system[^] and that there are no built-in security measures. I researched and implemented a signed/encrypted DHCP protocol but it's completely non-standard and just something I was experimenting with. All of these old standards are garbage... and need to be replaced. Oh... here's a pro tip: After you get your address offer and assign the address make sure to close the listening socket. Guess what happens if you leave a listening socket open for 12+ hours without reading the buffer? The socket buffers fill with 12 hours of whatever arrived at the listening port! I made this mistake in my first iteration. :) Best Wishes, -David Delaune

                          E 1 Reply Last reply
                          0
                          • L Lost User

                            Eugene Pustovoyt wrote:

                            Thanks. I've used the SendArp function

                            Nice. Remember that DHCP is an honor system[^] and that there are no built-in security measures. I researched and implemented a signed/encrypted DHCP protocol but it's completely non-standard and just something I was experimenting with. All of these old standards are garbage... and need to be replaced. Oh... here's a pro tip: After you get your address offer and assign the address make sure to close the listening socket. Guess what happens if you leave a listening socket open for 12+ hours without reading the buffer? The socket buffers fill with 12 hours of whatever arrived at the listening port! I made this mistake in my first iteration. :) Best Wishes, -David Delaune

                            E Offline
                            E Offline
                            Eugene Pustovoyt
                            wrote on last edited by
                            #13

                            Thanks. I did. In final I'll plan to used this code in the embedded application with hardware ethernet chip. It supports only a little count of sockets and I have to use a single socket for some sequence of tasks (DHCP, PING, SNTP etc).

                            Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2

                            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