dns_client.c
Go to the documentation of this file.
1 /**
2  * @file dns_client.c
3  * @brief DNS client (Domain Name System)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL DNS_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "dns/dns_cache.h"
37 #include "dns/dns_client.h"
38 #include "dns/dns_common.h"
39 #include "dns/dns_debug.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (DNS_CLIENT_SUPPORT == ENABLED)
44 
45 
46 /**
47  * @brief Resolve a host name using DNS
48  * @param[in] interface Underlying network interface
49  * @param[in] name Name of the host to be resolved
50  * @param[in] type Host type (IPv4 or IPv6)
51  * @param[out] ipAddr IP address corresponding to the specified host name
52  **/
53 
56 {
57  error_t error;
58  DnsCacheEntry *entry;
59 
60 #if (NET_RTOS_SUPPORT == ENABLED)
61  systime_t delay;
62 
63  //Debug message
64  TRACE_INFO("Resolving host name %s (DNS resolver)...\r\n", name);
65 #endif
66 
67  //Get exclusive access
69 
70  //Search the DNS cache for the specified host name
71  entry = dnsFindEntry(interface, name, type, HOST_NAME_RESOLVER_DNS);
72 
73  //Check whether a matching entry has been found
74  if(entry != NULL)
75  {
76  //Host name already resolved?
77  if(entry->state == DNS_STATE_RESOLVED ||
78  entry->state == DNS_STATE_PERMANENT)
79  {
80  //Return the corresponding IP address
81  *ipAddr = entry->ipAddr;
82  //Successful host name resolution
83  error = NO_ERROR;
84  }
85  else
86  {
87  //Host name resolution is in progress
88  error = ERROR_IN_PROGRESS;
89  }
90  }
91  else
92  {
93  //If no entry exists, then create a new one
94  entry = dnsCreateEntry();
95 
96  //Record the host name whose IP address is unknown
97  osStrcpy(entry->name, name);
98 
99  //Initialize DNS cache entry
100  entry->type = type;
102  entry->interface = interface;
103 
104  //Select primary DNS server
105  entry->dnsServerIndex = 0;
106 
107  //Get an ephemeral port number
108  entry->port = udpGetDynamicPort();
109 
110  //An identifier is used by the DNS client to match replies with
111  //corresponding requests
112  entry->id = (uint16_t) netGenerateRand();
113 
114  //Callback function to be called when a DNS response is received
115  error = udpAttachRxCallback(interface, entry->port, dnsProcessResponse,
116  NULL);
117 
118  //Check status code
119  if(!error)
120  {
121  //Initialize retransmission counter
123  //Send DNS query
124  error = dnsSendQuery(entry);
125 
126  //DNS message successfully sent?
127  if(!error)
128  {
129  //Save the time at which the query message was sent
130  entry->timestamp = osGetSystemTime();
131  //Set timeout value
134  //Decrement retransmission counter
135  entry->retransmitCount--;
136 
137  //Switch state
138  entry->state = DNS_STATE_IN_PROGRESS;
139  //Host name resolution is in progress
140  error = ERROR_IN_PROGRESS;
141  }
142  else
143  {
144  //Unregister callback function
145  udpDetachRxCallback(interface, entry->port);
146  }
147  }
148  }
149 
150  //Release exclusive access
152 
153 #if (NET_RTOS_SUPPORT == ENABLED)
154  //Set default polling interval
156 
157  //Wait the host name resolution to complete
158  while(error == ERROR_IN_PROGRESS)
159  {
160  //Wait until the next polling period
161  osDelayTask(delay);
162 
163  //Get exclusive access
165 
166  //Search the DNS cache for the specified host name
167  entry = dnsFindEntry(interface, name, type, HOST_NAME_RESOLVER_DNS);
168 
169  //Check whether a matching entry has been found
170  if(entry != NULL)
171  {
172  //Host name successfully resolved?
173  if(entry->state == DNS_STATE_RESOLVED)
174  {
175  //Return the corresponding IP address
176  *ipAddr = entry->ipAddr;
177  //Successful host name resolution
178  error = NO_ERROR;
179  }
180  }
181  else
182  {
183  //Host name resolution failed
184  error = ERROR_FAILURE;
185  }
186 
187  //Release exclusive access
189 
190  //Backoff support for less aggressive polling
191  delay = MIN(delay * 2, DNS_CACHE_MAX_POLLING_INTERVAL);
192  }
193 
194  //Check status code
195  if(error)
196  {
197  //Failed to resolve host name
198  TRACE_INFO("Host name resolution failed!\r\n");
199  }
200  else
201  {
202  //Successful host name resolution
203  TRACE_INFO("Host name resolved to %s...\r\n", ipAddrToString(ipAddr, NULL));
204  }
205 #endif
206 
207  //Return status code
208  return error;
209 }
210 
211 
212 /**
213  * @brief Send a DNS query message
214  * @param[in] entry Pointer to a valid DNS cache entry
215  * @return Error code
216  **/
217 
219 {
220  error_t error;
221  size_t length;
222  size_t offset;
223  NetBuffer *buffer;
225  DnsQuestion *dnsQuestion;
227  NetTxAncillary ancillary;
228 
229 #if (IPV4_SUPPORT == ENABLED)
230  //An IPv4 address is expected?
231  if(entry->type == HOST_TYPE_IPV4)
232  {
233  //Point to the IPv4 context
234  Ipv4Context *ipv4Context = &entry->interface->ipv4Context;
235 
236  //Select the relevant DNS server
237  while(1)
238  {
239  //Out of range index?
241  return ERROR_NO_DNS_SERVER;
242 
243  //Copy the address of the DNS server
244  destIpAddr.length = sizeof(Ipv4Addr);
245  destIpAddr.ipv4Addr = ipv4Context->dnsServerList[entry->dnsServerIndex];
246 
247  //Make sure the IP address is valid
248  if(destIpAddr.ipv4Addr != IPV4_UNSPECIFIED_ADDR)
249  break;
250 
251  //Select the next DNS server in the list
252  entry->dnsServerIndex++;
253  }
254  }
255  else
256 #endif
257 #if (IPV6_SUPPORT == ENABLED)
258  //An IPv6 address is expected?
259  if(entry->type == HOST_TYPE_IPV6)
260  {
261  //Point to the IPv6 context
262  Ipv6Context *ipv6Context = &entry->interface->ipv6Context;
263 
264  //Select the relevant DNS server
265  while(1)
266  {
267  //Out of range index?
269  return ERROR_NO_DNS_SERVER;
270 
271  //Copy the address of the DNS server
272  destIpAddr.length = sizeof(Ipv6Addr);
273  destIpAddr.ipv6Addr = ipv6Context->dnsServerList[entry->dnsServerIndex];
274 
275  //Make sure the IP address is valid
277  break;
278 
279  //Select the next DNS server in the list
280  entry->dnsServerIndex++;
281  }
282  }
283  else
284 #endif
285  //Invalid host type?
286  {
287  //Report an error
289  }
290 
291  //Allocate a memory buffer to hold the DNS query message
292  buffer = udpAllocBuffer(DNS_MESSAGE_MAX_SIZE, &offset);
293  //Failed to allocate buffer?
294  if(buffer == NULL)
295  return ERROR_OUT_OF_MEMORY;
296 
297  //Point to the DNS header
298  message = netBufferAt(buffer, offset, 0);
299 
300  //Format DNS query message
301  message->id = htons(entry->id);
302  message->qr = 0;
303  message->opcode = DNS_OPCODE_QUERY;
304  message->aa = 0;
305  message->tc = 0;
306  message->rd = 1;
307  message->ra = 0;
308  message->z = 0;
309  message->rcode = DNS_RCODE_NOERROR;
310 
311  //The DNS query contains one question
312  message->qdcount = HTONS(1);
313  message->ancount = 0;
314  message->nscount = 0;
315  message->arcount = 0;
316 
317  //Length of the DNS query message
318  length = sizeof(DnsHeader);
319 
320  //Encode the host name using the DNS name notation
321  length += dnsEncodeName(entry->name, message->questions);
322 
323  //Point to the corresponding question structure
324  dnsQuestion = DNS_GET_QUESTION(message, length);
325 
326 #if (IPV4_SUPPORT == ENABLED)
327  //An IPv4 address is expected?
328  if(entry->type == HOST_TYPE_IPV4)
329  {
330  //Fill in question structure
331  dnsQuestion->qtype = HTONS(DNS_RR_TYPE_A);
332  dnsQuestion->qclass = HTONS(DNS_RR_CLASS_IN);
333  }
334 #endif
335 #if (IPV6_SUPPORT == ENABLED)
336  //An IPv6 address is expected?
337  if(entry->type == HOST_TYPE_IPV6)
338  {
339  //Fill in question structure
340  dnsQuestion->qtype = HTONS(DNS_RR_TYPE_AAAA);
341  dnsQuestion->qclass = HTONS(DNS_RR_CLASS_IN);
342  }
343 #endif
344 
345  //Update the length of the DNS query message
346  length += sizeof(DnsQuestion);
347 
348  //Adjust the length of the multi-part buffer
349  netBufferSetLength(buffer, offset + length);
350 
351  //Debug message
352  TRACE_INFO("Sending DNS message (%" PRIuSIZE " bytes)...\r\n", length);
353  //Dump message
355 
356  //Additional options can be passed to the stack along with the packet
357  ancillary = NET_DEFAULT_TX_ANCILLARY;
358 
359  //Send DNS query message
360  error = udpSendBuffer(entry->interface, NULL, entry->port, &destIpAddr,
361  DNS_PORT, buffer, offset, &ancillary);
362 
363  //Free previously allocated memory
364  netBufferFree(buffer);
365 
366  //Return status code
367  return error;
368 }
369 
370 
371 /**
372  * @brief Process incoming DNS response message
373  * @param[in] interface Underlying network interface
374  * @param[in] pseudoHeader UDP pseudo header
375  * @param[in] udpHeader UDP header
376  * @param[in] buffer Multi-part buffer containing the incoming DNS message
377  * @param[in] offset Offset to the first byte of the DNS message
378  * @param[in] ancillary Additional options passed to the stack along with
379  * the packet
380  * @param[in] param Callback function parameter (not used)
381  **/
382 
384  const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
385  const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary,
386  void *param)
387 {
388  uint_t i;
389  uint_t j;
390  size_t pos;
391  size_t length;
393  DnsQuestion *question;
394  DnsResourceRecord *record;
395  DnsCacheEntry *entry;
396 
397  //Retrieve the length of the DNS message
398  length = netBufferGetLength(buffer) - offset;
399 
400  //Malformed DNS message?
401  if(length < sizeof(DnsHeader))
402  return;
403 
404  //Point to the DNS message header
405  message = netBufferAt(buffer, offset, length);
406  //Sanity check
407  if(message == NULL)
408  return;
409 
410  //Debug message
411  TRACE_INFO("DNS message received (%" PRIuSIZE " bytes)...\r\n", length);
412  //Dump message
414 
415  //Check message type
416  if(!message->qr)
417  return;
418 
419  //The DNS message shall contain one question
420  if(ntohs(message->qdcount) != 1)
421  return;
422 
423  //Loop through DNS cache entries
424  for(i = 0; i < DNS_CACHE_SIZE; i++)
425  {
426  //Point to the current entry
427  entry = &dnsCache[i];
428 
429  //DNS name resolution in progress?
430  if(entry->state == DNS_STATE_IN_PROGRESS &&
432  {
433  //Check destination port number
434  if(entry->port == ntohs(udpHeader->destPort))
435  {
436  //Compare identifier against the expected one
437  if(ntohs(message->id) != entry->id)
438  break;
439 
440  //Point to the first question
441  pos = sizeof(DnsHeader);
442  //Parse domain name
443  pos = dnsParseName(message, length, pos, NULL, 0);
444 
445  //Invalid name?
446  if(!pos)
447  break;
448  //Malformed DNS message?
449  if((pos + sizeof(DnsQuestion)) > length)
450  break;
451 
452  //Compare domain name
453  if(dnsCompareName(message, length, sizeof(DnsHeader), entry->name, 0))
454  break;
455 
456  //Point to the corresponding entry
457  question = DNS_GET_QUESTION(message, pos);
458 
459  //Check the class of the query
460  if(ntohs(question->qclass) != DNS_RR_CLASS_IN)
461  break;
462 
463  //Check the type of the query
464  if(entry->type == HOST_TYPE_IPV4 &&
465  ntohs(question->qtype) != DNS_RR_TYPE_A)
466  {
467  break;
468  }
469 
470  if(entry->type == HOST_TYPE_IPV6 &&
471  ntohs(question->qtype) != DNS_RR_TYPE_AAAA)
472  {
473  break;
474  }
475 
476  //Check response code
477  if(message->rcode != DNS_RCODE_NOERROR)
478  {
479  //Select the next DNS server
480  dnsSelectNextServer(entry);
481  //Exit immediately
482  break;
483  }
484 
485  //Point to the first answer
486  pos += sizeof(DnsQuestion);
487 
488  //Parse answer resource records
489  for(j = 0; j < ntohs(message->ancount); j++)
490  {
491  //Parse domain name
492  pos = dnsParseName(message, length, pos, NULL, 0);
493  //Invalid name?
494  if(!pos)
495  break;
496 
497  //Point to the associated resource record
498  record = DNS_GET_RESOURCE_RECORD(message, pos);
499  //Point to the resource data
500  pos += sizeof(DnsResourceRecord);
501 
502  //Make sure the resource record is valid
503  if(pos > length)
504  break;
505  if((pos + ntohs(record->rdlength)) > length)
506  break;
507 
508 #if (IPV4_SUPPORT == ENABLED)
509  //IPv4 address expected?
510  if(entry->type == HOST_TYPE_IPV4)
511  {
512  //A resource record found?
513  if(ntohs(record->rtype) == DNS_RR_TYPE_A &&
514  ntohs(record->rdlength) == sizeof(Ipv4Addr))
515  {
516  //Copy the IPv4 address
517  entry->ipAddr.length = sizeof(Ipv4Addr);
518  ipv4CopyAddr(&entry->ipAddr.ipv4Addr, record->rdata);
519 
520  //Save current time
521  entry->timestamp = osGetSystemTime();
522  //Save TTL value
523  entry->timeout = ntohl(record->ttl) * 1000;
524 
525  //Limit the lifetime of the DNS cache entries
526  if(entry->timeout >= DNS_MAX_LIFETIME)
527  entry->timeout = DNS_MAX_LIFETIME;
528  if(entry->timeout <= DNS_MIN_LIFETIME)
529  entry->timeout = DNS_MIN_LIFETIME;
530 
531  //Unregister UDP callback function
532  udpDetachRxCallback(interface, entry->port);
533  //Host name successfully resolved
534  entry->state = DNS_STATE_RESOLVED;
535  //Exit immediately
536  break;
537  }
538  }
539 #endif
540 #if (IPV6_SUPPORT == ENABLED)
541  //IPv6 address expected?
542  if(entry->type == HOST_TYPE_IPV6)
543  {
544  //AAAA resource record found?
545  if(ntohs(record->rtype) == DNS_RR_TYPE_AAAA &&
546  ntohs(record->rdlength) == sizeof(Ipv6Addr))
547  {
548  //Copy the IPv6 address
549  entry->ipAddr.length = sizeof(Ipv6Addr);
550  ipv6CopyAddr(&entry->ipAddr.ipv6Addr, record->rdata);
551 
552  //Save current time
553  entry->timestamp = osGetSystemTime();
554  //Save TTL value
555  entry->timeout = ntohl(record->ttl) * 1000;
556 
557  //Limit the lifetime of the DNS cache entries
558  if(entry->timeout >= DNS_MAX_LIFETIME)
559  entry->timeout = DNS_MAX_LIFETIME;
560  if(entry->timeout <= DNS_MIN_LIFETIME)
561  entry->timeout = DNS_MIN_LIFETIME;
562 
563  //Unregister UDP callback function
564  udpDetachRxCallback(interface, entry->port);
565  //Host name successfully resolved
566  entry->state = DNS_STATE_RESOLVED;
567  //Exit immediately
568  break;
569  }
570  }
571 #endif
572  //Point to the next resource record
573  pos += ntohs(record->rdlength);
574  }
575 
576  //We are done
577  break;
578  }
579  }
580  }
581 }
582 
583 
584 /**
585  * @brief Select the next DNS server
586  * @param[in] entry Pointer to a valid DNS cache entry
587  **/
588 
590 {
591  error_t error;
592 
593 #if defined(DNS_SELECT_NEXT_SERVER_HOOK)
594  DNS_SELECT_NEXT_SERVER_HOOK(entry);
595 #endif
596 
597  //Select the next DNS server
598  entry->dnsServerIndex++;
599 
600  //An identifier is used by the DNS client to match replies with
601  //corresponding requests
602  entry->id = (uint16_t) netGenerateRand();
603 
604  //Initialize retransmission counter
606  //Send DNS query
607  error = dnsSendQuery(entry);
608 
609  //DNS message successfully sent?
610  if(!error)
611  {
612  //Save the time at which the query message was sent
613  entry->timestamp = osGetSystemTime();
614  //Set timeout value
616  //Decrement retransmission counter
617  entry->retransmitCount--;
618  }
619  else
620  {
621  //The entry should be deleted since name resolution has failed
622  dnsDeleteEntry(entry);
623  }
624 }
625 
626 #endif
error_t dnsSendQuery(DnsCacheEntry *entry)
Send a DNS query message.
Definition: dns_client.c:218
#define htons(value)
Definition: cpu_endian.h:413
HostType
Host types.
Definition: socket.h:215
@ DNS_STATE_PERMANENT
Definition: dns_cache.h:88
#define DNS_MAX_LIFETIME
Definition: dns_client.h:77
HostType type
IPv4 or IPv6 host?
Definition: dns_cache.h:99
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:71
@ HOST_NAME_RESOLVER_DNS
Definition: socket.h:229
#define netMutex
Definition: net_legacy.h:195
Ipv4Addr dnsServerList[IPV4_DNS_SERVER_LIST_SIZE]
DNS servers.
Definition: ipv4.h:434
IP network address.
Definition: ip.h:90
@ DNS_OPCODE_QUERY
Query.
Definition: dns_common.h:81
#define DNS_MIN_LIFETIME
Definition: dns_client.h:70
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t message[]
Definition: chap.h:154
systime_t timeout
Retransmission timeout.
Definition: dns_cache.h:108
char_t * ipAddrToString(const IpAddr *ipAddr, char_t *str)
Convert a binary IP address to a string representation.
Definition: ip.c:805
size_t dnsParseName(const DnsHeader *message, size_t length, size_t pos, char_t *dest, uint_t level)
Decode a domain name that uses the DNS name encoding.
Definition: dns_common.c:132
Ipv6Addr
Definition: ipv6.h:260
uint8_t type
Definition: coap_common.h:176
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
HostnameResolver protocol
Name resolution protocol.
Definition: dns_cache.h:100
#define ipv6CompAddr(ipAddr1, ipAddr2)
Definition: ipv6.h:127
@ DNS_RR_CLASS_IN
Internet.
Definition: dns_common.h:124
#define DNS_CLIENT_MAX_RETRIES
Definition: dns_client.h:49
char_t name[]
DnsHeader
Definition: dns_common.h:199
IpAddr ipAddr
IP address.
Definition: dns_cache.h:106
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:297
IPv6 context.
Definition: ipv6.h:496
@ ERROR_NO_DNS_SERVER
Definition: error.h:254
IPv4 context.
Definition: ipv4.h:426
uint32_t netGenerateRand(void)
Generate a random 32-bit value.
Definition: net_misc.c:922
@ HOST_TYPE_IPV6
Definition: socket.h:218
IP pseudo header.
Definition: ip.h:110
uint16_t id
Identifier used to match queries and responses.
Definition: dns_cache.h:104
@ DNS_RCODE_NOERROR
No error.
Definition: dns_common.h:95
@ ERROR_IN_PROGRESS
Definition: error.h:213
uint16_t port
Port number used by the resolver.
Definition: dns_cache.h:103
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
error_t dnsResolve(NetInterface *interface, const char_t *name, HostType type, IpAddr *ipAddr)
Resolve a host name using DNS.
Definition: dns_client.c:54
error_t
Error codes.
Definition: error.h:43
#define DNS_GET_QUESTION(message, offset)
Definition: dns_common.h:63
char_t name[DNS_MAX_NAME_LEN+1]
Domain name.
Definition: dns_cache.h:105
systime_t timestamp
Time stamp to manage entry lifetime.
Definition: dns_cache.h:107
#define DNS_GET_RESOURCE_RECORD(message, offset)
Definition: dns_common.h:64
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
Ipv6Addr dnsServerList[IPV6_DNS_SERVER_LIST_SIZE]
DNS servers.
Definition: ipv6.h:507
#define IPV4_DNS_SERVER_LIST_SIZE
Definition: ipv4.h:76
error_t udpDetachRxCallback(NetInterface *interface, uint16_t port)
Unregister user callback.
Definition: udp.c:1062
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
error_t udpAttachRxCallback(NetInterface *interface, uint16_t port, UdpRxCallback callback, void *param)
Register user callback.
Definition: udp.c:1021
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
Definition: net_mem.c:282
DNS cache entry.
Definition: dns_cache.h:97
@ DNS_RR_TYPE_A
Host address.
Definition: dns_common.h:137
error_t udpSendBuffer(NetInterface *interface, const IpAddr *srcIpAddr, uint16_t srcPort, const IpAddr *destIpAddr, uint16_t destPort, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send a UDP datagram.
Definition: udp.c:658
DnsCacheEntry * dnsCreateEntry(void)
Create a new entry in the DNS cache.
Definition: dns_cache.c:103
#define NetTxAncillary
Definition: net_misc.h:36
systime_t maxTimeout
Maximum retransmission timeout.
Definition: dns_cache.h:109
const Ipv6Addr IPV6_UNSPECIFIED_ADDR
Definition: ipv6.c:66
#define IPV6_DNS_SERVER_LIST_SIZE
Definition: ipv6.h:93
#define TRACE_INFO(...)
Definition: debug.h:95
#define DNS_PORT
Definition: dns_common.h:57
uint8_t length
Definition: tcp.h:368
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Definition: net_mem.c:297
void dnsDumpMessage(const DnsHeader *message, size_t length)
Dump DNS message for debugging purpose.
Definition: dns_debug.c:52
#define MIN(a, b)
Definition: os_port.h:63
NetBuffer * udpAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold a UDP packet.
Definition: udp.c:948
size_t length
Definition: ip.h:91
@ HOST_TYPE_IPV4
Definition: socket.h:217
uint16_t udpGetDynamicPort(void)
Get an ephemeral port number.
Definition: udp.c:81
size_t dnsEncodeName(const char_t *src, uint8_t *dest)
Encode a domain name using the DNS name notation.
Definition: dns_common.c:58
DNS client (Domain Name System)
UdpHeader
Definition: udp.h:85
#define DNS_CACHE_INIT_POLLING_INTERVAL
Definition: dns_cache.h:61
uint32_t systime_t
System time.
#define ntohs(value)
Definition: cpu_endian.h:421
char char_t
Definition: compiler_port.h:48
DnsCacheEntry * dnsFindEntry(NetInterface *interface, const char_t *name, HostType type, HostnameResolver protocol)
Search the DNS cache for a given domain name.
Definition: dns_cache.c:186
Ipv4Addr ipv4Addr
Definition: ip.h:95
DNS cache management.
#define ipv6CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv6.h:123
#define HTONS(value)
Definition: cpu_endian.h:410
@ DNS_STATE_IN_PROGRESS
Definition: dns_cache.h:86
NetInterface * interface
Underlying network interface.
Definition: dns_cache.h:101
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
#define DNS_CACHE_SIZE
Definition: dns_cache.h:47
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
@ DNS_STATE_RESOLVED
Definition: dns_cache.h:87
#define DNS_MESSAGE_MAX_SIZE
Definition: dns_common.h:45
error_t netBufferSetLength(NetBuffer *buffer, size_t length)
Adjust the length of a multi-part buffer.
Definition: net_mem.c:322
DnsQuestion
Definition: dns_common.h:210
#define DNS_CLIENT_INIT_TIMEOUT
Definition: dns_client.h:56
#define DNS_CLIENT_MAX_TIMEOUT
Definition: dns_client.h:63
void dnsDeleteEntry(DnsCacheEntry *entry)
Delete the specified DNS cache entry.
Definition: dns_cache.c:152
#define ipv4CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv4.h:155
void osDelayTask(systime_t delay)
Delay routine.
void * netBufferAt(const NetBuffer *buffer, size_t offset, size_t length)
Returns a pointer to a data segment.
Definition: net_mem.c:418
Ipv4Addr ipAddr
Definition: ipcp.h:105
DnsCacheEntry dnsCache[DNS_CACHE_SIZE]
Definition: dns_cache.c:51
DnsState state
Entry state.
Definition: dns_cache.h:98
void dnsSelectNextServer(DnsCacheEntry *entry)
Select the next DNS server.
Definition: dns_client.c:589
uint_t dnsServerIndex
This parameter selects between the primary and secondary DNS server.
Definition: dns_cache.h:102
Ipv6Addr ipv6Addr
Definition: ip.h:98
uint_t retransmitCount
Retransmission counter.
Definition: dns_cache.h:110
#define PRIuSIZE
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
DnsResourceRecord
Definition: dns_common.h:224
@ DNS_RR_TYPE_AAAA
IPv6 address.
Definition: dns_common.h:147
Data logging functions for debugging purpose (DNS)
Common DNS routines.
int_t dnsCompareName(const DnsHeader *message, size_t length, size_t pos, const char_t *name, uint_t level)
Compare domain names.
Definition: dns_common.c:242
#define osStrcpy(s1, s2)
Definition: os_port.h:207
#define DNS_CACHE_MAX_POLLING_INTERVAL
Definition: dns_cache.h:68
void dnsProcessResponse(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary, void *param)
Process incoming DNS response message.
Definition: dns_client.c:383
#define ntohl(value)
Definition: cpu_endian.h:422
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
#define IPV4_UNSPECIFIED_ADDR
Definition: ipv4.h:117
systime_t osGetSystemTime(void)
Retrieve system time.
Ipv4Addr destIpAddr
Definition: ipcp.h:80