Question about source code.

Mark.Andrews at nominum.com Mark.Andrews at nominum.com
Thu Sep 28 12:06:10 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 point
> er 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 zon
> e*/
> 
>  n = ns_skiprr(cp, eom, ns_s_qd, ntohs(hp->qdcount));/*I've looked up this fu
> nc,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 z
> one.
> 
>  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;

	This is the start of last RR.
	We have only skipped "hp->arcount - 1" records so far in the
	additional section, so there is one to go.

> 
>  start = cp;
>  n = dn_skipname(cp, eom);     <<---- Skip a domain name again.This is my que
> stion.cp is pointed 
>                                 the tail of the datagram,Why we need to skip 
> domain again?

	Because this is the owner name of what may be the TSIG record.

>  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!
> 
> 
--
Mark Andrews, Nominum Inc.
1 Seymour St., Dundas Valley, NSW 2117, Australia
PHONE: +61 2 9871 4742                 INTERNET: Mark.Andrews at nominum.com



More information about the bind-users mailing list