Annotation of 43BSDReno/usr.sbin/named/tools/nslookup/skip.c, revision 1.1

1.1     ! root        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.8 (Berkeley) 6/21/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: #include <sys/types.h>
        !            42: #include <netinet/in.h>
        !            43: #include <stdio.h>
        !            44: #include <arpa/nameser.h>
        !            45: 
        !            46: char *res_skip_rr();
        !            47: 
        !            48: 
        !            49: /*
        !            50:  *******************************************************************************
        !            51:  *
        !            52:  *  res_skip --
        !            53:  *
        !            54:  *     Skip the contents of a query.
        !            55:  *
        !            56:  *     Interpretation of numFieldsToSkip argument:
        !            57:  *            res_skip returns pointer to:
        !            58:  *     1 ->  start of question records.
        !            59:  *     2 ->  start of authoritative answer records.
        !            60:  *     3 ->  start of additional records.
        !            61:  *     4 ->  first byte after end of additional records.
        !            62:  *
        !            63:  *   Results:
        !            64:  *     (address)       - success operation.
        !            65:  *     NULL            - a resource record had an incorrect format.
        !            66:  *
        !            67:  *******************************************************************************
        !            68:  */
        !            69: 
        !            70: char *
        !            71: res_skip(msg, numFieldsToSkip, eom)
        !            72:        char *msg;
        !            73:        int numFieldsToSkip;
        !            74:        char *eom;
        !            75: {
        !            76:        register char *cp;
        !            77:        register HEADER *hp;
        !            78:        register int tmp;
        !            79:        register int n;
        !            80: 
        !            81:        /*
        !            82:         * Skip the header fields.
        !            83:         */
        !            84:        hp = (HEADER *)msg;
        !            85:        cp = msg + sizeof(HEADER);
        !            86: 
        !            87:        /*
        !            88:         * skip question records.
        !            89:         */
        !            90:        if (n = ntohs(hp->qdcount) ) {
        !            91:                while (--n >= 0 && cp < eom) {
        !            92:                        tmp = dn_skipname(cp, eom);
        !            93:                        if (tmp == -1) return(NULL);
        !            94:                        cp += tmp;
        !            95:                        cp += sizeof(u_short);  /* type         */
        !            96:                        cp += sizeof(u_short);  /* class        */
        !            97:                }
        !            98:        }
        !            99:        if (--numFieldsToSkip <= 0) return(cp);
        !           100: 
        !           101:        /*
        !           102:         * skip authoritative answer records
        !           103:         */
        !           104:        if (n = ntohs(hp->ancount)) {
        !           105:                while (--n >= 0 && cp < eom) {
        !           106:                        cp = res_skip_rr(cp, eom);
        !           107:                        if (cp == NULL) return(NULL);
        !           108:                }
        !           109:        }
        !           110:        if (--numFieldsToSkip == 0) return(cp);
        !           111: 
        !           112:        /*
        !           113:         * skip name server records
        !           114:         */
        !           115:        if (n = ntohs(hp->nscount)) {
        !           116:                while (--n >= 0 && cp < eom) {
        !           117:                        cp = res_skip_rr(cp, eom);
        !           118:                        if (cp == NULL) return(NULL);
        !           119:                }
        !           120:        }
        !           121:        if (--numFieldsToSkip == 0) return(cp);
        !           122: 
        !           123:        /*
        !           124:         * skip additional records
        !           125:         */
        !           126:        if (n = ntohs(hp->arcount)) {
        !           127:                while (--n >= 0 && cp < eom) {
        !           128:                        cp = res_skip_rr(cp, eom);
        !           129:                        if (cp == NULL) return(NULL);
        !           130:                }
        !           131:        }
        !           132: 
        !           133:        return(cp);
        !           134: }
        !           135: 
        !           136: 
        !           137: /*
        !           138:  *******************************************************************************
        !           139:  *
        !           140:  *  res_skip_rr --
        !           141:  *
        !           142:  *     Skip over resource record fields.
        !           143:  *
        !           144:  *   Results:
        !           145:  *     (address)       - success operation.
        !           146:  *     NULL            - a resource record had an incorrect format.
        !           147:  *******************************************************************************
        !           148:  */
        !           149: 
        !           150: char *
        !           151: res_skip_rr(cp, eom)
        !           152:        char *cp;
        !           153:        char *eom;
        !           154: {
        !           155:        int tmp;
        !           156:        int dlen;
        !           157: 
        !           158:        if ((tmp = dn_skipname(cp, eom)) == -1)
        !           159:                return (NULL);                  /* compression error */
        !           160:        cp += tmp;
        !           161:        if ((cp + RRFIXEDSZ) > eom)
        !           162:                return (NULL);
        !           163:        cp += sizeof(u_short);  /*      type    */
        !           164:        cp += sizeof(u_short);  /*      class   */
        !           165:        cp += sizeof(u_long);   /*      ttl     */
        !           166:        dlen = _getshort(cp);
        !           167:        cp += sizeof(u_short);  /*      dlen    */
        !           168:        cp += dlen;
        !           169:        if ((cp + dlen) > eom)
        !           170:                return (NULL);
        !           171:        return (cp);
        !           172: }

unix.superglobalmegacorp.com

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