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 
9 #pragma once
10 
23 #include "modules.h"
24 #include "net/af.h"
25 #if IS_USED(MODULE_HOSTS)
26 # include "net/hosts.h"
27 #endif
28 #if IS_USED(MODULE_SOCK_DNS) || IS_USED(MODULE_SOCK_DNS_MOCK)
29 # include "net/sock/dns.h"
30 #endif
31 #if IS_USED(MODULE_SOCK_DODTLS)
32 # include "net/sock/dodtls.h"
33 #endif
34 #if IS_USED(MODULE_GCOAP_DNS)
35 # include "net/gcoap/dns.h"
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
46 #define DNS_TYPE_A (1)
47 #define DNS_TYPE_AAAA (28)
48 #define DNS_CLASS_IN (1)
55 #define RR_TYPE_LENGTH (2U)
56 #define RR_CLASS_LENGTH (2U)
57 #define RR_TTL_LENGTH (4U)
58 #define RR_RDLENGTH_LENGTH (2U)
83 static inline int dns_query(const char *domain_name, void *addr_out, int family)
84 {
85  (void)domain_name;
86  (void)addr_out;
87 
88  int res = -ENOTSUP;
89 
90  if (family == AF_UNSPEC) {
91  if (!IS_USED(MODULE_IPV4_ADDR)) {
92  family = AF_INET6;
93  }
94  else if (!IS_USED(MODULE_IPV6_ADDR)) {
95  family = AF_INET;
96  }
97  }
98 
99 #if IS_USED(MODULE_HOSTS)
100  if (res <= 0) {
101  res = hosts_query(domain_name, addr_out, family);
102  }
103 #endif
104 #if IS_USED(MODULE_GCOAP_DNS)
105  if (res <= 0) {
106  res = gcoap_dns_query(domain_name, addr_out, family);
107  }
108 #endif
109 #if IS_USED(MODULE_SOCK_DODTLS)
110  if (res <= 0) {
111  res = sock_dodtls_query(domain_name, addr_out, family);
112  }
113 #endif
114 #if IS_USED(MODULE_SOCK_DNS) || IS_USED(MODULE_SOCK_DNS_MOCK)
115  if (res <= 0) {
116  res = sock_dns_query(domain_name, addr_out, family);
117  }
118 #endif
119 
120  return res;
121 }
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
Global UNIX address family definitions.
DNS over DTLS sock definitions.
gcoap_dns definitions
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition: errno.h:129
@ 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:83
int gcoap_dns_query(const char *domain_name, void *addr_out, int family)
Query a domain name via CoAP synchronously.
int hosts_query(const char *host_name, void *addr_out, int family)
Get IP address for a host name.
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.
Static mappings from hostnames to IP addresses.
Common macros and compiler attributes/pragmas configuration.
#define IS_USED(module)
Checks whether a module is being used or not.
Definition: modules.h:70
DNS sock definitions.