Loading...
Searching...
No Matches
dns.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Freie Universität Berlin
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
19
20#include "modules.h"
21#include "net/af.h"
22#if IS_USED(MODULE_HOSTS)
23# include "net/hosts.h"
24#endif
25#if IS_USED(MODULE_SOCK_DNS) || IS_USED(MODULE_SOCK_DNS_MOCK)
26# include "net/sock/dns.h"
27#endif
28#if IS_USED(MODULE_SOCK_DODTLS)
29# include "net/sock/dodtls.h"
30#endif
31#if IS_USED(MODULE_GCOAP_DNS)
32# include "net/gcoap/dns.h"
33#endif
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
43#define DNS_TYPE_A (1)
44#define DNS_TYPE_AAAA (28)
45#define DNS_CLASS_IN (1)
47
52#define RR_TYPE_LENGTH (2U)
53#define RR_CLASS_LENGTH (2U)
54#define RR_TTL_LENGTH (4U)
55#define RR_RDLENGTH_LENGTH (2U)
57
80static inline int dns_query(const char *domain_name, void *addr_out, int family)
81{
82 (void)domain_name;
83 (void)addr_out;
84
85 int res = -ENOTSUP;
86
87 if (family == AF_UNSPEC) {
88 if (!IS_USED(MODULE_IPV4_ADDR)) {
89 family = AF_INET6;
90 }
91 else if (!IS_USED(MODULE_IPV6_ADDR)) {
92 family = AF_INET;
93 }
94 }
95
96#if IS_USED(MODULE_HOSTS)
97 if (res <= 0) {
98 res = hosts_query(domain_name, addr_out, family);
99 }
100#endif
101#if IS_USED(MODULE_GCOAP_DNS)
102 if (res <= 0) {
103 res = gcoap_dns_query(domain_name, addr_out, family);
104 }
105#endif
106#if IS_USED(MODULE_SOCK_DODTLS)
107 if (res <= 0) {
108 res = sock_dodtls_query(domain_name, addr_out, family);
109 }
110#endif
111#if IS_USED(MODULE_SOCK_DNS) || IS_USED(MODULE_SOCK_DNS_MOCK)
112 if (res <= 0) {
113 res = sock_dns_query(domain_name, addr_out, family);
114 }
115#endif
116
117 return res;
118}
119
120#ifdef __cplusplus
121}
122#endif
123
Global UNIX address family definitions.
#define AF_INET
internetwork address family: UDP, TCP, etc.
Definition af.h:35
#define AF_INET6
internetwork address family with IPv6: UDP, TCP, etc.
Definition af.h:37
#define AF_UNSPEC
unspecified address family (as macro)
Definition af.h:29
DNS over DTLS sock definitions.
gcoap_dns definitions
#define ENOTSUP
Not supported (may be the same value as [EOPNOTSUPP]).
Definition errno.h:129
static int dns_query(const char *domain_name, void *addr_out, int family)
Get IP address for DNS name.
Definition dns.h:80
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:67
DNS sock definitions.