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