NetBurner 3.5.8
PDF Version
dns.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
8
26
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)
43
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
56
57
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
94int fd_dns_part1(const char *name,const IPADDR &dns_server, uint16_t TYPE = DNS_A, uint16_t TYPE2 = extra_dns_t, int ifn = -1);
95
96
113#ifndef IPV4ONLY
114bool 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);
115
116inline bool fd_dns_processresult(int fd, const char *name, IPADDR4 &addr_out, uint16_t TYPE1, uint16_t TYPE2, uint32_t *ttl)
117{
118 IPADDR ir;
119 bool result = fd_dns_processresult(fd, name, ir, TYPE1, TYPE2, ttl);
120 if (result)
121 addr_out = ir.Extract4();
122 return result;
123}
124#else
125bool fd_dns_processresult(int fd, const char *name, IPADDR &addr_out, uint16_t TYPE = DNS_A, uint16_t TYPE2 = 0, uint32_t *ttl = 0);
126
127
128#endif
129
130
143
144
145// Used internally
146int RootGetHostByName(const char *name, IPADDR & Ipa,const IPADDR & dnsServer,const TickTimeout & timeout, uint16_t TYPE, uint16_t TYPE2,int ifn_select, uint32_t *ttl);
147
148
149
160
161
185inline
186int GetHostByName(const char *name,
187 IPADDR *pIpaddr,
188 const IPADDR &dns_server,
189 const TickTimeout tout,
190 uint16_t TYPE1 = DNS_A,
191 uint16_t TYPE2 = extra_dns_t,
192 uint32_t *ttl = NULL)
193{
194 return RootGetHostByName(name,*pIpaddr,dns_server,tout,TYPE1,TYPE2, -1,ttl);
195}
196
197#ifndef IPV4ONLY
198inline
199int GetHostByName(const char *name,
200 IPADDR4 *pI4,
201 const IPADDR &dns_server,
202 const TickTimeout tout,
203 uint16_t TYPE1 = DNS_A,
204 uint16_t TYPE2 = extra_dns_t,
205 uint32_t *ttl = NULL)
206{
207 IPADDR ir;
208 int rv=RootGetHostByName(name,ir,dns_server,tout,TYPE1,TYPE2, -1,ttl);
209 if((rv==DNS_OK) && (pI4)) *pI4=ir.Extract4();
210 return rv;
211}
212#endif
213
238inline
240 const char *name,
241 IPADDR *pIpaddr,
242 const IPADDR & dns_server,
243 int ifn,
244 const TickTimeout &tout,
245 uint16_t TYPE1 = DNS_A,
246 uint16_t TYPE2 = extra_dns_t,
247 uint32_t *ttl = NULL)
248{
249 return RootGetHostByName(name,*pIpaddr,dns_server,tout,TYPE1,TYPE2, ifn,ttl);
250}
251
252#ifndef IPV4ONLY
253inline
255 const char *name,
256 IPADDR4 *pI4,
257 const IPADDR & dns_server,
258 int ifn,
259 const TickTimeout &tout,
260 uint16_t TYPE1 = DNS_A,
261 uint16_t TYPE2 = extra_dns_t,
262 uint32_t *ttl = NULL)
263{
264 IPADDR ir;
265 int rv=RootGetHostByName(name,ir,dns_server,tout,TYPE1,TYPE2, ifn,ttl);
266 if((rv==DNS_OK) && (pI4)) *pI4=ir.Extract4();
267 return rv;
268}
269
270#endif
271
272
273
274#ifdef DNS_CACHE
275//Internal use
276void RegisterResult(const char* name, IPADDR ia,uint32_t ttl, uint16_t atype);
277
288bool CheckDnsCache(const char * name, IPADDR & ia, uint32_t *ttl, uint16_t rtype);
289#endif
290
291
292#endif
293
Used to store and manipulate IPv4 addresses in dual stack mode.
Definition nettypes.h:225
IPADDR4 Extract4() const
Extracts an IPv4 address from the object.
Definition ipv6_addr.h:80
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:162
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.
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:239
bool CheckDnsCache(const char *name, IPADDR &ia, uint32_t *ttl, uint16_t rtype)
Check the DNS cache for a stored response.
int fd_dns_part1(const char *name, const IPADDR &dns_server, uint16_t TYPE=DNS_A, uint16_t TYPE2=extra_dns_t, int ifn=-1)
Open a UDP socket and initiate a DNS lookup.
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:186
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
IPADDR6 IPADDR
IPADDR Object Type (either v4 or v6).
Definition nettypes.h:568