- sizeof(uip_ipaddr_t), &GatewayIPAddress);\r
-\r
- DHCPServerApp_LeaseIP(&AppData->YourIP);\r
- }\r
- else\r
- {\r
- AppDataSize += DHCPServerApp_FillDHCPHeader(AppData, DHCP_NAK, &RemoteMACAddress, TransactionID); \r
- }\r
+ sizeof(uip_ipaddr_t), &GatewayIPAddress);\r
+\r
+ /* Send the DHCP OFFER packet */\r
+ uip_poll_conn(BroadcastConnection);\r
+ memcpy(&uip_udp_conn->ripaddr, &uip_broadcast_addr, sizeof(uip_ipaddr_t));\r
+ uip_udp_send(AppDataSize);\r
+\r
+ break;\r
+ case DHCP_REQUEST:\r
+ /* Check to see if the requested IP address has already been leased to a client */\r
+ if (!(DHCPServerApp_CheckIfIPLeased(&PreferredClientIP)))\r
+ {\r
+ /* Create a new DHCP ACK packet to accept the IP address lease */ \r
+ AppDataSize += DHCPServerApp_FillDHCPHeader(AppData, DHCP_ACK, &RemoteMACAddress, &PreferredClientIP, TransactionID);\r
+\r
+ /* Add network mask and router information to the list of DHCP ACK packet options */\r
+ AppDataSize += DHCPCommon_SetOption(AppData->Options, DHCP_OPTION_SUBNET_MASK,\r
+ sizeof(uip_ipaddr_t), &Netmask);\r
+ AppDataSize += DHCPCommon_SetOption(AppData->Options, DHCP_OPTION_ROUTER,\r
+ sizeof(uip_ipaddr_t), &GatewayIPAddress);\r
+\r
+ /* Mark the requested IP as leased to a client */\r
+ DHCPServerApp_LeaseIP(&PreferredClientIP);\r
+ }\r
+ else\r
+ {\r
+ /* Create a new DHCP NAK packet to reject the requested allocation */\r
+ AppDataSize += DHCPServerApp_FillDHCPHeader(AppData, DHCP_NAK, &RemoteMACAddress, &uip_all_zeroes_addr, TransactionID);\r
+ }\r
+ \r
+ /* Send the DHCP ACK or NAK packet */\r
+ uip_poll_conn(BroadcastConnection);\r
+ memcpy(&uip_udp_conn->ripaddr, &uip_broadcast_addr, sizeof(uip_ipaddr_t));\r
+ uip_udp_send(AppDataSize);\r