Fix DHCPClient init code in the Webserver project writing to the incorrect applicatio...
[pub/USBasp.git] / Projects / Webserver / Lib / DHCPClientApp.c
index 2097062..0e51d57 100644 (file)
@@ -43,17 +43,19 @@ struct timer DHCPTimer;
 /** Initialization function for the DHCP client. */\r
 void DHCPClientApp_Init(void)\r
 {\r
-       uip_udp_appstate_t* const AppState = &uip_udp_conn->appstate;\r
-       \r
-       /* Create a new UDP connection to the DHCP server port for the DHCP solicitation */\r
+       /* Create an IP address to the broadcast network address */\r
        uip_ipaddr_t DHCPServerIPAddress;\r
        uip_ipaddr(&DHCPServerIPAddress, 255, 255, 255, 255);\r
-       AppState->DHCPClient.Connection = uip_udp_new(&DHCPServerIPAddress, HTONS(DHCPC_SERVER_PORT));\r
+\r
+       /* Create a new UDP connection to the DHCP server port for the DHCP solicitation */\r
+       struct uip_udp_conn* Connection = uip_udp_new(&DHCPServerIPAddress, HTONS(DHCPC_SERVER_PORT));\r
        \r
        /* If the connection was successfully created, bind it to the local DHCP client port */\r
-       if(AppState->DHCPClient.Connection != NULL)\r
+       if (Connection != NULL)\r
        {\r
-               uip_udp_bind(AppState->DHCPClient.Connection, HTONS(DHCPC_CLIENT_PORT));\r
+               uip_udp_appstate_t* const AppState = &Connection->appstate;\r
+\r
+               uip_udp_bind(Connection, HTONS(DHCPC_CLIENT_PORT));\r
                AppState->DHCPClient.CurrentState = DHCP_STATE_SendDiscover;\r
        }\r
 \r
@@ -188,13 +190,13 @@ uint16_t DHCPClientApp_FillDHCPHeader(DHCP_Header_t* DHCPHeader, uint8_t DHCPMes
        DHCPHeader->TransactionID         = DHCP_TRANSACTION_ID;\r
        DHCPHeader->ElapsedSeconds        = 0;\r
        DHCPHeader->Flags                 = HTONS(BOOTP_BROADCAST);\r
-       memcpy(&DHCPHeader->ClientIP, &uip_hostaddr, sizeof(uip_ipaddr_t));\r
-       memcpy(&DHCPHeader->YourIP, &AppState->DHCPClient.DHCPOffer_Data.AllocatedIP, sizeof(uip_ipaddr_t));\r
-       memcpy(&DHCPHeader->NextServerIP, &AppState->DHCPClient.DHCPOffer_Data.ServerIP, sizeof(uip_ipaddr_t));\r
+       memcpy(&DHCPHeader->ClientIP,     &uip_hostaddr,        sizeof(uip_ipaddr_t));\r
+       memcpy(&DHCPHeader->YourIP,       &AppState->DHCPClient.DHCPOffer_Data.AllocatedIP, sizeof(uip_ipaddr_t));\r
+       memcpy(&DHCPHeader->NextServerIP, &AppState->DHCPClient.DHCPOffer_Data.ServerIP,    sizeof(uip_ipaddr_t));\r
        memcpy(&DHCPHeader->ClientHardwareAddress, &MACAddress, sizeof(struct uip_eth_addr));\r
        DHCPHeader->Cookie                = DHCP_MAGIC_COOKIE;\r
        \r
-       /* Add a DHCP type and terminator options to the start of the DHCP options field */\r
+       /* Add a DHCP message type and terminator options to the start of the DHCP options field */\r
        DHCPHeader->Options[0]            = DHCP_OPTION_MSG_TYPE;\r
        DHCPHeader->Options[1]            = 1;\r
        DHCPHeader->Options[2]            = DHCPMessageType;\r