Skip to content

Commit d7abafe

Browse files
davefiddesearlephilhower
authored andcommitted
Remove duplication and incompatible declarations in sntp.h (#6610)
This removes definitions relating to the built-in SNTP client that are LwIP v1 specific. Instead of duplicating these pull in the LwIP header that correspond to the required functions depending on the version of the stack being used. Without this fix calls to sntp_getserver() work but return invalid data and can lead to stack exhaustion. Update the NTP-TZ-DST example to use the Arduino sntp.h header rather than duplicate the conditional checks to use the LwIP header. Tests: - Build against a simple SNTP API demonstratin app and all LwIP configurations. Verify that the app runs for an extended period and that the expected results are obtained.
1 parent c55f49b commit d7abafe

File tree

2 files changed

+3
-50
lines changed

2 files changed

+3
-50
lines changed

libraries/esp8266/examples/NTP-TZ-DST/NTP-TZ-DST.ino

+1-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@
5151
#include <time.h> // time() ctime()
5252
#include <sys/time.h> // struct timeval
5353

54-
#if LWIP_VERSION_MAJOR == 1
55-
#include <lwip/sntp.h> // sntp_servermode_dhcp()
56-
#else
57-
#include <lwip/apps/sntp.h> // sntp_servermode_dhcp()
58-
#endif
54+
#include <sntp.h> // sntp_servermode_dhcp()
5955

6056
// for testing purpose:
6157
extern "C" int clock_gettime(clockid_t unused, struct timespec *tp);

tools/sdk/include/sntp.h

+2-45
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55

66
#include "lwip/init.h"
77
#include "lwip/ip_addr.h"
8-
98
#if LWIP_VERSION_MAJOR == 1
10-
#define ipv4_addr_t ip_addr_t
9+
#include "lwip/sntp.h"
1110
#else
12-
typedef struct ip4_addr ipv4_addr_t;
11+
#include "lwip/apps/sntp.h"
1312
#endif
1413

1514
#ifdef __cplusplus
@@ -32,48 +31,6 @@ sint8 sntp_get_timezone(void);
3231
* SNTP set time_zone (default GMT + 8)
3332
*/
3433
bool sntp_set_timezone(sint8 timezone);
35-
/**
36-
* Initialize this module.
37-
* Send out request instantly or after SNTP_STARTUP_DELAY(_FUNC).
38-
*/
39-
void sntp_init(void);
40-
/**
41-
* Stop this module.
42-
*/
43-
void sntp_stop(void);
44-
/**
45-
* Initialize one of the NTP servers by IP address
46-
*
47-
* @param numdns the index of the NTP server to set must be < SNTP_MAX_SERVERS
48-
* @param dnsserver IP address of the NTP server to set
49-
*/
50-
void sntp_setserver(unsigned char idx, ipv4_addr_t *addr);
51-
/**
52-
* Obtain one of the currently configured by IP address (or DHCP) NTP servers
53-
*
54-
* @param numdns the index of the NTP server
55-
* @return IP address of the indexed NTP server or "ipv4_addr_any" if the NTP
56-
* server has not been configured by address (or at all).
57-
*/
58-
ipv4_addr_t sntp_getserver(unsigned char idx);
59-
/**
60-
* Initialize one of the NTP servers by name
61-
*
62-
* @param numdns the index of the NTP server to set must be < SNTP_MAX_SERVERS,now sdk support SNTP_MAX_SERVERS = 3
63-
* @param dnsserver DNS name of the NTP server to set, to be resolved at contact time
64-
*/
65-
void sntp_setservername(unsigned char idx, char *server);
66-
/**
67-
* Obtain one of the currently configured by name NTP servers.
68-
*
69-
* @param numdns the index of the NTP server
70-
* @return IP address of the indexed NTP server or NULL if the NTP
71-
* server has not been configured by name (or at all)
72-
*/
73-
char *sntp_getservername(unsigned char idx);
74-
75-
#define sntp_servermode_dhcp(x)
76-
7734

7835
#ifdef __cplusplus
7936
}

0 commit comments

Comments
 (0)