exeption of receive(TCPSocketconnection)

Dependents:   FTP_SDCard_File_Client_WIZwiki-W7500 FTPClient_example Freedman DigitalCamera_OV5642_WIZwiki-W7500 ... more

Fork of WIZnetInterface by WIZnet

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DHCPClient.h Source File

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 // DHCP Message Type
00015 #define DHCPDISCOVER 1
00016 #define DHCPOFFER    2
00017 #define DHCPREQUEST  3
00018 #define DHCPDECLINE  4
00019 #define DHCPACK      5
00020 #define DHCPNAK      6
00021 #define DHCPRELEASE  7
00022 #define DHCPINFORM   8
00023 
00024 class DHCPClient {
00025 public:
00026     DHCPClient();
00027     int setup(int timeout_ms = 15*1000);
00028     uint8_t chaddr[6]; // MAC
00029     uint8_t yiaddr[4]; // IP
00030     uint8_t dnsaddr[4]; // DNS
00031     uint8_t gateway[4];
00032     uint8_t netmask[4];
00033     uint8_t siaddr[4];
00034 private:
00035     int discover();
00036     int request();
00037     int offer(uint8_t buf[], int size);
00038     void add_buf(uint8_t* buf, int len);
00039     void fill_buf(int len, uint8_t data = 0x00);
00040     void add_buf(uint8_t c);
00041     void add_option(uint8_t code, uint8_t* buf = NULL, int len = 0);
00042     bool verify(uint8_t buf[], int len);
00043     void callback();
00044     UDPSocket* m_udp;
00045     Endpoint m_server;
00046     uint8_t xid[4];
00047     bool exit_flag;
00048     Timer m_interval;
00049     int m_retry;
00050     uint8_t m_buf[DHCP_MAX_PACKET_SIZE];
00051     int m_pos;
00052     WIZnet_Chip* eth;
00053 };
00054 #endif //DHCPCLIENT_H
00055