25 #include <sys/socket.h>
26 #include <arpa/inet.h>
28 #define LBL_PTR_MASK 0xC0
29 #define LBL_PTR_OFF_MASK 0x3f
30 #define LBL_PTR(c) ((c)&LBL_PTR_MASK)
32 #define MAX_RECURSION_PTR 20
35 #define DNS_INV_PREFIX ".IN-ADDR.ARPA"
36 #define DNS_INV_PREFIX6 ".IP6.ARPA"
37 #define OLD_DNS_INV_PREFIX6 ".IP6.INT"
46 #define DNS_RCODE_NOERR 0
47 #define DNS_RCODE_EINTRPRT 1
48 #define DNS_RCODE_ESRVFAIL 2
49 #define DNS_RCODE_ENSDMN 3
50 #define DNS_RCODE_ENIMPL 4
51 #define DNS_RCODE_ERFSD 5
57 #define DNS_MAX_SZ 512
59 #define DNS_MAX_LABELS 63
60 #define DNS_MAX_HNAME_LEN 255
61 #define DNS_TTL 86400;
63 #define min(x,y) ((x)<(y))?(x):(y)
80 #define DNS_PKT_HDR_SZ sizeof(dns_pkt_hdr)
83 #define DP_QDCOUNT(dp) ((dp)->pkt_hdr).qdcount
84 #define DP_ANCOUNT(dp) ((dp)->pkt_hdr).ancount
85 #define DP_NSCOUNT(dp) ((dp)->pkt_hdr).nscount
86 #define DP_ARCOUNT(dp) ((dp)->pkt_hdr).arcount
96 #define DNS_PKT_QST_SZ sizeof(dns_pkt_qst)
109 #define DNS_PKT_A_SZ sizeof(dns_pkt_a)
119 #define DNS_PKT_SZ sizeof(dns_pkt)
122 #define DNS_GET_ID(dp) (dp)->pkt_hdr.id
123 #define DNS_GET_QR(dp) (dp)->pkt_hdr.qr
124 #define DNS_GET_OPCODE(dp) (dp)->pkt_hdr.opcode
125 #define DNS_GET_AA(dp) (dp)->pkt_hdr.aa
126 #define DNS_GET_TC(dp) (dp)->pkt_hdr.tc
127 #define DNS_GET_RD(dp) (dp)->pkt_hdr.rd
128 #define DNS_GET_RA(dp) (dp)->pkt_hdr.ra
129 #define DNS_GET_Z(dp) (dp)->pkt_hdr.z
130 #define DNS_GET_RCODE(dp) (dp)->pkt_hdr.rcode
131 #define DNS_GET_QDCOUNT(dp) (dp)->pkt_hdr.qdcount
132 #define DNS_GET_ANCOUNT(dp) (dp)->pkt_hdr.ancount
133 #define DNS_GET_NSCOUNT(dp) (dp)->pkt_hdr.nscount
134 #define DNS_GET_ARCOUNT(dp) (dp)->pkt_hdr.arcount
136 #define DNS_SET_ID(dp,x) (dp)->pkt_hdr.id=x
137 #define DNS_SET_QR(dp,x) (dp)->pkt_hdr.qr=x
138 #define DNS_SET_OPCODE(dp,x) (dp)->pkt_hdr.opcode=x
139 #define DNS_SET_AA(dp,x) (dp)->pkt_hdr.aa=x
140 #define DNS_SET_TC(dp,x) (dp)->pkt_hdr.tc=x
141 #define DNS_SET_RD(dp,x) (dp)->pkt_hdr.rd=x
142 #define DNS_SET_RA(dp,x) (dp)->pkt_hdr.ra=x
143 #define DNS_SET_Z(dp,x) (dp)->pkt_hdr.z=x
144 #define DNS_SET_RCODE(dp,x) (dp)->pkt_hdr.rcode=x
145 #define DNS_SET_QDCOUNT(dp,x) (dp)->pkt_hdr.qdcount=x
146 #define DNS_SET_ANCOUNT(dp,x) (dp)->pkt_hdr.ancount=x
147 #define DNS_SET_NSCOUNT(dp,x) (dp)->pkt_hdr.nscount=x
148 #define DNS_SET_ARCOUNT(dp,x) (dp)->pkt_hdr.arcount=x
150 #define DP_ADD_ANSWER(dp) dns_add_a(&((dp)->pkt_answ));DP_ANCOUNT(dp)+=1;
151 #define DP_ADD_AUTH(dp) dns_add_a(&((dp)->pkt_auth));DP_NSCOUNT(dp)+=1;
152 #define DP_ADD_ADD(dp) dns_add_a(&((dp)->pkt_add));DP_ARCOUNT(dp)+=1;
158 int lbltoname(
char *buf,
char *start_pkt,
char *dst,
int limit);
169 int d_a_u(
char *start_buf,
char *buf,
dns_pkt_a **dpa_orig,
int limit_len);
170 int d_as_u(
char *start_buf,
char *buf,
dns_pkt_a **dpa,
int limit_len,
int count);
dns_pkt_hdr pkt_hdr
Definition: dnslib.h:113
dns_pkt_a * dns_add_a(dns_pkt_a **dpa)
Definition: dnslib.c:822
int d_qst_p(dns_pkt_qst *dpq, char *buf, int limitlen)
Definition: dnslib.c:608
int d_u(char *buf, int pktlen, dns_pkt **dpp)
Definition: dnslib.c:513
uint32_t ttl
Definition: dnslib.h:103
int swapped_straddr_pref(char *src, char *dst, int family)
Definition: dnslib.c:246
uint8_t opcode
Definition: dnslib.h:68
dns_pkt_a * create_dns_pkt_a(void)
Definition: dnslib.c:784
void dns_del_last_qst(dns_pkt *dp)
Definition: dnslib.c:807
dns_pkt_a * pkt_add
Definition: dnslib.h:117
uint8_t ancount
Definition: dnslib.h:76
int read_label_octet(const char *src, char *dst, int limit)
Definition: dnslib.c:64
void dns_a_default_fill(dns_pkt *dp, dns_pkt_a *dpa)
Definition: dnslib.c:841
char rdata[255]
Definition: dnslib.h:105
int nametolbl(char *name, char *dst)
Definition: dnslib.c:267
int add_inv_prefix(char *s, int family)
Definition: dnslib.c:214
uint16_t qclass
Definition: dnslib.h:92
char name[255]
Definition: dnslib.h:100
uint8_t qr
Definition: dnslib.h:67
uint16_t id
Definition: dnslib.h:66
uint8_t z
Definition: dnslib.h:73
uint8_t nscount
Definition: dnslib.h:77
int d_qsts_p(dns_pkt *dp, char *buf, int limitlen)
Definition: dnslib.c:635
uint8_t rcode
Definition: dnslib.h:74
int swapped_straddr(char *src, char *dst)
Definition: dnslib.c:226
int d_hdr_u(char *buf, dns_pkt_hdr *dph)
Definition: dnslib.c:305
uint8_t aa
Definition: dnslib.h:69
int d_a_u(char *start_buf, char *buf, dns_pkt_a **dpa_orig, int limit_len)
Definition: dnslib.c:411
int swap_straddr6(char *src, char *dst)
Definition: dnslib.c:178
uint16_t cl
Definition: dnslib.h:102
uint8_t qdcount
Definition: dnslib.h:75
uint16_t rdlength
Definition: dnslib.h:104
uint8_t arcount
Definition: dnslib.h:78
dns_pkt_a * pkt_auth
Definition: dnslib.h:116
uint8_t ra
Definition: dnslib.h:72
int d_p(dns_pkt *dp, char *buf)
Definition: dnslib.c:730
dns_pkt_qst * create_dns_pkt_qst(void)
Definition: dnslib.c:776
dns_pkt_qst * pkt_qst
Definition: dnslib.h:114
dns_pkt * create_dns_pkt(void)
Definition: dnslib.c:764
char qname[255]
Definition: dnslib.h:90
int d_as_u(char *start_buf, char *buf, dns_pkt_a **dpa, int limit_len, int count)
Definition: dnslib.c:488
dns_pkt_qst * dns_add_qst(dns_pkt *dp)
Definition: dnslib.c:794
int d_qst_u(char *start_buf, char *buf, dns_pkt *dp, int limit_len)
Definition: dnslib.c:353
uint16_t qtype
Definition: dnslib.h:91
void destroy_dns_pkt(dns_pkt *dp)
Definition: dnslib.c:848
int d_as_p(dns_pkt_a *dpa, char *buf, int limitlen, int count)
Definition: dnslib.c:704
uint16_t type
Definition: dnslib.h:101
int swap_straddr(char *src, char *dst)
Definition: dnslib.c:136
int d_hdr_p(dns_pkt *dp, char *buf)
Definition: dnslib.c:564
dns_pkt_a * pkt_answ
Definition: dnslib.h:115
int d_qsts_u(char *start_buf, char *buf, dns_pkt *dp, int limit_len)
Definition: dnslib.c:390
int rm_inv_prefix(char *src, char *dst)
Definition: dnslib.c:190
uint8_t tc
Definition: dnslib.h:70
int family
Definition: if.c:34
#define DNS_MAX_HNAME_LEN
Definition: dnslib.h:60
uint8_t rd
Definition: dnslib.h:71
struct dns_pkt_qst * next
Definition: dnslib.h:93
struct dns_pkt_a * next
Definition: dnslib.h:106
int lbltoname(char *buf, char *start_pkt, char *dst, int limit)
Definition: dnslib.c:85
int d_a_p(dns_pkt_a *dpa, char *buf, int limitlen)
Definition: dnslib.c:652
int getlblptr(char *buf)
Definition: dnslib.c:34
struct dns_pkt_hdr dns_pkt_hdr