Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of WIZnetInterface by
DHCPClient.h
00001 // DHCPClient.h 2013/4/10 00002 #ifndef DHCPCLIENT_H 00003 #define DHCPCLIENT_H 00004 #include "eth_arch.h" 00005 #include "UDPSocket.h" 00006 00007 #define DHCP_OFFSET_OP 0 00008 #define DHCP_OFFSET_XID 4 00009 #define DHCP_OFFSET_YIADDR 16 00010 #define DHCP_OFFSET_SIADDR 20 00011 #define DHCP_OFFSET_OPTIONS 240 00012 #define DHCP_MAX_PACKET_SIZE 600 00013 00014 #define DHCP_SERVER_PORT 67 00015 #define DHCP_CLIENT_PORT 68 00016 00017 // DHCP Message Type 00018 #define DHCPDISCOVER 1 00019 #define DHCPOFFER 2 00020 #define DHCPREQUEST 3 00021 #define DHCPDECLINE 4 00022 #define DHCPACK 5 00023 #define DHCPNAK 6 00024 #define DHCPRELEASE 7 00025 #define DHCPINFORM 8 00026 #define DHCP_MAGIC_COOKIE 0x63825363 00027 #define OPT_PAD 0 00028 #define OPT_SUBNET_MASK 1 00029 #define OPT_TIME_OFFSET 2 00030 #define OPT_ROUTER 3 00031 #define OPT_TIME_SERVER 4 00032 #define OPT_IEN116_NAME_SERVER 5 00033 #define OPT_DNS 6 00034 #define OPT_LOG_SERVER 7 00035 #define OPT_COOKIE_SERVER 8 00036 #define OPT_LPR_SERVER 9 00037 #define OPT_IMPRESS_SERVER 10 00038 #define OPT_RESOURCE_LOC_SERVER 11 00039 #define OPT_HOSTNAME 12 00040 #define OPT_BOOTFILE_SIZE 13 00041 #define OPT_MERIT_DUMP 14 00042 #define OPT_DOMAIN_NAME 15 00043 #define OPT_SWAP_SERVER 16 00044 #define OPT_ROOT_PATH 17 00045 #define OPT_EXTENSIONS_PATH 18 00046 #define OPT_IP_FORWARDING 19 00047 #define OPT_NONLOCAL_SOURCE_ROUTING 20 00048 #define OPT_POLICY_FILTER 21 00049 #define OPT_MAX_DATAGRAM_REASS 22 00050 #define OPT_DEFAULT_IP_TTL 23 00051 #define OPT_PATH_MTU_AGING_TIMEOUT 24 00052 #define OPT_PATH_MTU_PLATEAU_TABLE 25 00053 #define OPT_INTERFACE_MTU 26 00054 #define OPT_ALL_SUBNETS_ARE_LOCAL 27 00055 #define OPT_BROADCAST_ADDR 28 00056 #define OPT_STATIC_ROUTE 33 00057 #define OPT_VENDOR 43 00058 #define OPT_NETBIOS_NAME_SERVER 44 00059 #define OPT_NETBIOS_DATA_DIST 45 00060 #define OPT_NETBIOS_NODE_TYPE 46 00061 #define OPT_NETBIOS_SCOPE 47 00062 #define OPT_IP_ADDR_REQ 50 00063 #define OPT_ADDR_LEASE_TIME 51 00064 #define OPT_DHCP_MESSAGE 53 00065 #define OPT_SERVER_IDENT 54 00066 #define OPT_PARAMETER_REQ 55 00067 #define OPT_RENEWAL_TIME 58 00068 #define OPT_REBINDING_TIME 59 00069 #define OPT_CLIENT_IDENT 61 00070 #define OPT_TFTP_SERVER_NAME 66 00071 #define OPT_BOOTFILE_NAME 67 00072 #define OPT_LDAP_URL 95 /* from draft RFC */ 00073 #define OPT_DOMAIN_SEARCH 119 /* from draft RFC 3397 */ 00074 00075 /* site specific options */ 00076 #define SITE_HD 252 00077 #define SITE_BF 253 00078 #define SITE_SA 254 00079 #define OPT_END 255 00080 00081 class DHCPClient { 00082 public: 00083 DHCPClient(); 00084 ~DHCPClient(); 00085 int setup(const char *hostnane, int timeout_ms = 15*1000); 00086 uint8_t chaddr[6]; // MAC 00087 uint8_t yiaddr[4]; // IP 00088 uint8_t siaddr[4]; // DHCP server 00089 uint8_t dnsaddr[4]; // DNS 00090 uint8_t gateway[4]; 00091 uint8_t netmask[4]; 00092 uint8_t timesrv[4]; 00093 uint8_t leaseTime[4]; 00094 char *domainName; 00095 private: 00096 int discover(); 00097 int request(); 00098 int offer(uint8_t buf[], int size); 00099 void add_buf(uint8_t* buf, int len); 00100 void fill_buf(int len, uint8_t data = 0x00); 00101 void add_buf(uint8_t c); 00102 void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0); 00103 bool verify(uint8_t buf[], int len); 00104 void callback(); 00105 UDPSocket* m_udp; 00106 Endpoint m_server; 00107 uint8_t xid[4]; 00108 bool exit_flag; 00109 Timer m_interval; 00110 int m_retry; 00111 uint8_t m_buf[DHCP_MAX_PACKET_SIZE]; 00112 int m_pos; 00113 const char *_hostname; 00114 WIZnet_Chip* eth; 00115 }; 00116 #endif //DHCPCLIENT_H 00117
Generated on Tue Jul 12 2022 17:13:34 by
1.7.2
