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.0
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);
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  //Return status code
366  return error;
367 }
368 
369 
370 /**
371  * @brief Process incoming DNS response message
372  * @param[in] interface Underlying network interface
373  * @param[in] pseudoHeader UDP pseudo header
374  * @param[in] udpHeader UDP header
375  * @param[in] buffer Multi-part buffer containing the incoming DNS message
376  * @param[in] offset Offset to the first byte of the DNS message
377  * @param[in] ancillary Additional options passed to the stack along with
378  * the packet
379  * @param[in] param Callback function parameter (not used)
380  **/
381 
383  const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
384  const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary,
385  void *param)
386 {
387  uint_t i;
388  uint_t j;
389  size_t pos;
390  size_t length;
392  DnsQuestion *question;
393  DnsResourceRecord *record;
394  DnsCacheEntry *entry;
395 
396  //Retrieve the length of the DNS message
397  length = netBufferGetLength(buffer) - offset;
398 
399  //Ensure the DNS message is valid
400  if(length < sizeof(DnsHeader))
401  return;
403  return;
404 
405  //Point to the DNS message header
406  message = netBufferAt(buffer, offset);
407  //Sanity check
408  if(message == NULL)
409  return;
410 
411  //Debug message
412  TRACE_INFO("DNS message received (%" PRIuSIZE " bytes)...\r\n", length);
413  //Dump message
415 
416  //Check message type
417  if(!message->qr)
418  return;
419 
420  //The DNS message shall contain one question
421  if(ntohs(message->qdcount) != 1)
422  return;
423 
424  //Loop through DNS cache entries
425  for(i = 0; i < DNS_CACHE_SIZE; i++)
426  {
427  //Point to the current entry
428  entry = &dnsCache[i];
429 
430  //DNS name resolution in progress?
431  if(entry->state == DNS_STATE_IN_PROGRESS &&
433  {
434  //Check destination port number
435  if(entry->port == ntohs(udpHeader->destPort))
436  {
437  //Compare identifier against the expected one
438  if(ntohs(message->id) != entry->id)
439  break;
440 
441  //Point to the first question
442  pos = sizeof(DnsHeader);
443  //Parse domain name
444  pos = dnsParseName(message, length, pos, NULL, 0);
445 
446  //Invalid name?
447  if(!pos)
448  break;
449  //Malformed DNS message?
450  if((pos + sizeof(DnsQuestion)) > length)
451  break;
452 
453  //Compare domain name
454  if(dnsCompareName(message, length, sizeof(DnsHeader), entry->name, 0))
455  break;
456 
457  //Point to the corresponding entry
458  question = DNS_GET_QUESTION(message, pos);
459 
460  //Check the class of the query
461  if(ntohs(question->qclass) != DNS_RR_CLASS_IN)
462  break;
463 
464  //Check the type of the query
465  if(entry->type == HOST_TYPE_IPV4 &&
466  ntohs(question->qtype) != DNS_RR_TYPE_A)
467  {
468  break;
469  }
470 
471  if(entry->type == HOST_TYPE_IPV6 &&
472  ntohs(question->qtype) != DNS_RR_TYPE_AAAA)
473  {
474  break;
475  }
476 
477  //Check response code
478  if(message->rcode != DNS_RCODE_NOERROR)
479  {
480  //Select the next DNS server
481  dnsSelectNextServer(entry);
482  //Exit immediately
483  break;
484  }
485 
486  //Point to the first answer
487  pos += sizeof(DnsQuestion);
488 
489  //Parse answer resource records
490  for(j = 0; j < ntohs(message->ancount); j++)
491  {
492  //Parse domain name
493  pos = dnsParseName(message, length, pos, NULL, 0);
494  //Invalid name?
495  if(!pos)
496  break;
497 
498  //Point to the associated resource record
499  record = DNS_GET_RESOURCE_RECORD(message, pos);
500  //Point to the resource data
501  pos += sizeof(DnsResourceRecord);
502 
503  //Make sure the resource record is valid
504  if(pos > length)
505  break;
506  if((pos + ntohs(record->rdlength)) > length)
507  break;
508 
509 #if (IPV4_SUPPORT == ENABLED)
510  //IPv4 address expected?
511  if(entry->type == HOST_TYPE_IPV4)
512  {
513  //A resource record found?
514  if(ntohs(record->rtype) == DNS_RR_TYPE_A &&
515  ntohs(record->rdlength) == sizeof(Ipv4Addr))
516  {
517  //Copy the IPv4 address
518  entry->ipAddr.length = sizeof(Ipv4Addr);
519  ipv4CopyAddr(&entry->ipAddr.ipv4Addr, record->rdata);
520 
521  //Save current time
522  entry->timestamp = osGetSystemTime();
523  //Save TTL value
524  entry->timeout = ntohl(record->ttl) * 1000;
525 
526  //Limit the lifetime of the DNS cache entries
527  if(entry->timeout >= DNS_MAX_LIFETIME)
528  entry->timeout = DNS_MAX_LIFETIME;
529  if(entry->timeout <= DNS_MIN_LIFETIME)
530  entry->timeout = DNS_MIN_LIFETIME;
531 
532  //Unregister UDP callback function
533  udpDetachRxCallback(interface, entry->port);
534  //Host name successfully resolved
535  entry->state = DNS_STATE_RESOLVED;
536  //Exit immediately
537  break;
538  }
539  }
540 #endif
541 #if (IPV6_SUPPORT == ENABLED)
542  //IPv6 address expected?
543  if(entry->type == HOST_TYPE_IPV6)
544  {
545  //AAAA resource record found?
546  if(ntohs(record->rtype) == DNS_RR_TYPE_AAAA &&
547  ntohs(record->rdlength) == sizeof(Ipv6Addr))
548  {
549  //Copy the IPv6 address
550  entry->ipAddr.length = sizeof(Ipv6Addr);
551  ipv6CopyAddr(&entry->ipAddr.ipv6Addr, record->rdata);
552 
553  //Save current time
554  entry->timestamp = osGetSystemTime();
555  //Save TTL value
556  entry->timeout = ntohl(record->ttl) * 1000;
557 
558  //Limit the lifetime of the DNS cache entries
559  if(entry->timeout >= DNS_MAX_LIFETIME)
560  entry->timeout = DNS_MAX_LIFETIME;
561  if(entry->timeout <= DNS_MIN_LIFETIME)
562  entry->timeout = DNS_MIN_LIFETIME;
563 
564  //Unregister UDP callback function
565  udpDetachRxCallback(interface, entry->port);
566  //Host name successfully resolved
567  entry->state = DNS_STATE_RESOLVED;
568  //Exit immediately
569  break;
570  }
571  }
572 #endif
573  //Point to the next resource record
574  pos += ntohs(record->rdlength);
575  }
576 
577  //We are done
578  break;
579  }
580  }
581  }
582 }
583 
584 
585 /**
586  * @brief Select the next DNS server
587  * @param[in] entry Pointer to a valid DNS cache entry
588  **/
589 
591 {
592  error_t error;
593 
594 #if defined(DNS_SELECT_NEXT_SERVER_HOOK)
595  DNS_SELECT_NEXT_SERVER_HOOK(entry);
596 #endif
597 
598  //Select the next DNS server
599  entry->dnsServerIndex++;
600 
601  //An identifier is used by the DNS client to match replies with
602  //corresponding requests
603  entry->id = (uint16_t) netGenerateRand();
604 
605  //Initialize retransmission counter
607  //Send DNS query
608  error = dnsSendQuery(entry);
609 
610  //DNS message successfully sent?
611  if(!error)
612  {
613  //Save the time at which the query message was sent
614  entry->timestamp = osGetSystemTime();
615  //Set timeout value
617  //Decrement retransmission counter
618  entry->retransmitCount--;
619  }
620  else
621  {
622  //The entry should be deleted since name resolution has failed
623  dnsDeleteEntry(entry);
624  }
625 }
626 
627 #endif
uint8_t message[]
Definition: chap.h:154
uint8_t type
Definition: coap_common.h:176
unsigned int uint_t
Definition: compiler_port.h:50
#define PRIuSIZE
char char_t
Definition: compiler_port.h:48
#define HTONS(value)
Definition: cpu_endian.h:410
#define ntohl(value)
Definition: cpu_endian.h:422
#define htons(value)
Definition: cpu_endian.h:413
#define ntohs(value)
Definition: cpu_endian.h:421
Debugging facilities.
#define TRACE_INFO(...)
Definition: debug.h:95
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:187
DnsCacheEntry dnsCache[DNS_CACHE_SIZE]
Definition: dns_cache.c:52
void dnsDeleteEntry(DnsCacheEntry *entry)
Delete the specified DNS cache entry.
Definition: dns_cache.c:153
DnsCacheEntry * dnsCreateEntry(void)
Create a new entry in the DNS cache.
Definition: dns_cache.c:104
DNS cache management.
#define DNS_CACHE_SIZE
Definition: dns_cache.h:47
#define DNS_CACHE_INIT_POLLING_INTERVAL
Definition: dns_cache.h:61
@ DNS_STATE_RESOLVED
Definition: dns_cache.h:87
@ DNS_STATE_PERMANENT
Definition: dns_cache.h:88
@ DNS_STATE_IN_PROGRESS
Definition: dns_cache.h:86
#define DNS_CACHE_MAX_POLLING_INTERVAL
Definition: dns_cache.h:68
error_t dnsSendQuery(DnsCacheEntry *entry)
Send a DNS query message.
Definition: dns_client.c:218
error_t dnsResolve(NetInterface *interface, const char_t *name, HostType type, IpAddr *ipAddr)
Resolve a host name using DNS.
Definition: dns_client.c:54
void dnsSelectNextServer(DnsCacheEntry *entry)
Select the next DNS server.
Definition: dns_client.c:590
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:382
DNS client (Domain Name System)
#define DNS_CLIENT_MAX_TIMEOUT
Definition: dns_client.h:63
#define DNS_MAX_LIFETIME
Definition: dns_client.h:77
#define DNS_CLIENT_INIT_TIMEOUT
Definition: dns_client.h:56
#define DNS_CLIENT_MAX_RETRIES
Definition: dns_client.h:49
#define DNS_MIN_LIFETIME
Definition: dns_client.h:70
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
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
size_t dnsEncodeName(const char_t *src, uint8_t *dest)
Encode a domain name using the DNS name notation.
Definition: dns_common.c:58
Common DNS routines.
DnsHeader
Definition: dns_common.h:199
#define DNS_GET_RESOURCE_RECORD(message, offset)
Definition: dns_common.h:64
DnsResourceRecord
Definition: dns_common.h:224
#define DNS_GET_QUESTION(message, offset)
Definition: dns_common.h:63
@ DNS_RCODE_NOERROR
No error.
Definition: dns_common.h:95
#define DNS_MESSAGE_MAX_SIZE
Definition: dns_common.h:45
@ DNS_OPCODE_QUERY
Query.
Definition: dns_common.h:81
@ DNS_RR_TYPE_A
Host address.
Definition: dns_common.h:137
@ DNS_RR_TYPE_AAAA
IPv6 address.
Definition: dns_common.h:147
@ DNS_RR_CLASS_IN
Internet.
Definition: dns_common.h:124
DnsQuestion
Definition: dns_common.h:210
#define DNS_PORT
Definition: dns_common.h:57
void dnsDumpMessage(const DnsHeader *message, size_t length)
Dump DNS message for debugging purpose.
Definition: dns_debug.c:52
Data logging functions for debugging purpose (DNS)
error_t
Error codes.
Definition: error.h:43
@ ERROR_IN_PROGRESS
Definition: error.h:213
@ ERROR_NO_DNS_SERVER
Definition: error.h:253
@ NO_ERROR
Success.
Definition: error.h:44
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
char_t * ipAddrToString(const IpAddr *ipAddr, char_t *str)
Convert a binary IP address to a string representation.
Definition: ip.c:838
Ipv4Addr ipAddr
Definition: ipcp.h:105
Ipv4Addr destIpAddr
Definition: ipcp.h:80
#define ipv4CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv4.h:148
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:267
#define IPV4_UNSPECIFIED_ADDR
Definition: ipv4.h:110
#define IPV4_DNS_SERVER_LIST_SIZE
Definition: ipv4.h:76
const Ipv6Addr IPV6_UNSPECIFIED_ADDR
Definition: ipv6.c:65
Ipv6Addr
Definition: ipv6.h:251
#define IPV6_DNS_SERVER_LIST_SIZE
Definition: ipv6.h:93
#define ipv6CompAddr(ipAddr1, ipAddr2)
Definition: ipv6.h:120
#define ipv6CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv6.h:116
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
#define netMutex
Definition: net_legacy.h:195
void * netBufferAt(const NetBuffer *buffer, size_t offset)
Returns a pointer to the data at the specified position.
Definition: net_mem.c:415
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
Definition: net_mem.c:282
error_t netBufferSetLength(NetBuffer *buffer, size_t length)
Adjust the length of a multi-part buffer.
Definition: net_mem.c:322
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Definition: net_mem.c:297
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:71
uint32_t netGenerateRand(void)
Generate a random 32-bit value.
Definition: net_misc.c:888
#define NetRxAncillary
Definition: net_misc.h:40
#define NetTxAncillary
Definition: net_misc.h:36
#define MIN(a, b)
Definition: os_port.h:63
#define osStrcpy(s1, s2)
Definition: os_port.h:207
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osDelayTask(systime_t delay)
Delay routine.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
systime_t osGetSystemTime(void)
Retrieve system time.
uint32_t systime_t
System time.
char_t name[]
HostType
Host types.
Definition: socket.h:204
@ HOST_TYPE_IPV6
Definition: socket.h:207
@ HOST_TYPE_IPV4
Definition: socket.h:206
@ HOST_NAME_RESOLVER_DNS
Definition: socket.h:218
DNS cache entry.
Definition: dns_cache.h:97
systime_t timestamp
Time stamp to manage entry lifetime.
Definition: dns_cache.h:107
uint_t dnsServerIndex
This parameter selects between the primary and secondary DNS server.
Definition: dns_cache.h:102
uint16_t id
Identifier used to match queries and responses.
Definition: dns_cache.h:104
systime_t maxTimeout
Maximum retransmission timeout.
Definition: dns_cache.h:109
HostnameResolver protocol
Name resolution protocol.
Definition: dns_cache.h:100
HostType type
IPv4 or IPv6 host?
Definition: dns_cache.h:99
uint16_t port
Port number used by the resolver.
Definition: dns_cache.h:103
uint_t retransmitCount
Retransmission counter.
Definition: dns_cache.h:110
DnsState state
Entry state.
Definition: dns_cache.h:98
systime_t timeout
Retransmission timeout.
Definition: dns_cache.h:108
char_t name[DNS_MAX_NAME_LEN+1]
Domain name.
Definition: dns_cache.h:105
NetInterface * interface
Underlying network interface.
Definition: dns_cache.h:101
IpAddr ipAddr
IP address.
Definition: dns_cache.h:106
IP network address.
Definition: ip.h:79
Ipv6Addr ipv6Addr
Definition: ip.h:87
Ipv4Addr ipv4Addr
Definition: ip.h:84
size_t length
Definition: ip.h:80
IP pseudo header.
Definition: ip.h:99
IPv4 context.
Definition: ipv4.h:371
Ipv4Addr dnsServerList[IPV4_DNS_SERVER_LIST_SIZE]
DNS servers.
Definition: ipv4.h:379
IPv6 context.
Definition: ipv6.h:462
Ipv6Addr dnsServerList[IPV6_DNS_SERVER_LIST_SIZE]
DNS servers.
Definition: ipv6.h:473
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t length
Definition: tcp.h:368
error_t udpDetachRxCallback(NetInterface *interface, uint16_t port)
Unregister user callback.
Definition: udp.c:1019
NetBuffer * udpAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold a UDP packet.
Definition: udp.c:905
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:627
error_t udpAttachRxCallback(NetInterface *interface, uint16_t port, UdpRxCallback callback, void *param)
Register user callback.
Definition: udp.c:978
uint16_t udpGetDynamicPort(void)
Get an ephemeral port number.
Definition: udp.c:80
UdpHeader
Definition: udp.h:85