dns_client.h
Go to the documentation of this file.
1 /**
2  * @file dns_client.h
3  * @brief DNS client (Domain Name System)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _DNS_CLIENT_H
32 #define _DNS_CLIENT_H
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/socket.h"
37 #include "core/udp.h"
38 #include "dns/dns_cache.h"
39 
40 //DNS client support
41 #ifndef DNS_CLIENT_SUPPORT
42  #define DNS_CLIENT_SUPPORT ENABLED
43 #elif (DNS_CLIENT_SUPPORT != ENABLED && DNS_CLIENT_SUPPORT != DISABLED)
44  #error DNS_CLIENT_SUPPORT parameter is not valid
45 #endif
46 
47 //Maximum number of retransmissions of DNS queries
48 #ifndef DNS_CLIENT_MAX_RETRIES
49  #define DNS_CLIENT_MAX_RETRIES 3
50 #elif (DNS_CLIENT_MAX_RETRIES < 1)
51  #error DNS_CLIENT_MAX_RETRIES parameter is not valid
52 #endif
53 
54 //Initial retransmission timeout
55 #ifndef DNS_CLIENT_INIT_TIMEOUT
56  #define DNS_CLIENT_INIT_TIMEOUT 1000
57 #elif (DNS_CLIENT_INIT_TIMEOUT < 1000)
58  #error DNS_CLIENT_INIT_TIMEOUT parameter is not valid
59 #endif
60 
61 //Maximum retransmission timeout
62 #ifndef DNS_CLIENT_MAX_TIMEOUT
63  #define DNS_CLIENT_MAX_TIMEOUT 5000
64 #elif (DNS_CLIENT_MAX_TIMEOUT < 1000)
65  #error DNS_CLIENT_MAX_TIMEOUT parameter is not valid
66 #endif
67 
68 //Minimum cache lifetime for DNS entries
69 #ifndef DNS_MIN_LIFETIME
70  #define DNS_MIN_LIFETIME 1000
71 #elif (DNS_MIN_LIFETIME < 0)
72  #error DNS_MIN_LIFETIME parameter is not valid
73 #endif
74 
75 //Maximum cache lifetime for DNS entries
76 #ifndef DNS_MAX_LIFETIME
77  #define DNS_MAX_LIFETIME 3600000
78 #elif (DNS_MAX_LIFETIME < 1000 || DNS_MAX_LIFETIME < DNS_MIN_LIFETIME)
79  #error DNS_MAX_LIFETIME parameter is not valid
80 #endif
81 
82 //C++ guard
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 //DNS related functions
88 error_t dnsResolve(NetInterface *interface, const char_t *name,
90 
92 
93 void dnsProcessResponse(NetInterface *interface,
94  const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader,
95  const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary,
96  void *param);
97 
99 
100 //C++ guard
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif
uint8_t type
Definition: coap_common.h:176
char char_t
Definition: compiler_port.h:48
DNS cache management.
error_t dnsSendQuery(DnsCacheEntry *entry)
Send a DNS query message.
Definition: dns_client.c:218
error_t dnsResolve(NetInterface *interface, const char_t *name, HostType type, IpAddr *ipAddr)
Resolve a host name using DNS.
Definition: dns_client.c:54
void dnsSelectNextServer(DnsCacheEntry *entry)
Select the next DNS server.
Definition: dns_client.c:590
void dnsProcessResponse(NetInterface *interface, const IpPseudoHeader *pseudoHeader, const UdpHeader *udpHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary, void *param)
Process incoming DNS response message.
Definition: dns_client.c:382
error_t
Error codes.
Definition: error.h:43
Ipv4Addr ipAddr
Definition: ipcp.h:105
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
#define NetRxAncillary
Definition: net_misc.h:40
char_t name[]
Socket API.
HostType
Host types.
Definition: socket.h:204
DNS cache entry.
Definition: dns_cache.h:97
IP network address.
Definition: ip.h:79
IP pseudo header.
Definition: ip.h:99
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
UDP (User Datagram Protocol)
UdpHeader
Definition: udp.h:85