dns.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
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 
26 #include <errno.h>
27 #include <stdint.h>
28 #include <unistd.h>
29 
30 #include "net/dns/msg.h"
31 
32 #include "net/sock/udp.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #ifdef MODULE_AUTO_INIT_SOCK_DNS
42 #ifndef CONFIG_AUTO_INIT_SOCK_DNS_IP_VERSION
43  /* IPv6 is preferred */
44  #if defined(SOCK_HAS_IPV6)
45  #define CONFIG_AUTO_INIT_SOCK_DNS_IP_VERSION 6
46  #elif defined(SOCK_HAS_IPV4)
47  #define CONFIG_AUTO_INIT_SOCK_DNS_IP_VERSION 4
48  #else
49  #error "Neither IPv4 nor IPv6 included in build"
50  #endif
51 #endif
52 
56 #ifndef CONFIG_AUTO_INIT_SOCK_DNS_SERVER_ADDR
57  /* Default to Quad9 Public DNS */
58  #if CONFIG_AUTO_INIT_SOCK_DNS_IP_VERSION == 6
59  #define CONFIG_AUTO_INIT_SOCK_DNS_SERVER_ADDR "2620:fe::fe"
60  #elif CONFIG_AUTO_INIT_SOCK_DNS_IP_VERSION == 4
61  #define CONFIG_AUTO_INIT_SOCK_DNS_SERVER_ADDR "9.9.9.9"
62  #endif
63 #endif
64 
68 #ifndef CONFIG_AUTO_INIT_SOCK_DNS_SERVER_PORT
69 #define CONFIG_AUTO_INIT_SOCK_DNS_SERVER_PORT SOCK_DNS_PORT
70 #endif
71 #endif /* MODULE_AUTO_INIT_SOCK_DNS */
72 
77 #define SOCK_DNS_PORT (53)
78 #define SOCK_DNS_RETRIES (2)
79 
80 #define SOCK_DNS_MAX_NAME_LEN (CONFIG_DNS_MSG_LEN - sizeof(dns_hdr_t) - 4)
105 int sock_dns_query(const char *domain_name, void *addr_out, int family);
106 
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
int sock_dns_query(const char *domain_name, void *addr_out, int family)
Get IP address for DNS name.
sock_udp_ep_t sock_dns_server
global DNS server endpoint
UDP sock definitions.
Common IP-based transport layer end point.
Definition: sock.h:214
Definitions for parsing and composition of DNS messages.