dns.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Freie Universität Berlin
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 
20 #ifndef NET_DNS_H
21 #define NET_DNS_H
22 
23 #include "modules.h"
24 #include "net/sock/dns.h"
25 #include "net/sock/dodtls.h"
26 #include "net/gcoap/dns.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
36 #define DNS_TYPE_A (1)
37 #define DNS_TYPE_AAAA (28)
38 #define DNS_CLASS_IN (1)
45 #define RR_TYPE_LENGTH (2U)
46 #define RR_CLASS_LENGTH (2U)
47 #define RR_TTL_LENGTH (4U)
48 #define RR_RDLENGTH_LENGTH (2U)
73 static inline int dns_query(const char *domain_name, void *addr_out, int family)
74 {
75  int res = -ENOTSUP;
76 
77  if (family == AF_UNSPEC) {
78  if (!IS_USED(MODULE_IPV4_ADDR)) {
79  family = AF_INET6;
80  }
81  else if (!IS_USED(MODULE_IPV6_ADDR)) {
82  family = AF_INET;
83  }
84  }
85 
86  if (res <= 0 && IS_USED(MODULE_GCOAP_DNS)) {
87  res = gcoap_dns_query(domain_name, addr_out, family);
88  }
89  if (res <= 0 && IS_USED(MODULE_SOCK_DODTLS)) {
90  res = sock_dodtls_query(domain_name, addr_out, family);
91  }
92  if (res <= 0 && (IS_USED(MODULE_SOCK_DNS) || IS_USED(MODULE_SOCK_DNS_MOCK))) {
93  res = sock_dns_query(domain_name, addr_out, family);
94  }
95 
96  return res;
97 }
98 
99 #ifdef __cplusplus
100 }
101 #endif
102 
103 #endif /* NET_DNS_H */
DNS over DTLS sock definitions.
gcoap_dns definitions
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:130
@ AF_INET6
internetwork address family with IPv6: UDP, TCP, etc.
Definition: af.h:39
@ AF_INET
internetwork address family: UDP, TCP, etc.
Definition: af.h:37
@ AF_UNSPEC
unspecified address family
Definition: af.h:31
static int dns_query(const char *domain_name, void *addr_out, int family)
Get IP address for DNS name.
Definition: dns.h:73
int gcoap_dns_query(const char *domain_name, void *addr_out, int family)
Query a domain name via CoAP synchronously.
int sock_dns_query(const char *domain_name, void *addr_out, int family)
Get IP address for DNS name.
int sock_dodtls_query(const char *domain_name, void *addr_out, int family)
Get IP address for DNS name.
Common macros and compiler attributes/pragmas configuration.
#define IS_USED(module)
Checks whether a module is being used or not.
Definition: modules.h:71
DNS sock definitions.