cache.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 ML!PA Consulting GmbH
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
9 #pragma once
10 
35 #include <stdint.h>
36 
37 #include "modules.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
46 #ifndef CONFIG_DNS_CACHE_SIZE
47 #define CONFIG_DNS_CACHE_SIZE 4
48 #endif
49 
53 #ifndef CONFIG_DNS_CACHE_A
54 #define CONFIG_DNS_CACHE_A IS_USED(MODULE_IPV4)
55 #endif
56 
60 #ifndef CONFIG_DNS_CACHE_AAAA
61 #define CONFIG_DNS_CACHE_AAAA IS_USED(MODULE_IPV6)
62 #endif
63 
64 #if IS_USED(MODULE_DNS_CACHE) || DOXYGEN
75 int dns_cache_query(const char *domain_name, void *addr_out, int family);
76 
85 void dns_cache_add(const char *domain_name, const void *addr, int addr_len, uint32_t ttl);
86 #else
87 static inline int dns_cache_query(const char *domain_name, void *addr_out, int family)
88 {
89  (void)domain_name;
90  (void)addr_out;
91  (void)family;
92  return 0;
93 }
94 
95 static inline void dns_cache_add(const char *domain_name, const void *addr,
96  int addr_len, uint32_t ttl)
97 {
98  (void)domain_name;
99  (void)addr;
100  (void)addr_len;
101  (void)ttl;
102 }
103 #endif
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
int dns_cache_query(const char *domain_name, void *addr_out, int family)
Get IP address for a DNS name from the DNS cache.
void dns_cache_add(const char *domain_name, const void *addr, int addr_len, uint32_t ttl)
Add an IP address for a DNS name to the DNS cache.
Common macros and compiler attributes/pragmas configuration.