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

Defined functions

res_skip_rr defined in line 151; used 4 times

Defined variables

sccsid defined in line 21; never used
Last modified: 1993-04-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2476
Valid CSS Valid XHTML 1.0 Strict