32 void DHCP::prepareDHCPRequest()
61 void DHCP::sendDHCPDiscover()
66 const DHCPDiscoverMessageTypeOption discover;
77 const DHCPOption<DHCP_OPTIONS_REQUESTED_IP, sizeof(IPAddress)> r;
84 writeAdditionalFields();
102 uint8_t DHCP::getMessageType()
106 if (mtoption == NULL)
109 return mtoption->messageType;
112 void DHCP::onReceive(uint16_t len)
114 ACTRACE(
"DHCP response");
128 if (sioptionPtr == NULL)
131 DHCPIPOption serverIDOption = *sioptionPtr;
132 DHCPRequestedIPOption requestedIPOption;
135 prepareDHCPRequest();
138 const DHCPRequestMessageTypeOption request;
140 write(serverIDOption);
141 write(requestedIPOption);
142 writeAdditionalFields();
154 switch (getMessageType())
161 if (subnetOpt == NULL || dnsOpt==NULL || routerOpt== NULL)
165 if (timerOpt != NULL)
167 if (timerOpt->timer.h.rawValue != 0)
168 renewalTimer = 0xFFFF;
170 renewalTimer = timerOpt->timer.l;
173 renewalTimer = DHCP_DEFAULT_RENEWAL_TIMER;
203 void DHCP::setMagicCookie()
208 DHCPOptionHeader* DHCP::findOption(uint8_t searchCode)
215 header = (DHCPOptionHeader*)(((uint8_t*)header) + header->length+
sizeof(DHCPOptionHeader)))
217 if (header->code == searchCode)
222 return ((searchCode==header->code) ? header : NULL);
229 ACDEBUG(
"tick/state=%S", getStateString());
240 if (renewalTimer > 0)
272 void DHCP::writeAdditionalFields()
274 const DHCPClientIdentifierOptionHeader clientIdentifierHeader;
275 write(clientIdentifierHeader);
278 #if ENABLE_DHCP_HOSTNAME
280 write(hostnameOptionHeader);
287 __FlashStringHelper* DHCP::getStateString()
304 return (__FlashStringHelper*)s;
static const uint8_t DHCP_OPTIONS_SUBNET
Stores a MAC address in memory.
static const uint8_t DHCP_STATE_REBINDING
The client has failed to renew its lease with the server that originally granted it, and now seeks a lease extension with any server that can hear it.
static const char DHCP_HOSTNAME[]
host name sent to DHCP server.
nint16_t localPort
local TCP or UDP port
static const uint8_t DHCP_STATE_BOUND
Client has a valid lease and is in its normal operating state.
static const uint8_t DHCP_OPTIONS_HOSTNAME
static const uint8_t DHCP_MAX_ATTEMPTS
how many times to retry if address request is denied.
static DNSClient & DNS()
Obtains access to the DNS service singleton instance.
uint16_t write(uint16_t len, const byte *data)
In the case of TCP, writes the given data buffer to the socket.
static EthBuffer packet
in-memory packet buffer currently being processed.
void setState(uint8_t newState, uint8_t timeout)
Changes to a new state
nint16_t remotePort
remote TCP or UDP port
uint32_t rawValue
provides low level access to the memory containing the network-order integer
static const uint8_t DHCP_OPTIONS_RENEWAL_TIME
void tick()
This is a timer function that is called every NETWORK_TIMER_RESOLUTION milliseconds on every service...
bool send()
Sends the packet currently in the outgoing buffer
uint8_t stateTimer
state timer, in ticks
static const uint8_t DHCP_OPTIONS_END
void setBroadcastIP()
Sets the IP to 255.255.255.255
static IPAddress netmask
Subnet mask.
static IPAddress gatewayIP
IP address of the gateway in this network.
static const uint8_t DHCP_OPTIONS_SERVER_IDENTIFIER
#define IPADDR_P(b0, b1, b2, b3)
defines an IP address as stored in PROGMEM
bool dhcpSetup()
Attempts to configure the IP settings: local IP, subnet mask, gateway and DNS via DHCP...
static const uint8_t DHCP_OFFER
static IPAddress dnsIP
IP address of the DNS server to use.
static MACAddress localMAC
Ethernet MAC address.
static const uint8_t DHCP_STATE_REQUESTING
The client is waiting to hear back from the server to which it sent its request.
Base data structures for Internet communication.
static const uint8_t DHCP_ACK
static const uint8_t DHCP_OPTIONS_ROUTER
static void loop()
Gives processing time to EtherDune so that it can check for incoming packets or send queued packets...
static IPAddress localIP
IP address of this application.
IPAddress remoteIP
remote IP address to connect to (TCP) or send the next packet to (UDP)
static const uint8_t DHCP_NACK
static const uint8_t DHCP_OPTIONS_DNS
static const uint8_t DHCP_OPTIONS_MESSAGETYPE
static const uint8_t DHCP_STATE_INIT
This is the initialization state, where a client begins the process of acquiring a lease...
static const uint8_t DHCP_STATE_RENEWING
Client is trying to renew its lease.
static const uint8_t DHCP_STATE_SELECTING
The client is waiting to receive DHCPOFFER messages from one or more DHCP servers, so it can choose one.