A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
Diff: udp/dhcp/dhcp.c
- Revision:
- 179:55342264fca1
- Parent:
- 178:52714fef5ca1
- Child:
- 180:0a30cff6b36a
--- a/udp/dhcp/dhcp.c Tue Dec 29 19:14:35 2020 +0000 +++ b/udp/dhcp/dhcp.c Wed Dec 30 19:26:19 2020 +0000 @@ -58,6 +58,22 @@ char DhcpDomainName[DNS_MAX_LABEL_LENGTH+1]; char DhcpHostName [DNS_MAX_LABEL_LENGTH+1]; +static void clearAll() +{ + DhcpLeaseTime = 0; + DhcpServerIp = 0; + DhcpRouterIp = 0; + DhcpSubnetMask = 0; + DhcpNtpIp = 0; + DhcpRenewalT1 = 0; + DhcpRenewalT2 = 0; + DhcpBroadcastIp = 0; + DhcpLocalIp = 0; + DhcpDnsServerIp = 0; + DhcpDomainName[0] = 0; + DhcpHostName [0] = 0; +} + bool DhcpIpNeedsToBeRouted(uint32_t ip) { if ((ip & 0x000000FF) == 0xFF) return false; //Broadcast 255.xxx.xxx.xxx @@ -267,6 +283,7 @@ break; case DHCPNAK: if (DhcpTrace) { LogTime("DHCP <- nack ip "); Ip4AddressLog(yiaddr); Log("\r\n"); } + clearAll(); break; default: LogTimeF("DHCP <- unknown message %d\r\n", dhcpMessageType); @@ -300,8 +317,7 @@ else { if (DhcpTrace) LogTimeF("DHCP lease has expired\r\n"); - DhcpLocalIp = 0; - DhcpServerIp = 0; + clearAll(); *pSize = sendRequest(pPacket, DHCPDISCOVER, 0, 0); //If outside T2 then start from scratch to do a full DHCP dest = BROADCAST; }