A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
Diff: udp/ntp/ntpclientquery.c
- Revision:
- 116:60521b29e4c9
- Parent:
- 113:904b40231907
- Child:
- 124:6e558721ec1c
--- a/udp/ntp/ntpclientquery.c Wed Jan 23 15:42:35 2019 +0000 +++ b/udp/ntp/ntpclientquery.c Fri Jan 25 17:37:51 2019 +0000 @@ -15,14 +15,7 @@ #include "ntpclient.h" #include "dns.h" #include "ip4.h" -#include "ar4.h" -#include "ar6.h" -#include "arp.h" -#include "eth.h" -#include "nr4.h" -#include "nr6.h" -#include "ip6addr.h" -#include "mac.h" +#include "resolve.h" #include "action.h" #define ONE_BILLION 1000000000ULL @@ -56,54 +49,6 @@ intervalTypeNtp = type; } -static bool resolve4(char* server, uint32_t* pIp) -{ - //Check if have IP, if not, then request it and stop - Nr4NameToIp(server, pIp); - if (!*pIp) - { - Nr4MakeRequestForIpFromName(server); //The request is only repeated if made after a freeze time - call as often as you want. - return false; - } - - //Check if have MAC and, if not, request it and stop - char mac[6]; - Ar4IpToMac(*pIp, mac); - if (MacIsEmpty(mac)) - { - Ar4MakeRequestForMacFromIp(*pIp); //The request is only repeated if made after a freeze time - call as often as you want. - return false; - } - - return true; -} -static bool resolve6(char* server, char* ip) -{ - //Check if have IP, if not, then request it and stop - Nr6NameToIp(server, ip); - if (Ip6AddressIsEmpty(ip)) - { - Nr6MakeRequestForIpFromName(server); //The request is only repeated if made after a freeze time - call as often as you want. - return false; - } - - //Check if have MAC and, if not, request it and stop - char mac[6]; - Ar6IpToMac(ip, mac); - if (MacIsEmpty(mac)) - { - Ar6MakeRequestForMacFromIp(ip); //The request is only repeated if made after a freeze time - call as often as you want. - return false; - } - - return true; -} -static bool haveIpAndMac(int type) -{ - if (type == IPV4) return resolve4(NtpClientQueryServerName, &NtpClientQueryServerIp4); - else if (type == IPV6) return resolve6(NtpClientQueryServerName, NtpClientQueryServerIp6); - else return false; -} void writeRequest(void* pPacket, int* pSize) { struct NtpHeader* pHeader = (struct NtpHeader*)pPacket; @@ -135,7 +80,7 @@ if (intervalCompleteNtp()) //Wait for the time out { bool isMulticast = NtpClientQueryServerName[0] == '*'; - if (isMulticast || haveIpAndMac(type)) + if (isMulticast || Resolve(NtpClientQueryServerName, type, &NtpClientQueryServerIp4, NtpClientQueryServerIp6)) { ClkGovIsReceivingTime = false; NtpClientQueryStartInterval(NTP_QUERY_INTERVAL_RETRY);