Ethernet
Ethernet copied to clipboard
Support NTP option 42 in DHCP (as well as other options, possibly)
Hi,
I'm likely sure that i'll be blasted by a RTFM but... i was not able to find out why the Ethernet class is not supporting the NTP/Time options (eg option 42) to allow the NTP setup in a dynamic way. I believe that the approach is KISS and memory footprint, but i would like to understand it in detail.
Footnote: In worst case (option will be not supported), I believe that some lines should detail in README why options A-B-C are not supported... so that's why i'm opening an issue and not a port in the forum.
This was already referenced in the forum quite time ago, with a way to take out only the first NTP entry. https://forum.arduino.cc/t/ethernet-shield-get-ntp-server-via-dhcp/256676/2 with a working workaround:
- comment out option 42: https://github.com/arduino-libraries/Ethernet/blob/75a3c37b5e513305b82e926ca6a4f8190f536c9d/src/Dhcp.h#L97
- add the following snippet (i would say nearby https://github.com/arduino-libraries/Ethernet/blob/master/src/Dhcp.cpp#L327)
case ntpServers :
opt_len = _dhcpUdpSocket.read();
_dhcpUdpSocket.read(_dhcpNtpServerIp, 4);
for (int i = 0; i < opt_len-4; i++)
{
_dhcpUdpSocket.read();
}
break;
Thanks!