NetBurner 3.5.8
PDF Version
dns.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
8
231
232#ifndef _NB_DNS_H
233#define _NB_DNS_H
234
235#include <nettypes.h>
236#include <nbrtos.h>
237#include <buffers.h>
238#include <udp.h>
239
243#define DNS_OK (0)
244#define DNS_TIMEOUT (1)
245#define DNS_NOSUCHNAME (2)
246#define DNS_ERR (3)
248
254#define DNS_A 1
255#define DNS_CNAME 5
256#define DNS_MB 7
257#define DNS_MG 8
258#define DNS_MX 15
259#define DNS_AAAA 28
261
262
263#ifdef IPV6
264const uint16_t extra_dns_t=DNS_AAAA;
265#else
266const uint16_t extra_dns_t=DNS_A;
267#endif
268
269
279bool IsNameIPAddress(const char *name);
280
299int fd_dns_part1(const char *name,const IPADDR &dns_server, uint16_t TYPE = DNS_A, uint16_t TYPE2 = extra_dns_t, int ifn = -1);
300
301
318#ifndef IPV4ONLY
319bool 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);
320
321inline bool fd_dns_processresult(int fd, const char *name, IPADDR4 &addr_out, uint16_t TYPE1, uint16_t TYPE2, uint32_t *ttl)
322{
323 IPADDR ir;
324 bool result = fd_dns_processresult(fd, name, ir, TYPE1, TYPE2, ttl);
325 if (result)
326 addr_out = ir.Extract4();
327 return result;
328}
329#else
330bool fd_dns_processresult(int fd, const char *name, IPADDR &addr_out, uint16_t TYPE = DNS_A, uint16_t TYPE2 = 0, uint32_t *ttl = 0);
331
332
333#endif
334
335
348
349
350// Used internally
351int RootGetHostByName(const char *name, IPADDR & Ipa,const IPADDR & dnsServer,const TickTimeout & timeout, uint16_t TYPE, uint16_t TYPE2,int ifn_select, uint32_t *ttl);
352
353
354
365
366
390inline
391int GetHostByName(const char *name,
392 IPADDR *pIpaddr,
393 const IPADDR &dns_server,
394 const TickTimeout tout,
395 uint16_t TYPE1 = DNS_A,
396 uint16_t TYPE2 = extra_dns_t,
397 uint32_t *ttl = NULL)
398{
399 return RootGetHostByName(name,*pIpaddr,dns_server,tout,TYPE1,TYPE2, -1,ttl);
400}
401
402#ifndef IPV4ONLY
403inline
404int GetHostByName(const char *name,
405 IPADDR4 *pI4,
406 const IPADDR &dns_server,
407 const TickTimeout tout,
408 uint16_t TYPE1 = DNS_A,
409 uint16_t TYPE2 = extra_dns_t,
410 uint32_t *ttl = NULL)
411{
412 IPADDR ir;
413 int rv=RootGetHostByName(name,ir,dns_server,tout,TYPE1,TYPE2, -1,ttl);
414 if((rv==DNS_OK) && (pI4)) *pI4=ir.Extract4();
415 return rv;
416}
417#endif
418
443inline
445 const char *name,
446 IPADDR *pIpaddr,
447 const IPADDR & dns_server,
448 int ifn,
449 const TickTimeout &tout,
450 uint16_t TYPE1 = DNS_A,
451 uint16_t TYPE2 = extra_dns_t,
452 uint32_t *ttl = NULL)
453{
454 return RootGetHostByName(name,*pIpaddr,dns_server,tout,TYPE1,TYPE2, ifn,ttl);
455}
456
457#ifndef IPV4ONLY
458inline
460 const char *name,
461 IPADDR4 *pI4,
462 const IPADDR & dns_server,
463 int ifn,
464 const TickTimeout &tout,
465 uint16_t TYPE1 = DNS_A,
466 uint16_t TYPE2 = extra_dns_t,
467 uint32_t *ttl = NULL)
468{
469 IPADDR ir;
470 int rv=RootGetHostByName(name,ir,dns_server,tout,TYPE1,TYPE2, ifn,ttl);
471 if((rv==DNS_OK) && (pI4)) *pI4=ir.Extract4();
472 return rv;
473}
474
475#endif
476
477
478
479#ifdef DNS_CACHE
480//Internal use
481void RegisterResult(const char* name, IPADDR ia,uint32_t ttl, uint16_t atype);
482
493bool CheckDnsCache(const char * name, IPADDR & ia, uint32_t *ttl, uint16_t rtype);
494#endif
495
496
497#endif
498
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:444
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:391
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:243
#define DNS_AAAA
128-bit IPv6 address
Definition dns.h:259
#define DNS_A
32-bit IPv4 address
Definition dns.h:254
IPADDR6 IPADDR
IPADDR Object Type (either v4 or v6).
Definition nettypes.h:568