开发者

Is there a method to procedurally detecting if network router supports DHCP using C/C++?

There is a scenario where an 开发者_如何转开发application tells a device on a network to get their IP address from the network router's DHCP server. If a DHCP server is not available, the device's behavior becomes erratic. Is there a method to procedurally detect if the network router supports DHCP? Or, is this something the device needs to do when attempting to get its IP address from the DHCP server?


DHCP client on the device is doing exactly that. Well, almost that.

The DHCP DISCOVERY message is broadcast on the link. Then, if there are any DHCP servers willing to serve this particular MAC address, each one reserves an IP address from its pool, and answers with the OFFER message. The client then picks what server it wants to "bind" to and issues the REQUEST message. The server confirms the granted lease of the IP address with an ACK message.
The client discovers "non-availability" of DHCP servers by simply timing out waiting for offers.

Take a look at the DHCPing project. Might give you some ideas.

Links to the DHCP RFCs:

RFC 2131, Dynamic Host Configuration Protocol
RFC 2132, DHCP Options and BOOTP Vendor Extensions


I was something along the lines of this Windows DHCP C API.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜