NetBurner 3.5.0
PDF Version
 
dns.h
Go to the documentation of this file.
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
27#ifndef _NB_DNS_H
28#define _NB_DNS_H
29
30#include <nettypes.h>
31#include <nbrtos.h>
32#include <buffers.h>
33#include <udp.h>
34
38#define DNS_OK (0)
39#define DNS_TIMEOUT (1)
40#define DNS_NOSUCHNAME (2)
41#define DNS_ERR (3)
49#define DNS_A 1
50#define DNS_CNAME 5
51#define DNS_MB 7
52#define DNS_MG 8
53#define DNS_MX 15
54#define DNS_AAAA 28
58#ifdef IPV6
59const uint16_t extra_dns_t=DNS_AAAA;
60#else
61const uint16_t extra_dns_t=DNS_A;
62#endif
63
64
74bool IsNameIPAddress(const char *name);
75
92int fd_dns_part1(const char *name,const IPADDR &dns_server, uint16_t TYPE = DNS_A, uint16_t TYPE2 = 0, int ifn = -1);
93
94
111#ifndef IPV4ONLY
112bool fd_dns_processresult(int fd, const char *name, IPADDR &addr_out, uint16_t TYPE = DNS_A, uint16_t TYPE2 = DNS_AAAA, uint32_t *ttl = 0);
113
114inline bool fd_dns_processresult(int fd, const char *name, IPADDR4 &addr_out, uint16_t TYPE1, uint16_t TYPE2, uint32_t *ttl)
115{
116 IPADDR ir;
117 bool result = fd_dns_processresult(fd, name, ir, TYPE1, TYPE2, ttl);
118 if (result)
119 addr_out = ir.Extract4();
120 return result;
121}
122#else
123bool fd_dns_processresult(int fd, const char *name, IPADDR &addr_out, uint16_t TYPE = DNS_A, uint16_t TYPE2 = 0, uint32_t *ttl = 0);
124
125
126#endif
127
128
141
142
143// Used internally
144int RootGetHostByName(const char *name, IPADDR & Ipa,const IPADDR & dnsServer,const TickTimeout & timeout, uint16_t TYPE, uint16_t TYPE2,int ifn_select, uint32_t *ttl);
145
146
147
158
159
183inline
184int GetHostByName(const char *name,
185 IPADDR *pIpaddr,
186 const IPADDR &dns_server,
187 const TickTimeout tout,
188 uint16_t TYPE1 = DNS_A,
189 uint16_t TYPE2 = extra_dns_t,
190 uint32_t *ttl = NULL)
191{
192 return RootGetHostByName(name,*pIpaddr,dns_server,tout,TYPE1,TYPE2, -1,ttl);
193}
194
195#ifndef IPV4ONLY
196inline
197int GetHostByName(const char *name,
198 IPADDR4 *pI4,
199 const IPADDR &dns_server,
200 const TickTimeout tout,
201 uint16_t TYPE1 = DNS_A,
202 uint16_t TYPE2 = extra_dns_t,
203 uint32_t *ttl = NULL)
204{
205 IPADDR ir;
206 int rv=RootGetHostByName(name,ir,dns_server,tout,TYPE1,TYPE2, -1,ttl);
207 if((rv==DNS_OK) && (pI4)) *pI4=ir.Extract4();
208 return rv;
209}
210#endif
211
236inline
238 const char *name,
239 IPADDR *pIpaddr,
240 const IPADDR & dns_server,
241 int ifn,
242 const TickTimeout &tout,
243 uint16_t TYPE1 = DNS_A,
244 uint16_t TYPE2 = extra_dns_t,
245 uint32_t *ttl = NULL)
246{
247 return RootGetHostByName(name,*pIpaddr,dns_server,tout,TYPE1,TYPE2, ifn,ttl);
248}
249
250#ifndef IPV4ONLY
251inline
253 const char *name,
254 IPADDR4 *pI4,
255 const IPADDR & dns_server,
256 int ifn,
257 const TickTimeout &tout,
258 uint16_t TYPE1 = DNS_A,
259 uint16_t TYPE2 = extra_dns_t,
260 uint32_t *ttl = NULL)
261{
262 IPADDR ir;
263 int rv=RootGetHostByName(name,ir,dns_server,tout,TYPE1,TYPE2, ifn,ttl);
264 if((rv==DNS_OK) && (pI4)) *pI4=ir.Extract4();
265 return rv;
266}
267
268#endif
269
270
271
272#ifdef DNS_CACHE
273//Internal use
274void RegisterResult(const char* name, IPADDR ia,uint32_t ttl);
275
285bool CheckDnsCache(const char * name, IPADDR & ia, uint32_t *ttl);
286#endif
287
288
289#endif
290
NetBurner Buffers API.
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:208
Used to hold and manipulate IPv4 and IPv6 addresses in dual stack mode.
Definition ipv6_addr.h:41
IPADDR4 Extract4() const
Extracts an IPv4 address from the object.
Definition ipv6_addr.h:73
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:157
bool fd_dns_processresult(int fd, const char *name, IPADDR &addr_out, uint16_t TYPE=DNS_A, uint16_t TYPE2=DNS_AAAA, uint32_t *ttl=0)
Process any responses on the UDP socket opened for DNS.
int fd_outstanding_Responses(int fd)
Check to see if there are any outstanding DNS requests.
int fd_dns_part1(const char *name, const IPADDR &dns_server, uint16_t TYPE=DNS_A, uint16_t TYPE2=0, int ifn=-1)
Open a UDP socket and initiate a DNS lookup.
bool AnyDNSInterFaceActive()
Determine if we have an active DNS route; DNS server is set for an active interface.
int GetHostByNameViaIfNum(const char *name, IPADDR *pIpaddr, const IPADDR &dns_server, int ifn, const TickTimeout &tout, uint16_t TYPE1=DNS_A, uint16_t TYPE2=extra_dns_t, uint32_t *ttl=NULL)
Get the IP address associated with the specified domain name on a specific interface.
Definition dns.h:237
int GetHostByName(const char *name, IPADDR *pIpaddr, const IPADDR &dns_server, const TickTimeout tout, uint16_t TYPE1=DNS_A, uint16_t TYPE2=extra_dns_t, uint32_t *ttl=NULL)
Get the IP address associated with the specified domain name.
Definition dns.h:184
bool IsNameIPAddress(const char *name)
Determine if the name is a valid IP Address and does not need to be looked up.
#define DNS_OK
Success.
Definition dns.h:38
#define DNS_AAAA
128-bit IPv6 address
Definition dns.h:54
#define DNS_A
32-bit IPv4 address
Definition dns.h:49
NetBurner Real-Time Operating System (NBRTOS) API.
NetBurner IPADDR4 Class. See the IPADDR4 Class page for complete documentation.
NetBurner User Datagram Protocol Header File.