home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / NETWORK / ISP / bind.4.8.3.lzh / BIND483 / TOOLS / NSLOOKUP / skip.c < prev    next >
Text File  |  1994-09-23  |  4KB  |  178 lines

  1. /*
  2.  * Copyright (c) 1985 Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted provided
  6.  * that: (1) source distributions retain this entire copyright notice and
  7.  * comment, and (2) distributions including binaries display the following
  8.  * acknowledgement:  ``This product includes software developed by the
  9.  * University of California, Berkeley and its contributors'' in the
  10.  * documentation or other materials provided with the distribution and in
  11.  * all advertising materials mentioning features or use of this software.
  12.  * Neither the name of the University nor the names of its contributors may
  13.  * be used to endorse or promote products derived from this software without
  14.  * specific prior written permission.
  15.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  16.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  17.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18.  */
  19.  
  20. #ifndef lint
  21. static char sccsid[] = "@(#)skip.c    5.9 (Berkeley) 8/3/90";
  22. #endif /* not lint */
  23.  
  24. /*
  25.  *******************************************************************************
  26.  *
  27.  *  skip.c --
  28.  *
  29.  *    Routines to skip over portions of a query buffer.
  30.  *
  31.  *    Note: this file has been submitted for inclusion in
  32.  *    BIND resolver library. When this has been done, this file
  33.  *    is no longer necessary (assuming there haven't been any
  34.  *    changes).
  35.  *
  36.  *    Adapted from 4.3BSD BIND res_debug.c
  37.  *
  38.  *******************************************************************************
  39.  */
  40.  
  41. #ifdef OSK
  42. #include <types.h>
  43. #include <in.h>
  44. #else
  45. #include <sys/types.h>
  46. #include <netinet/in.h>
  47. #endif
  48. #include <stdio.h>
  49. #include <arpa/nameser.h>
  50.  
  51. char *res_skip_rr();
  52.  
  53.  
  54. /*
  55.  *******************************************************************************
  56.  *
  57.  *  res_skip --
  58.  *
  59.  *     Skip the contents of a query.
  60.  *
  61.  *     Interpretation of numFieldsToSkip argument:
  62.  *            res_skip returns pointer to:
  63.  *        1 ->  start of question records.
  64.  *        2 ->  start of authoritative answer records.
  65.  *        3 ->  start of additional records.
  66.  *        4 ->  first byte after end of additional records.
  67.  *
  68.  *   Results:
  69.  *    (address)    - success operation.
  70.  *      NULL         - a resource record had an incorrect format.
  71.  *
  72.  *******************************************************************************
  73.  */
  74.  
  75. char *
  76. res_skip(msg, numFieldsToSkip, eom)
  77.     char *msg;
  78.     int numFieldsToSkip;
  79.     char *eom;
  80. {
  81.     register char *cp;
  82.     register HEADER *hp;
  83.     register int tmp;
  84.     register int n;
  85.  
  86.     /*
  87.      * Skip the header fields.
  88.      */
  89.     hp = (HEADER *)msg;
  90.     cp = msg + sizeof(HEADER);
  91.  
  92.     /*
  93.      * skip question records.
  94.      */
  95.     if (n = ntohs(hp->qdcount) ) {
  96.         while (--n >= 0 && cp < eom) {
  97.             tmp = dn_skipname(cp, eom);
  98.             if (tmp == -1) return(NULL);
  99.             cp += tmp;
  100.             cp += sizeof(u_short);    /* type     */
  101.             cp += sizeof(u_short);    /* class     */
  102.         }
  103.     }
  104.     if (--numFieldsToSkip <= 0) return(cp);
  105.  
  106.     /*
  107.      * skip authoritative answer records
  108.      */
  109.     if (n = ntohs(hp->ancount)) {
  110.         while (--n >= 0 && cp < eom) {
  111.             cp = res_skip_rr(cp, eom);
  112.             if (cp == NULL) return(NULL);
  113.         }
  114.     }
  115.     if (--numFieldsToSkip == 0) return(cp);
  116.  
  117.     /*
  118.      * skip name server records
  119.      */
  120.     if (n = ntohs(hp->nscount)) {
  121.         while (--n >= 0 && cp < eom) {
  122.             cp = res_skip_rr(cp, eom);
  123.             if (cp == NULL) return(NULL);
  124.         }
  125.     }
  126.     if (--numFieldsToSkip == 0) return(cp);
  127.  
  128.     /*
  129.      * skip additional records
  130.      */
  131.     if (n = ntohs(hp->arcount)) {
  132.         while (--n >= 0 && cp < eom) {
  133.             cp = res_skip_rr(cp, eom);
  134.             if (cp == NULL) return(NULL);
  135.         }
  136.     }
  137.  
  138.     return(cp);
  139. }
  140.  
  141.  
  142. /*
  143.  *******************************************************************************
  144.  *
  145.  *  res_skip_rr --
  146.  *
  147.  *     Skip over resource record fields.
  148.  *
  149.  *   Results:
  150.  *    (address)    - success operation.
  151.  *      NULL         - a resource record had an incorrect format.
  152.  *******************************************************************************
  153.  */
  154.  
  155. char *
  156. res_skip_rr(cp, eom)
  157.     char *cp;
  158.     char *eom;
  159. {
  160.     int tmp;
  161.     int dlen;
  162.  
  163.     if ((tmp = dn_skipname(cp, eom)) == -1)
  164.         return (NULL);            /* compression error */
  165.     cp += tmp;
  166.     if ((cp + RRFIXEDSZ) > eom)
  167.         return (NULL);
  168.     cp += sizeof(u_short);    /*     type     */
  169.     cp += sizeof(u_short);    /*     class     */
  170.     cp += sizeof(u_long);    /*     ttl     */
  171.     dlen = _getshort(cp);
  172.     cp += sizeof(u_short);    /*     dlen     */
  173.     cp += dlen;
  174.     if (cp > eom)
  175.         return (NULL);
  176.     return (cp);
  177. }
  178.