DhcpClient.h 894 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * DhcpClient.h
  3. *
  4. * Created on: Mar 25, 2023
  5. * Author: ZKSWE Develop Team
  6. */
  7. #ifndef _NET_DHCP_CLIENT_H_
  8. #define _NET_DHCP_CLIENT_H_
  9. #include <stdint.h>
  10. #include <string>
  11. #include "system/Thread.h"
  12. typedef enum {
  13. E_DHCP_LEASE_TYPE_SUCCESS,
  14. E_DHCP_LEASE_TYPE_FAIL,
  15. E_DHCP_LEASE_TYPE_TIMEOUT
  16. } dhcp_lease_type_e;
  17. typedef void (*dhcp_lease_cb)(dhcp_lease_type_e type, void *data);
  18. namespace net {
  19. class DhcpClient : public Thread {
  20. public:
  21. DhcpClient();
  22. virtual ~DhcpClient();
  23. void set_lease_cb(dhcp_lease_cb cb);
  24. bool start(const char *ip, const char *macaddr, const char *gateway);
  25. void stop();
  26. protected:
  27. bool threadLoop();
  28. bool renew();
  29. private:
  30. std::string ip_;
  31. std::string macaddr_;
  32. std::string gateway_;
  33. dhcp_lease_cb lease_cb_;
  34. uint32_t record_time_;
  35. uint32_t lease_;
  36. uint32_t record_lease_;
  37. int wakeup_[2];
  38. };
  39. }
  40. #endif /* _NET_DHCP_CLIENT_H_ */