Annotation of 43BSD/etc/named/tools/ns.lookup/src/skip.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *******************************************************************************
        !             3:  *
        !             4:  *  skip.c --
        !             5:  *
        !             6:  *     Routines to skip over portions of a query buffer.
        !             7:  *
        !             8:  *     Note: this file has been submitted for inclusion in
        !             9:  *     BIND resolver library. When this has been done, this file
        !            10:  *     is no longer necessary (assuming there haven't been any
        !            11:  *     changes).
        !            12:  *
        !            13:  *     Adapted from 4.3BSD BIND res_debug.c
        !            14:  *
        !            15:  *     Copyright (c) 1985 Regents of the University of California.
        !            16:  *     All rights reserved.  The Berkeley software License Agreement
        !            17:  *     specifies the terms and conditions for redistribution.
        !            18:  *
        !            19:  *******************************************************************************
        !            20:  */
        !            21: 
        !            22: #ifndef lint
        !            23: static char sccsid[] = "@(#)skip.c     5.1 (Berkeley) 11/29/85";
        !            24: #endif not lint
        !            25: 
        !            26: #include <sys/types.h>
        !            27: #include <netinet/in.h>
        !            28: #include <stdio.h>
        !            29: #include <arpa/nameser.h>
        !            30: 
        !            31: char *res_skip_rr();
        !            32: 
        !            33: 
        !            34: /*
        !            35:  *******************************************************************************
        !            36:  *
        !            37:  *  res_skip --
        !            38:  *
        !            39:  *     Skip the contents of a query.
        !            40:  *
        !            41:  *     Interpretation of numFieldsToSkip argument:
        !            42:  *            res_skip returns pointer to:
        !            43:  *     1 ->  start of question records.
        !            44:  *     2 ->  start of authoritative answer records.
        !            45:  *     3 ->  start of additional records.
        !            46:  *     4 ->  first byte after end of additional records.
        !            47:  *
        !            48:  *   Results:
        !            49:  *     (address)       - success operation.
        !            50:  *     NULL            - a resource record had an incorrect format.
        !            51:  *
        !            52:  *******************************************************************************
        !            53:  */
        !            54: 
        !            55: char *
        !            56: res_skip(msg, numFieldsToSkip)
        !            57:        char *msg;
        !            58:        int numFieldsToSkip;
        !            59: {
        !            60:        register char *cp;
        !            61:        register HEADER *hp;
        !            62:        register int tmp;
        !            63:        register int n;
        !            64: 
        !            65:        /*
        !            66:         * Skip the header fields.
        !            67:         */
        !            68:        hp = (HEADER *)msg;
        !            69:        cp = msg + sizeof(HEADER);
        !            70: 
        !            71:        /*
        !            72:         * skip question records.
        !            73:         */
        !            74:        if (n = ntohs(hp->qdcount) ) {
        !            75:                while (--n >= 0) {
        !            76:                        tmp = dn_skip(cp);
        !            77:                        if (tmp == -1) return(NULL);
        !            78:                        cp += tmp;
        !            79:                        cp += sizeof(u_short);  /* type         */
        !            80:                        cp += sizeof(u_short);  /* class        */
        !            81:                }
        !            82:        }
        !            83:        if (--numFieldsToSkip <= 0) return(cp);
        !            84: 
        !            85:        /*
        !            86:         * skip authoritative answer records
        !            87:         */
        !            88:        if (n = ntohs(hp->ancount)) {
        !            89:                while (--n >= 0) {
        !            90:                        cp = res_skip_rr(cp);
        !            91:                        if (cp == NULL) return(NULL);
        !            92:                }
        !            93:        }
        !            94:        if (--numFieldsToSkip == 0) return(cp);
        !            95: 
        !            96:        /*
        !            97:         * skip name server records
        !            98:         */
        !            99:        if (n = ntohs(hp->nscount)) {
        !           100:                while (--n >= 0) {
        !           101:                        cp = res_skip_rr(cp);
        !           102:                        if (cp == NULL) return(NULL);
        !           103:                }
        !           104:        }
        !           105:        if (--numFieldsToSkip == 0) return(cp);
        !           106: 
        !           107:        /*
        !           108:         * skip additional records
        !           109:         */
        !           110:        if (n = ntohs(hp->arcount)) {
        !           111:                while (--n >= 0) {
        !           112:                        cp = res_skip_rr(cp);
        !           113:                        if (cp == NULL) return(NULL);
        !           114:                }
        !           115:        }
        !           116: 
        !           117:        return(cp);
        !           118: }
        !           119: 
        !           120: 
        !           121: /*
        !           122:  *******************************************************************************
        !           123:  *
        !           124:  *  res_skip_rr --
        !           125:  *
        !           126:  *     Skip over resource record fields.
        !           127:  *
        !           128:  *   Results:
        !           129:  *     (address)       - success operation.
        !           130:  *     NULL            - a resource record had an incorrect format.
        !           131:  *******************************************************************************
        !           132:  */
        !           133: 
        !           134: char *
        !           135: res_skip_rr(cp)
        !           136:        char *cp;
        !           137: {
        !           138:        int tmp;
        !           139:        int dlen;
        !           140: 
        !           141:        if ((tmp = dn_skip(cp)) == -1)
        !           142:                return (NULL);                  /* compression error */
        !           143:        cp += tmp;
        !           144:        cp += sizeof(u_short);  /*      type    */
        !           145:        cp += sizeof(u_short);  /*      class   */
        !           146:        cp += sizeof(u_long);   /*      ttl     */
        !           147:        dlen = getshort(cp);
        !           148:        cp += sizeof(u_short);  /*      dlen    */
        !           149:        cp += dlen;
        !           150:        return (cp);
        !           151: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.