Hello,
I am actually reading the FreeRTOS DHCP implementation and I found something that bother me.
In FreeRTOS_DHCP.c, line “~693” you have :
~~~
case dhcpGATEWAY
OPTIONCODE :
if( ucLength == sizeof( uint32_t ) )
{
/* ulProcessed is not incremented in this case
because the gateway is not essential. */
xNetworkAddressing.ulGatewayAddress = ulParameter;
}
break;
~~~
In the code, if we receive the dhcpGATEWAY
OPTIONCODE (=3), and the size of the parameter (ucLength) is 4 bytes, we take the parameter and use it as the gateway address.
In the RFC 2132 (https://tools.ietf.org/html/rfc2132) which defines the DHCP option format, you can read :
***3.5. Router Option
The router option specifies a list of IP addresses for routers on the
client’s subnet. Routers SHOULD be listed in order of preference.
The code for the router option is 3. The minimum length for the
router option is 4 octets, and the length MUST always be a multiple
of 4.
Code Len Address 1Address 2
+—–+—–+—–+—–+—–+—–+—–+—–+–
| 3 | n | a1 | a2 | a3 | a4 | a1 | a2 | …
+—–+—–+—–+—–+—–+—–+—–+—–+–*
As you can see the lenght can be different from 4.
In your implementation, in the case (probably a very rare one) where the router option contains more than one IP address, it should be more “clever” to take at least the first one ?
Without the gateway address, the device will not be able to connect to internet.
Thank for your time.
PS : Sorry for my bad English