How to check retrived IP address from DHCP server for conflict ?
-
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
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 -
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 KreskowiakI'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
-
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
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 -
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 KreskowiakThanks. ARP is working!
Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2
-
Thanks. ARP is working!
Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2
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 -
Thanks. ARP is working!
Eugene Pustovoyt Soft and Hard Developer CPPMessageBox v1.0 CPPToolTip v2.1 CPPDumpCtrl v1.2 CPPHtmlStatic v1.2
-
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
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
-
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
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
-
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
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
-
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
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