- if (qu->cnameoff<0 &&
- (qu->typei->type & adns__rrt_typemask) != adns_r_cname &&
- rrtype == adns_r_cname) { /* Ignore second and subsequent CNAMEs */
- st= adns__get_domain_perm(ads,qu,serv, dgram,dglen,
- &rdstart,rdstart+rdlength,&qu->cnameoff);
- if (st) { adns__query_fail(ads,qu,st); return; }
- if (qu->cnameoff==-1) goto x_truncated;
- /* If we find the answer section truncated after this point we restart
- * the query at the CNAME; if beforehand then we obviously have to use
- * TCP. If there is no truncation we can use the whole answer if
- * it contains the relevant info.
- */
+ if (rrtype == adns_r_cname &&
+ (qu->typei->type & adns__rrt_typemask) != adns_r_cname) {
+ if (!qu->cname_str) { /* Ignore second and subsequent CNAMEs */
+ qu->cname_begin= rdstart;
+ qu->cname_dgram= dgram;
+ qu->cname_dglen= dglen;
+ st= adns__parse_domain(ads,serv,&qu->vb,qu->flags,
+ dgram,dglen, &rdstart,rdstart+rdlength);
+ if (!vb.used) goto x_truncated;
+ if (st) { adns__query_fail(ads,qu,st); return; }
+ qu->answer->cname= adns__savestring(qu);
+ if (!qu->answer->cname) return;
+ /* If we find the answer section truncated after this point we restart
+ * the query at the CNAME; if beforehand then we obviously have to use
+ * TCP. If there is no truncation we can use the whole answer if
+ * it contains the relevant info.
+ */
+ } else {
+ adns__debug(ads,serv,qu,"ignoring duplicate CNAME (%s, as well as %s)",
+ adns__diag_domain(ads,serv,&qu->vb,qu->flags,
+ dgram,dglen, rdstart,rdstart+rdlength),
+ qu->cname_str);
+ }