llmnr_client.c
Go to the documentation of this file.
1 /**
2  * @file llmnr_client.c
3  * @brief LLMNR client (Link-Local Multicast Name Resolution)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 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.6.2
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL LLMNR_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "ipv4/ipv4_misc.h"
37 #include "llmnr/llmnr_client.h"
38 #include "dns/dns_debug.h"
39 #include "debug.h"
40 
41 //Check TCP/IP stack configuration
42 #if (LLMNR_CLIENT_SUPPORT == ENABLED)
43 
44 
45 /**
46  * @brief Resolve a host name using LLMNR
47  * @param[in] interface Underlying network interface
48  * @param[in] name Name of the host to be resolved
49  * @param[in] type Host type (IPv4 or IPv6)
50  * @param[out] ipAddr IP address corresponding to the specified host name
51  **/
52 
55 {
56  error_t error;
57  DnsCacheEntry *entry;
58 
59 #if (NET_RTOS_SUPPORT == ENABLED)
60  systime_t delay;
61 
62  //Debug message
63  TRACE_INFO("Resolving host name %s (LLMNR resolver)...\r\n", name);
64 #endif
65 
66  //Get exclusive access
67  netLock(interface->netContext);
68 
69  //Search the DNS cache for the specified host name
70  entry = dnsFindEntry(interface, name, type, HOST_NAME_RESOLVER_LLMNR);
71 
72  //Check whether a matching entry has been found
73  if(entry != NULL)
74  {
75  //Host name already resolved?
76  if(entry->state == DNS_STATE_RESOLVED ||
77  entry->state == DNS_STATE_PERMANENT)
78  {
79  //Return the corresponding IP address
80  *ipAddr = entry->ipAddr;
81  //Successful host name resolution
82  error = NO_ERROR;
83  }
84  else if(entry->state == DNS_STATE_FAILED)
85  {
86  //The entry should be deleted since name resolution has failed
87  if(entry->refCount == 0)
88  {
89  //The entry should be deleted since name resolution has failed
90  dnsDeleteEntry(entry);
91  }
92 
93  //Report an error
94  error = ERROR_FAILURE;
95  }
96  else
97  {
98 #if (NET_RTOS_SUPPORT == ENABLED)
99  //Increment the reference count
100  entry->refCount++;
101 #endif
102  //Host name resolution is in progress
103  error = ERROR_IN_PROGRESS;
104  }
105  }
106  else
107  {
108  //If no entry exists, then create a new one
109  entry = dnsCreateEntry();
110 
111  //Record the host name whose IP address is unknown
112  osStrcpy(entry->name, name);
113 
114  //Initialize DNS cache entry
115  entry->type = type;
117  entry->interface = interface;
118 
119  //Get an ephemeral port number
120  entry->port = udpGetDynamicPort(interface->netContext);
121 
122  //An identifier is used by the LLMNR client to match replies with
123  //corresponding requests
124  entry->id = (uint16_t) netGenerateRand(interface->netContext);
125 
126  //Callback function to be called when a LLMNR response is received
127  error = udpRegisterRxCallback(interface, entry->port,
128  llmnrProcessResponse, NULL);
129 
130  //Check status code
131  if(!error)
132  {
133  //Initialize retransmission counter
135  //Send LLMNR query
136  error = llmnrSendQuery(entry);
137 
138  //LLMNR message successfully sent?
139  if(!error)
140  {
141  //Save the time at which the query message was sent
142  entry->timestamp = osGetSystemTime();
143  //Set timeout value
146  //Decrement retransmission counter
147  entry->retransmitCount--;
148 
149  //Switch state
150  entry->state = DNS_STATE_IN_PROGRESS;
151 
152 #if (NET_RTOS_SUPPORT == ENABLED)
153  //Initialize the reference count
154  entry->refCount = 1;
155 #endif
156  //Host name resolution is in progress
157  error = ERROR_IN_PROGRESS;
158  }
159  else
160  {
161  //Unregister UDP callback function
162  udpUnregisterRxCallback(interface, entry->port);
163  }
164  }
165  }
166 
167  //Release exclusive access
168  netUnlock(interface->netContext);
169 
170 #if (NET_RTOS_SUPPORT == ENABLED)
171  //Set default polling interval
173 
174  //Wait the host name resolution to complete
175  while(error == ERROR_IN_PROGRESS)
176  {
177  //Wait until the next polling period
178  osDelayTask(delay);
179 
180  //Get exclusive access
181  netLock(interface->netContext);
182 
183  //Search the DNS cache for the specified host name
184  entry = dnsFindEntry(interface, name, type, HOST_NAME_RESOLVER_LLMNR);
185 
186  //Check whether a matching entry has been found
187  if(entry != NULL)
188  {
189  //Host name successfully resolved?
190  if(entry->state == DNS_STATE_RESOLVED)
191  {
192  //Return the corresponding IP address
193  *ipAddr = entry->ipAddr;
194  //Successful host name resolution
195  error = NO_ERROR;
196  }
197  else if(entry->state == DNS_STATE_FAILED)
198  {
199  //Decrement the reference count
200  if(entry->refCount > 0)
201  {
202  entry->refCount--;
203  }
204 
205  //The entry should be deleted since name resolution has failed
206  if(entry->refCount == 0)
207  {
208  dnsDeleteEntry(entry);
209  }
210 
211  //Report an error
212  error = ERROR_FAILURE;
213  }
214  else
215  {
216  //Host name resolution is in progress
217  }
218  }
219  else
220  {
221  //Host name resolution failed
222  error = ERROR_FAILURE;
223  }
224 
225  //Release exclusive access
226  netUnlock(interface->netContext);
227 
228  //Backoff support for less aggressive polling
229  delay = MIN(delay * 2, DNS_CACHE_MAX_POLLING_INTERVAL);
230  }
231 
232  //Check status code
233  if(error)
234  {
235  //Failed to resolve host name
236  TRACE_INFO("Host name resolution failed!\r\n");
237  }
238  else
239  {
240  //Successful host name resolution
241  TRACE_INFO("Host name resolved to %s...\r\n", ipAddrToString(ipAddr, NULL));
242  }
243 #endif
244 
245  //Return status code
246  return error;
247 }
248 
249 
250 /**
251  * @brief Send a LLMNR query message
252  * @param[in] entry Pointer to a valid DNS cache entry
253  * @return Error code
254  **/
255 
257 {
258  error_t error;
259  size_t length;
260  size_t offset;
261  NetBuffer *buffer;
263  DnsQuestion *dnsQuestion;
265  NetTxAncillary ancillary;
266 
267 #if (IPV4_SUPPORT == ENABLED)
268  //An IPv4 address is expected?
269  if(entry->type == HOST_TYPE_IPV4)
270  {
271  //The IPv4 link-scope multicast address to which a sender sends queries
272  //is 224.0.0.252
273  destIpAddr.length = sizeof(Ipv4Addr);
275  }
276  else
277 #endif
278 #if (IPV6_SUPPORT == ENABLED)
279  //An IPv6 address is expected?
280  if(entry->type == HOST_TYPE_IPV6)
281  {
282  //The IPv6 link-scope multicast address to which a sender sends queries
283  //is ff02:0:0:0:0:0:1:3
284  destIpAddr.length = sizeof(Ipv6Addr);
286  }
287  else
288 #endif
289  //Invalid host type?
290  {
291  //Report an error
293  }
294 
295  //Allocate a memory buffer to hold the LLMNR query message
296  buffer = udpAllocBuffer(LLMNR_MESSAGE_MAX_SIZE, &offset);
297  //Failed to allocate buffer?
298  if(buffer == NULL)
299  return ERROR_OUT_OF_MEMORY;
300 
301  //Point to the LLMNR header
302  message = netBufferAt(buffer, offset, 0);
303 
304  //Format LLMNR query message
305  message->id = htons(entry->id);
306  message->qr = 0;
307  message->opcode = DNS_OPCODE_QUERY;
308  message->c = 0;
309  message->tc = 0;
310  message->t = 0;
311  message->z = 0;
312  message->rcode = DNS_RCODE_NOERROR;
313 
314  //The LLMNR query contains one question
315  message->qdcount = HTONS(1);
316  message->ancount = 0;
317  message->nscount = 0;
318  message->arcount = 0;
319 
320  //Length of the LLMNR query message
321  length = sizeof(DnsHeader);
322 
323  //Encode the host name using the DNS name notation
324  length += dnsEncodeName(entry->name, message->questions);
325 
326  //Point to the corresponding question structure
327  dnsQuestion = DNS_GET_QUESTION(message, length);
328 
329 #if (IPV4_SUPPORT == ENABLED)
330  //An IPv4 address is expected?
331  if(entry->type == HOST_TYPE_IPV4)
332  {
333  //Fill in question structure
334  dnsQuestion->qtype = HTONS(DNS_RR_TYPE_A);
335  dnsQuestion->qclass = HTONS(DNS_RR_CLASS_IN);
336  }
337 #endif
338 #if (IPV6_SUPPORT == ENABLED)
339  //An IPv6 address is expected?
340  if(entry->type == HOST_TYPE_IPV6)
341  {
342  //Fill in question structure
343  dnsQuestion->qtype = HTONS(DNS_RR_TYPE_AAAA);
344  dnsQuestion->qclass = HTONS(DNS_RR_CLASS_IN);
345  }
346 #endif
347 
348  //Update the length of the LLMNR query message
349  length += sizeof(DnsQuestion);
350 
351  //Adjust the length of the multi-part buffer
352  netBufferSetLength(buffer, offset + length);
353 
354  //Debug message
355  TRACE_INFO("Sending LLMNR message (%" PRIuSIZE " bytes)...\r\n", length);
356  //Dump message
358 
359  //Additional options can be passed to the stack along with the packet
360  ancillary = NET_DEFAULT_TX_ANCILLARY;
361 
362  //For UDP queries, the Hop Limit field in the IPv6 header and the TTL
363  //field in the IPV4 header MAY be set to any value. However, it is
364  //recommended that the value 255 be used for compatibility with early
365  //implementations (refer to RFC 4795, section 2.5)
366  ancillary.ttl = LLMNR_DEFAULT_QUERY_IP_TTL;
367 
368  //LLMNR queries are sent to and received on port 5355
369  error = udpSendBuffer(entry->interface->netContext, entry->interface, NULL,
370  entry->port, &destIpAddr, LLMNR_PORT, buffer, offset, &ancillary);
371 
372  //Free previously allocated memory
373  netBufferFree(buffer);
374 
375  //Return status code
376  return error;
377 }
378 
379 
380 /**
381  * @brief Process LLMNR response message
382  * @param[in] interface Underlying network interface
383  * @param[in] pseudoHeader UDP pseudo header
384  * @param[in] udpHeader UDP header
385  * @param[in] buffer Multi-part buffer containing the incoming LLMNR message
386  * @param[in] offset Offset to the first byte of the LLMNR message
387  * @param[in] ancillary Additional options passed to the stack along with
388  * the packet
389  * @param[in] param Callback function parameter (not used)
390  **/
391 
393  const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
394  const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary,
395  void *param)
396 {
397  uint_t i;
398  uint_t j;
399  size_t pos;
400  size_t length;
402  DnsQuestion *question;
403  DnsResourceRecord *record;
404  DnsCacheEntry *entry;
405 
406  //Retrieve the length of the LLMNR message
407  length = netBufferGetLength(buffer) - offset;
408 
409  //Malformed LLMNR message?
410  if(length < sizeof(LlmnrHeader))
411  return;
412 
413  //Point to the LLMNR message header
414  message = netBufferAt(buffer, offset, length);
415  //Sanity check
416  if(message == NULL)
417  return;
418 
419  //Debug message
420  TRACE_INFO("LLMNR message received (%" PRIuSIZE " bytes)...\r\n", length);
421  //Dump message
423 
424  //Discard LLMNR queries
425  if(!message->qr)
426  return;
427 
428  //LLMNR messages received with an opcode other than zero must be silently
429  //ignored
430  if(message->opcode != DNS_OPCODE_QUERY)
431  return;
432 
433  //LLMNR messages received with non-zero response codes must be silently
434  //ignored
435  if(message->rcode != DNS_RCODE_NOERROR)
436  return;
437 
438  //LLMNR senders must silently discard LLMNR responses with QDCOUNT not
439  //equal to one (refer to RFC 4795, section 2.1.1)
440  if(ntohs(message->qdcount) != 1)
441  return;
442 
443  //Loop through DNS cache entries
444  for(i = 0; i < DNS_CACHE_SIZE; i++)
445  {
446  //Point to the current entry
447  entry = &dnsCache[i];
448 
449  //LLMNR name resolution in progress?
450  if(entry->state == DNS_STATE_IN_PROGRESS &&
452  {
453  //Check destination port number
454  if(entry->port == ntohs(udpHeader->destPort))
455  {
456  //Compare identifier against the expected one
457  if(ntohs(message->id) != entry->id)
458  break;
459 
460  //Point to the first question
461  pos = sizeof(DnsHeader);
462  //Parse domain name
463  pos = dnsParseName((DnsHeader *) message, length, pos, NULL, 0);
464 
465  //Invalid name?
466  if(!pos)
467  break;
468  //Malformed DNS message?
469  if((pos + sizeof(DnsQuestion)) > length)
470  break;
471 
472  //Compare domain name
474  entry->name, 0))
475  {
476  break;
477  }
478 
479  //Point to the corresponding entry
480  question = DNS_GET_QUESTION(message, pos);
481 
482  //Check the class of the query
483  if(ntohs(question->qclass) != DNS_RR_CLASS_IN)
484  break;
485 
486  //Check the type of the query
487  if(entry->type == HOST_TYPE_IPV4 &&
488  ntohs(question->qtype) != DNS_RR_TYPE_A)
489  {
490  break;
491  }
492 
493  if(entry->type == HOST_TYPE_IPV6 &&
494  ntohs(question->qtype) != DNS_RR_TYPE_AAAA)
495  {
496  break;
497  }
498 
499  //Point to the first answer
500  pos += sizeof(DnsQuestion);
501 
502  //Parse answer resource records
503  for(j = 0; j < ntohs(message->ancount); j++)
504  {
505  //Parse domain name
506  pos = dnsParseName((DnsHeader *) message, length, pos, NULL, 0);
507  //Invalid name?
508  if(!pos)
509  break;
510 
511  //Point to the associated resource record
512  record = DNS_GET_RESOURCE_RECORD(message, pos);
513  //Point to the resource data
514  pos += sizeof(DnsResourceRecord);
515 
516  //Make sure the resource record is valid
517  if(pos > length)
518  break;
519  if((pos + ntohs(record->rdlength)) > length)
520  break;
521 
522 #if (IPV4_SUPPORT == ENABLED)
523  //IPv4 address expected?
524  if(entry->type == HOST_TYPE_IPV4)
525  {
526  //A resource record found?
527  if(ntohs(record->rtype) == DNS_RR_TYPE_A &&
528  ntohs(record->rdlength) == sizeof(Ipv4Addr))
529  {
530  //Copy the IPv4 address
531  entry->ipAddr.length = sizeof(Ipv4Addr);
532  ipv4CopyAddr(&entry->ipAddr.ipv4Addr, record->rdata);
533 
534  //Save current time
535  entry->timestamp = osGetSystemTime();
536  //Save TTL value
537  entry->timeout = ntohl(record->ttl) * 1000;
538  //Limit the lifetime of the NBNS cache entries
539  entry->timeout = MIN(entry->timeout, LLMNR_MAX_LIFETIME);
540 
541  //Unregister UDP callback function
542  udpUnregisterRxCallback(interface, entry->port);
543  //Host name successfully resolved
544  entry->state = DNS_STATE_RESOLVED;
545 
546  //Exit immediately
547  break;
548  }
549  }
550 #endif
551 #if (IPV6_SUPPORT == ENABLED)
552  //IPv6 address expected?
553  if(entry->type == HOST_TYPE_IPV6)
554  {
555  //AAAA resource record found?
556  if(ntohs(record->rtype) == DNS_RR_TYPE_AAAA &&
557  ntohs(record->rdlength) == sizeof(Ipv6Addr))
558  {
559  //Copy the IPv6 address
560  entry->ipAddr.length = sizeof(Ipv6Addr);
561  ipv6CopyAddr(&entry->ipAddr.ipv6Addr, record->rdata);
562 
563  //Save current time
564  entry->timestamp = osGetSystemTime();
565  //Save TTL value
566  entry->timeout = ntohl(record->ttl) * 1000;
567  //Limit the lifetime of the NBNS cache entries
568  entry->timeout = MIN(entry->timeout, LLMNR_MAX_LIFETIME);
569 
570  //Unregister UDP callback function
571  udpUnregisterRxCallback(interface, entry->port);
572  //Host name successfully resolved
573  entry->state = DNS_STATE_RESOLVED;
574 
575  //Exit immediately
576  break;
577  }
578  }
579 #endif
580  //Point to the next resource record
581  pos += ntohs(record->rdlength);
582  }
583 
584  //We are done
585  break;
586  }
587  }
588  }
589 }
590 
591 #endif
#define LLMNR_DEFAULT_QUERY_IP_TTL
Definition: llmnr_common.h:55
#define htons(value)
Definition: cpu_endian.h:413
HostType
Host types.
Definition: socket.h:215
@ DNS_STATE_PERMANENT
Definition: dns_cache.h:89
HostType type
IPv4 or IPv6 host?
Definition: dns_cache.h:101
void netUnlock(NetContext *context)
Release exclusive access to the core of the TCP/IP stack.
Definition: net.c:319
error_t udpUnregisterRxCallback(NetInterface *interface, uint16_t port)
Unregister user callback.
Definition: udp.c:1062
#define LLMNR_MAX_LIFETIME
Definition: llmnr_client.h:72
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:70
IP network address.
Definition: ip.h:90
@ DNS_OPCODE_QUERY
Query.
Definition: dns_common.h:81
#define LLMNR_CLIENT_MAX_TIMEOUT
Definition: llmnr_client.h:65
LlmnrHeader
Definition: llmnr_common.h:105
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t message[]
Definition: chap.h:154
uint32_t netGenerateRand(NetContext *context)
Generate a random 32-bit value.
Definition: net_misc.c:956
error_t llmnrSendQuery(DnsCacheEntry *entry)
Send a LLMNR query message.
Definition: llmnr_client.c:256
systime_t timeout
Retransmission timeout.
Definition: dns_cache.h:110
@ HOST_NAME_RESOLVER_LLMNR
Definition: socket.h:232
char_t * ipAddrToString(const IpAddr *ipAddr, char_t *str)
Convert a binary IP address to a string representation.
Definition: ip.c:810
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:280
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:102
@ DNS_RR_CLASS_IN
Internet.
Definition: dns_common.h:124
char_t name[]
DnsHeader
Definition: dns_common.h:202
uint_t refCount
Reference count for the current entry.
Definition: dns_cache.h:100
IpAddr ipAddr
IP address.
Definition: dns_cache.h:108
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:323
@ 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:106
@ DNS_RCODE_NOERROR
No error.
Definition: dns_common.h:95
@ ERROR_IN_PROGRESS
Definition: error.h:214
Helper functions for IPv4.
uint16_t port
Port number used by the resolver.
Definition: dns_cache.h:105
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
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:107
systime_t timestamp
Timestamp to manage entry lifetime.
Definition: dns_cache.h:109
#define DNS_GET_RESOURCE_RECORD(message, offset)
Definition: dns_common.h:64
#define LLMNR_CLIENT_MAX_RETRIES
Definition: llmnr_client.h:51
#define LLMNR_IPV4_MULTICAST_ADDR
Definition: llmnr_common.h:60
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
#define LLMNR_PORT
Definition: llmnr_common.h:53
@ DNS_STATE_FAILED
Definition: dns_cache.h:88
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:40
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
Definition: net_mem.c:282
DNS cache entry.
Definition: dns_cache.h:98
@ DNS_RR_TYPE_A
Host address.
Definition: dns_common.h:137
DnsCacheEntry * dnsCreateEntry(void)
Create a new entry in the DNS cache.
Definition: dns_cache.c:101
#define NetTxAncillary
Definition: net_misc.h:36
systime_t maxTimeout
Maximum retransmission timeout.
Definition: dns_cache.h:111
error_t udpSendBuffer(NetContext *context, 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:657
error_t llmnrResolve(NetInterface *interface, const char_t *name, HostType type, IpAddr *ipAddr)
Resolve a host name using LLMNR.
Definition: llmnr_client.c:53
#define TRACE_INFO(...)
Definition: debug.h:105
uint8_t length
Definition: tcp.h:375
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
size_t dnsEncodeName(const char_t *src, uint8_t *dest)
Encode a domain name using the DNS name notation.
Definition: dns_common.c:58
const Ipv6Addr LLMNR_IPV6_MULTICAST_ADDR
Definition: llmnr_common.c:45
UdpHeader
Definition: udp.h:85
#define DNS_CACHE_INIT_POLLING_INTERVAL
Definition: dns_cache.h:61
uint16_t udpGetDynamicPort(NetContext *context)
Get an ephemeral port number.
Definition: udp.c:80
#define LLMNR_MESSAGE_MAX_SIZE
Definition: llmnr_common.h:40
uint32_t systime_t
System time.
#define ntohs(value)
Definition: cpu_endian.h:421
char char_t
Definition: compiler_port.h:55
LLMNR client (Link-Local Multicast Name Resolution)
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:183
Ipv4Addr ipv4Addr
Definition: ip.h:95
#define ipv6CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv6.h:130
#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:103
#define DNS_CACHE_SIZE
Definition: dns_cache.h:47
@ DNS_STATE_RESOLVED
Definition: dns_cache.h:87
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:213
void dnsDeleteEntry(DnsCacheEntry *entry)
Delete the specified DNS cache entry.
Definition: dns_cache.c:151
#define ipv4CopyAddr(destIpAddr, srcIpAddr)
Definition: ipv4.h:166
void netLock(NetContext *context)
Get exclusive access to the core of the TCP/IP stack.
Definition: net.c:307
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
#define LLMNR_CLIENT_INIT_TIMEOUT
Definition: llmnr_client.h:58
Ipv4Addr ipAddr
Definition: ipcp.h:105
DnsCacheEntry dnsCache[DNS_CACHE_SIZE]
Definition: dns_cache.c:49
DnsState state
Entry state.
Definition: dns_cache.h:99
error_t udpRegisterRxCallback(NetInterface *interface, uint16_t port, UdpRxCallback callback, void *param)
Register user callback.
Definition: udp.c:1021
Ipv6Addr ipv6Addr
Definition: ip.h:98
uint_t retransmitCount
Retransmission counter.
Definition: dns_cache.h:112
#define PRIuSIZE
unsigned int uint_t
Definition: compiler_port.h:57
TCP/IP stack core.
DnsResourceRecord
Definition: dns_common.h:227
void llmnrProcessResponse(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary, void *param)
Process LLMNR response message.
Definition: llmnr_client.c:392
@ DNS_RR_TYPE_AAAA
IPv6 address.
Definition: dns_common.h:147
Data logging functions for debugging purpose (DNS)
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:210
#define DNS_CACHE_MAX_POLLING_INTERVAL
Definition: dns_cache.h:68
#define ntohl(value)
Definition: cpu_endian.h:422
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
systime_t osGetSystemTime(void)
Retrieve system time.
Ipv4Addr destIpAddr
Definition: ipcp.h:80