Question about source code.

R.Z. Pan rzpan at sitechasia.com
Thu Sep 28 08:21:20 UTC 2000


Hi,please check these code below:(I've added some comments with red color.)

u_char *
ns_find_tsig(u_char *msg, u_char *eom) {                   /*msg is the pointer of a DNS                                                                             datagram,eom is msg+512; */
 HEADER *hp = (HEADER *)msg;
 int n, type;
 u_char *cp = msg, *start;

 if (msg == NULL || eom == NULL || msg > eom)
  return (NULL);

 if (cp + HFIXEDSZ >= eom)
  return (NULL);

 if (hp->arcount == 0)
  return (NULL);

 cp += HFIXEDSZ;          /* HFIXEDSZ is 12,so,cp pointed to the question zone*/

 n = ns_skiprr(cp, eom, ns_s_qd, ntohs(hp->qdcount));/*I've looked up this func,it means skip                                                                         the question zone.Of course,a                                                                         question zone include a request 
                                                          name,a request type and a request type. */
 if (n < 0)    
  return (NULL);
 cp += n;                <------ Now,the cp pointed to the tail of question zone.

 n = ns_skiprr(cp, eom, ns_s_an, ntohs(hp->ancount));
 if (n < 0)
  return (NULL);
 cp += n;

 n = ns_skiprr(cp, eom, ns_s_ns, ntohs(hp->nscount));
 if (n < 0)
  return (NULL);
 cp += n;

 n = ns_skiprr(cp, eom, ns_s_ar, ntohs(hp->arcount) - 1);
 if (n < 0)
  return (NULL);
 cp += n;

 start = cp;
 n = dn_skipname(cp, eom);     <<---- Skip a domain name again.This is my question.cp is pointed 
                                the tail of the datagram,Why we need to skip domain again?
 if (n < 0)
  return (NULL);
 cp += n;
 if (cp + INT16SZ >= eom)
  return (NULL);

 GETSHORT(type, cp);
 if (type != ns_t_tsig)
  return (NULL);
 return (start);
}

Is there anyone can give some idea about this?Thanks a lot!



More information about the bind-users mailing list