dns.h
#ifndef DNS_H
#define DNS_H
#include "sysdeps.h"
#include "systime.h"
#include "ipv4.h"
#include "ipv6.h"
#include "str.h"
#include "uint16.h"
#define TV_LESS(A,B) (((A)->tv_sec < (B)->tv_sec) || ((A)->tv_sec == (B)->tv_sec && (A)->tv_usec < (B)->tv_usec))
#define DNS_C_IN 1
#define DNS_C_ANY 255
#define DNS_T_A 1
#define DNS_T_NS 2
#define DNS_T_CNAME 5
#define DNS_T_SOA 6
#define DNS_T_PTR 12
#define DNS_T_HINFO 13
#define DNS_T_MX 15
#define DNS_T_TXT 16
#define DNS_T_RP 17
#define DNS_T_SIG 24
#define DNS_T_KEY 25
#define DNS_T_AAAA 28
#define DNS_T_AXFR 252
#define DNS_T_ANY 255
#define DNS_RANDOM_SEED (32*4)
#define DNS_MAX_IPS 16
#define DNS_NAME4_DOMAIN (4*4+14)
#define DNS_NAME6_DOMAIN (32*2+10)
struct dns_transmit {
char *query;
unsigned int querylen;
char *packet;
unsigned int packetlen;
int s1;
int tcpstate;
unsigned int udploop;
unsigned int curserver;
struct timeval deadline;
unsigned int pos;
const ipv4addr *servers;
ipv4addr localip;
uint16 qtype;
};
struct dns_mx
{
uint16 distance;
char* name;
};
union dns_result_rrs
{
void* __ptr;
ipv4addr* ip4;
ipv6addr* ip6;
struct dns_mx* mx;
char** name;
};
struct dns_result
{
int count;
int type;
union dns_result_rrs rr;
void* __buffer;
};
extern int dns_result_alloc(struct dns_result* d, int type, int count, int size);
extern void dns_result_free(struct dns_result* d);
extern void dns_random_init(const char [DNS_RANDOM_SEED]);
extern unsigned int dns_random(unsigned int);
extern void dns_rotate(unsigned char*, unsigned int n, unsigned int shift);
extern void dns_rotateipv4(ipv4addr*, unsigned int);
extern void dns_rotateipv6(ipv6addr*, unsigned int);
extern void dns_sort_mx(struct dns_mx* mxs, int count);
extern void dns_domain_free(char **);
extern int dns_domain_copy(char **,const char *);
extern unsigned int dns_domain_length(const char *);
extern int dns_domain_equal(const char *,const char *);
extern int dns_domain_suffix(const char *,const char *);
extern unsigned int dns_domain_suffixpos(const char *,const char *);
extern int dns_domain_fromdot(char **,const char *,unsigned int);
extern int dns_domain_todot_cat(str *,const char *);
extern unsigned int dns_packet_copy(const char *,unsigned int,unsigned int,unsigned char *,unsigned int);
extern unsigned int dns_packet_getname(const char *,unsigned int,unsigned int,char **);
extern unsigned int dns_packet_skipname(const char *,unsigned int,unsigned int);
extern int dns_packet_extract(struct dns_result* out, const char* buf, unsigned int len, uint16 rrtype, uint16 rrclass,
int (*sizefn)(const char* buf, unsigned int len, unsigned int pos, uint16 datalen),
int (*copy)(struct dns_result* out, unsigned int index, unsigned int offset,
const char* buf, unsigned int len, unsigned int pos, uint16 datalen));
extern int dns_transmit_start(struct dns_transmit *,const ipv4addr [DNS_MAX_IPS],int,const char *,uint16,const ipv4addr *);
extern void dns_transmit_free(struct dns_transmit *);
extern void dns_transmit_io(const struct dns_transmit *,iopoll_fd *,struct timeval *);
extern int dns_transmit_get(struct dns_transmit *,const iopoll_fd *,const struct timeval *);
extern int dns_read_resolvconf(str *out);
extern int dns_resolvconfip(ipv4addr [DNS_MAX_IPS]);
extern int dns_resolve(struct dns_transmit *,const char *,uint16);
extern int dns_ip4_packet(struct dns_result*, const char*, unsigned int);
extern int dns_ip4_r(struct dns_transmit*, struct dns_result*, const char *);
extern int dns_ip4(struct dns_result*, const char *);
extern int dns_ip6_packet(struct dns_result*, const char*, unsigned int);
extern int dns_ip6_r(struct dns_transmit*, struct dns_result*, const char *);
extern int dns_ip6(struct dns_result*, const char*);
extern int dns_name_packet(struct dns_result*, const char *,unsigned int);
extern void dns_name4_domain(char [DNS_NAME4_DOMAIN],const ipv4addr *);
extern void dns_name6_domain(char [DNS_NAME6_DOMAIN],const ipv6addr *);
extern int dns_name4_r(struct dns_transmit*, struct dns_result*, const ipv4addr*);
extern int dns_name4(struct dns_result*, const ipv4addr*);
extern int dns_name6_r(struct dns_transmit*, struct dns_result*, const ipv6addr*);
extern int dns_name6(struct dns_result*, const ipv6addr*);
extern int dns_txt_packet(struct dns_result*, const char *,unsigned int);
extern int dns_txt_r(struct dns_transmit *,struct dns_result*, const char *);
extern int dns_txt(struct dns_result*, const char *);
extern int dns_mx_packet(struct dns_result*, const char *,unsigned int);
extern int dns_mx_r(struct dns_transmit *,struct dns_result*, const char *);
extern int dns_mx(struct dns_result*, const char *);
extern int dns_resolvconfrewrite(str *);
extern int dns_qualify_rules(struct dns_result*,str *,const char *,const str *,
int (*)(struct dns_transmit*, struct dns_result*, const char*));
extern int dns_qualify(struct dns_result*,str *,const char *,
int (*)(struct dns_transmit*, struct dns_result*, const char*));
extern unsigned fmt_dns_domain(char*, const char*);
#define DNS_R_FN_WRAP(NAME,TYPE) \
int dns_##NAME(struct dns_result* out,TYPE in) \
{ \
struct dns_transmit tx = {0}; \
int r = dns_##NAME##_r(&tx,out,in); \
dns_transmit_free(&tx); \
return r; \
}
#endif
DNS_RANDOM_SEED
#define DNS_RANDOM_SEED
Definition: dns.h:70
dns_transmit::s1
int s1
Definition: dns.h:91
fmt_dns_domain
unsigned fmt_dns_domain(char *, const char *)
Definition: dns_fmt.c:4
dns_mx_packet
int dns_mx_packet(struct dns_result *, const char *, unsigned int)
Definition: dns_mx.c:34
dns_transmit
Definition: dns.h:79
dns_mx::distance
uint16 distance
Definition: dns.h:122
dns_transmit_get
int dns_transmit_get(struct dns_transmit *, const iopoll_fd *, const struct timeval *)
Definition: dns_transmit.c:257
dns_result_rrs
Definition: dns.h:127
dns_transmit::udploop
unsigned int udploop
Definition: dns.h:103
dns_resolvconfip
int dns_resolvconfip(ipv4addr [DNS_MAX_IPS])
Definition: dns_resolvconfip.c:84
dns_random
unsigned int dns_random(unsigned int)
Definition: dns_random.c:28
dns_txt_r
int dns_txt_r(struct dns_transmit *, struct dns_result *, const char *)
Definition: dns_txt.c:50
dns_qualify
int dns_qualify(struct dns_result *, str *, const char *, int(*)(struct dns_transmit *, struct dns_result *, const char *))
Definition: dns_qualify.c:99
dns_name4
int dns_name4(struct dns_result *, const ipv4addr *)
dns_txt_packet
int dns_txt_packet(struct dns_result *, const char *, unsigned int)
Definition: dns_txt.c:44
DNS_NAME4_DOMAIN
#define DNS_NAME4_DOMAIN
Definition: dns.h:74
ipv6addr
Definition: ipv6.h:11
dns_transmit::querylen
unsigned int querylen
Definition: dns.h:83
dns_ip4_packet
int dns_ip4_packet(struct dns_result *, const char *, unsigned int)
Definition: dns_ip4.c:18
dns_ip6
int dns_ip6(struct dns_result *, const char *)
dns_txt
int dns_txt(struct dns_result *, const char *)
dns_transmit_start
int dns_transmit_start(struct dns_transmit *, const ipv4addr [DNS_MAX_IPS], int, const char *, uint16, const ipv4addr *)
Definition: dns_transmit.c:204
dns_mx
int dns_mx(struct dns_result *, const char *)
dns_rotate
void dns_rotate(unsigned char *, unsigned int n, unsigned int shift)
Definition: dns_rotate.c:11
dns_result::count
int count
Definition: dns.h:140
dns_domain_fromdot
int dns_domain_fromdot(char **, const char *, unsigned int)
Definition: dns_domain_fromdot.c:8
dns_transmit::localip
ipv4addr localip
Definition: dns.h:113
dns_transmit::tcpstate
int tcpstate
Definition: dns.h:101
dns_transmit::deadline
struct timeval deadline
Definition: dns.h:107
dns_transmit::curserver
unsigned int curserver
Definition: dns.h:105
dns_transmit::packet
char * packet
Definition: dns.h:85
dns_mx
Definition: dns.h:119
dns_result::__buffer
void * __buffer
Definition: dns.h:146
dns_name6_r
int dns_name6_r(struct dns_transmit *, struct dns_result *, const ipv6addr *)
Definition: dns_name6.c:4
dns_result_alloc
int dns_result_alloc(struct dns_result *d, int type, int count, int size)
Definition: dns_result.c:21
dns_ip4_r
int dns_ip4_r(struct dns_transmit *, struct dns_result *, const char *)
Definition: dns_ip4.c:27
dns_domain_todot_cat
int dns_domain_todot_cat(str *, const char *)
Definition: dns_domain_todot.c:4
dns_qualify_rules
int dns_qualify_rules(struct dns_result *, str *, const char *, const str *, int(*)(struct dns_transmit *, struct dns_result *, const char *))
Definition: dns_qualify.c:50
dns_transmit::packetlen
unsigned int packetlen
Definition: dns.h:87
dns_transmit::servers
const ipv4addr * servers
Definition: dns.h:111
dns_name4_domain
void dns_name4_domain(char [DNS_NAME4_DOMAIN], const ipv4addr *)
Definition: dns_name4_domain.c:7
dns_packet_copy
unsigned int dns_packet_copy(const char *, unsigned int, unsigned int, unsigned char *, unsigned int)
Definition: dns_packet.c:12
DNS_NAME6_DOMAIN
#define DNS_NAME6_DOMAIN
Definition: dns.h:76
dns_packet_getname
unsigned int dns_packet_getname(const char *, unsigned int, unsigned int, char **)
Definition: dns_packet.c:41
dns_packet_extract
int dns_packet_extract(struct dns_result *out, const char *buf, unsigned int len, uint16 rrtype, uint16 rrclass, int(*sizefn)(const char *buf, unsigned int len, unsigned int pos, uint16 datalen), int(*copy)(struct dns_result *out, unsigned int index, unsigned int offset, const char *buf, unsigned int len, unsigned int pos, uint16 datalen))
Definition: dns_packet.c:96
dns_result
Definition: dns.h:137
DNS_MAX_IPS
#define DNS_MAX_IPS
Definition: dns.h:72
dns_result_free
void dns_result_free(struct dns_result *d)
Definition: dns_result.c:8
dns_resolvconfrewrite
int dns_resolvconfrewrite(str *)
Definition: dns_resolvconfrewrite.c:128
dns_transmit::query
char * query
Definition: dns.h:81
dns_domain_length
unsigned int dns_domain_length(const char *)
Definition: dns_domain.c:8
dns_domain_suffix
int dns_domain_suffix(const char *, const char *)
Definition: dns_domain.c:56
ipv4addr
Definition: ipv4.h:11
dns_domain_free
void dns_domain_free(char **)
Definition: dns_domain.c:20
dns_read_resolvconf
int dns_read_resolvconf(str *out)
Definition: dns_resolvconfip.c:15
str
Definition: str.h:30
dns_domain_suffixpos
unsigned int dns_domain_suffixpos(const char *, const char *)
Definition: dns_domain.c:69
dns_packet_skipname
unsigned int dns_packet_skipname(const char *, unsigned int, unsigned int)
Definition: dns_packet.c:23
dns_name_packet
int dns_name_packet(struct dns_result *, const char *, unsigned int)
Definition: dns_name_packet.c:31
dns_name6
int dns_name6(struct dns_result *, const ipv6addr *)
dns_transmit_free
void dns_transmit_free(struct dns_transmit *)
Definition: dns_transmit.c:79
dns_name4_r
int dns_name4_r(struct dns_transmit *, struct dns_result *, const ipv4addr *)
Definition: dns_name4.c:6
dns_rotateipv4
void dns_rotateipv4(ipv4addr *, unsigned int)
Definition: dns_rotate.c:27
dns_domain_equal
int dns_domain_equal(const char *, const char *)
Definition: dns_domain.c:44
dns_rotateipv6
void dns_rotateipv6(ipv6addr *, unsigned int)
Definition: dns_rotate.c:33
dns_ip6_r
int dns_ip6_r(struct dns_transmit *, struct dns_result *, const char *)
Definition: dns_ip6.c:27
dns_transmit::qtype
uint16 qtype
Definition: dns.h:115
dns_mx_r
int dns_mx_r(struct dns_transmit *, struct dns_result *, const char *)
Definition: dns_mx.c:40
dns_resolve
int dns_resolve(struct dns_transmit *, const char *, uint16)
Definition: dns_resolve.c:33
dns_mx::name
char * name
Definition: dns.h:124
dns_transmit::pos
unsigned int pos
Definition: dns.h:109
dns_ip6_packet
int dns_ip6_packet(struct dns_result *, const char *, unsigned int)
Definition: dns_ip6.c:18
dns_name6_domain
void dns_name6_domain(char [DNS_NAME6_DOMAIN], const ipv6addr *)
Definition: dns_name6_domain.c:7
dns_ip4
int dns_ip4(struct dns_result *, const char *)
dns_transmit_io
void dns_transmit_io(const struct dns_transmit *, iopoll_fd *, struct timeval *)
Definition: dns_transmit.c:236
dns_domain_copy
int dns_domain_copy(char **, const char *)
Definition: dns_domain.c:29
dns_result::type
int type
Definition: dns.h:142