fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
dns_cname.c
Go to the documentation of this file.
1#include "stralloc.h"
2#include "uint_t.h"
3#include "byte.h"
4#include "ip.h"
5#include "case.h"
6#include "dnsresolv.h"
7
14static char *q = 0;
15
16int dns_cname_packet(stralloc *out,const char *buf,unsigned int len)
17{
18 unsigned int pos;
19 char header[12];
20 uint16 numanswers;
21 uint16 datalen;
22 int ranswers = 0;
23
24 if (!stralloc_copys(out,"")) return DNS_MEM;
25
26 pos = dns_packet_copy(buf,len,0,header,12); if (!pos) return DNS_ERR;
27 uint16_unpack_big(header + 6,&numanswers);
28 pos = dns_packet_skipname(buf,len,pos); if (!pos) return DNS_ERR;
29 pos += 4;
30
31 while (numanswers--) {
32 pos = dns_packet_skipname(buf,len,pos); if (!pos) return DNS_ERR;
33 pos = dns_packet_copy(buf,len,pos,header,10); if (!pos) return DNS_ERR;
34 uint16_unpack_big(header + 8,&datalen);
35 if (byte_equal(header,2,DNS_T_CNAME))
36 if (byte_equal(header + 2,2,DNS_C_IN)) {
37 if (!dns_packet_getname(buf,len,pos,&q)) return DNS_ERR;
38 if (dns_domain_todot_cat(out,q) <= 0) return DNS_ERR;
39 }
40 pos += datalen;
41 ++ranswers;
42 }
43
44 return ranswers;
45}
46
48{
49 int rc;
50
51 if (dns_domain_fromdot(&q,fqdn->s,fqdn->len) <= 0) return DNS_ERR;
52 if (dns_resolve(q,DNS_T_CNAME) < 0) return DNS_ERR;
56 if (case_equals(out->s,fqdn->s)) rc = -6; // loop DNS_HARD
57
58 return rc;
59}
int dns_cname(stralloc *out, stralloc *fqdn)
Definition: dns_cname.c:47
int dns_cname_packet(stralloc *out, const char *buf, unsigned int len)
Definition: dns_cname.c:16
#define case_equals(s, t)
Definition: case.h:14
additional types and pack routines
uint16_t uint16
Definition: uint_t.h:29
void uint16_unpack_big(char[16], uint16 *)
#define byte_equal(s, n, t)
Definition: byte.h:18
void dns_transmit_free(struct dns_transmit *)
Definition: dns_transmit.c:105
unsigned int dns_packet_copy(const char *, unsigned int, unsigned int, char *, unsigned int)
Definition: dns_packet.c:12
#define DNS_ERR
Definition: dnsresolv.h:44
int dns_domain_fromdot(char **, const char *, unsigned int)
Definition: dns_dfd.c:13
int dns_domain_todot_cat(stralloc *, const char *)
Definition: dns_dtda.c:11
#define DNS_C_IN
Definition: dnsresolv.h:60
int dns_resolve(const char *, const char *)
unsigned int dns_packet_skipname(const char *, unsigned int, unsigned int)
Definition: dns_packet.c:22
void dns_domain_free(char **)
Definition: dns_domain.c:24
#define DNS_T_CNAME
Definition: dnsresolv.h:65
unsigned int dns_packet_getname(const char *, unsigned int, unsigned int, char **)
Definition: dns_packet.c:39
#define DNS_MEM
Definition: dnsresolv.h:43
struct dns_transmit dns_resolve_tx
Definition: dns_resolve.c:14
int stralloc_copys(stralloc *, const char *)
Definition: stralloc.c:79
unsigned int packetlen
Definition: dnsresolv.h:103
char * packet
Definition: dnsresolv.h:102
size_t len
Definition: stralloc.h:19
char * s
Definition: stralloc.h:18