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

unix.superglobalmegacorp.com

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