integrate changes from bind 4.9 (most of them); continue to use address
[unix-history] / usr / src / lib / libc / net / res_comp.c
index ce3e0eb..8dd1f75 100644 (file)
@@ -1,27 +1,42 @@
-/*
+/*-
  * Copyright (c) 1985 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1985 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ * 
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ * -
+ * --Copyright--
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_comp.c 6.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)res_comp.c 6.23 (Berkeley) %G%";
+static char rcsid[] = "$Id: res_comp.c,v 4.9.1.1 1993/05/02 22:43:03 vixie Rel $";
 #endif /* LIBC_SCCS and not lint */
 
 #endif /* LIBC_SCCS and not lint */
 
-#include <sys/types.h>
-#include <stdio.h>
+#include <sys/param.h>
 #include <arpa/nameser.h>
 #include <arpa/nameser.h>
+#include <netinet/in.h>
+#include <resolv.h>
+#include <stdio.h>
+
+static int dn_find();
 
 /*
  * Expand compressed domain name 'comp_dn' to full domain name.
 
 /*
  * Expand compressed domain name 'comp_dn' to full domain name.
@@ -31,7 +46,8 @@ static char sccsid[] = "@(#)res_comp.c        6.15 (Berkeley) %G%";
  * Return size of compressed name or -1 if there was an error.
  */
 dn_expand(msg, eomorig, comp_dn, exp_dn, length)
  * Return size of compressed name or -1 if there was an error.
  */
 dn_expand(msg, eomorig, comp_dn, exp_dn, length)
-       u_char *msg, *eomorig, *comp_dn, *exp_dn;
+       const u_char *msg, *eomorig, *comp_dn;
+       u_char *exp_dn;
        int length;
 {
        register u_char *cp, *dn;
        int length;
 {
        register u_char *cp, *dn;
@@ -40,7 +56,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
        int len = -1, checked = 0;
 
        dn = exp_dn;
        int len = -1, checked = 0;
 
        dn = exp_dn;
-       cp = comp_dn;
+       cp = (u_char *)comp_dn;
        eom = exp_dn + length;
        /*
         * fetch next label in domain name
        eom = exp_dn + length;
        /*
         * fetch next label in domain name
@@ -61,7 +77,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
                        checked += n + 1;
                        while (--n >= 0) {
                                if ((c = *cp++) == '.') {
                        checked += n + 1;
                        while (--n >= 0) {
                                if ((c = *cp++) == '.') {
-                                       if (dn+n+1 >= eom)
+                                       if (dn + n + 2 >= eom)
                                                return (-1);
                                        *dn++ = '\\';
                                }
                                                return (-1);
                                        *dn++ = '\\';
                                }
@@ -74,7 +90,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
                case INDIR_MASK:
                        if (len < 0)
                                len = cp - comp_dn + 1;
                case INDIR_MASK:
                        if (len < 0)
                                len = cp - comp_dn + 1;
-                       cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff));
+                       cp = (u_char *)msg + (((n & 0x3f) << 8) | (*cp & 0xff));
                        if (cp < msg || cp >= eomorig)  /* out of range */
                                return(-1);
                        checked += 2;
                        if (cp < msg || cp >= eomorig)  /* out of range */
                                return(-1);
                        checked += 2;
@@ -110,16 +126,16 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
  * is NULL, we don't update the list.
  */
 dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
  * is NULL, we don't update the list.
  */
 dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
-       u_char *exp_dn, *comp_dn;
+       const u_char *exp_dn;
+       u_char *comp_dn, **dnptrs, **lastdnptr;
        int length;
        int length;
-       u_char **dnptrs, **lastdnptr;
 {
        register u_char *cp, *dn;
        register int c, l;
        u_char **cpp, **lpp, *sp, *eob;
        u_char *msg;
 
 {
        register u_char *cp, *dn;
        register int c, l;
        u_char **cpp, **lpp, *sp, *eob;
        u_char *msg;
 
-       dn = exp_dn;
+       dn = (u_char *)exp_dn;
        cp = comp_dn;
        eob = cp + length;
        if (dnptrs != NULL) {
        cp = comp_dn;
        eob = cp + length;
        if (dnptrs != NULL) {
@@ -187,13 +203,13 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
 /*
  * Skip over a compressed domain name. Return the size or -1.
  */
 /*
  * Skip over a compressed domain name. Return the size or -1.
  */
-dn_skipname(comp_dn, eom)
-       u_char *comp_dn, *eom;
+__dn_skipname(comp_dn, eom)
+       const u_char *comp_dn, *eom;
 {
        register u_char *cp;
        register int n;
 
 {
        register u_char *cp;
        register int n;
 
-       cp = comp_dn;
+       cp = (u_char *)comp_dn;
        while (cp < eom && (n = *cp++)) {
                /*
                 * check for indirection
        while (cp < eom && (n = *cp++)) {
                /*
                 * check for indirection
@@ -218,7 +234,7 @@ dn_skipname(comp_dn, eom)
  * dnptrs is the pointer to the first name on the list,
  * not the pointer to the start of the message.
  */
  * dnptrs is the pointer to the first name on the list,
  * not the pointer to the start of the message.
  */
-static
+static int
 dn_find(exp_dn, msg, dnptrs, lastdnptr)
        u_char *exp_dn, *msg;
        u_char **dnptrs, **lastdnptr;
 dn_find(exp_dn, msg, dnptrs, lastdnptr)
        u_char *exp_dn, *msg;
        u_char **dnptrs, **lastdnptr;
@@ -274,52 +290,40 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr)
 
 u_short
 _getshort(msgp)
 
 u_short
 _getshort(msgp)
-       u_char *msgp;
+       register u_char *msgp;
 {
 {
-       register u_char *p = (u_char *) msgp;
-#ifdef vax
-       /*
-        * vax compiler doesn't put shorts in registers
-        */
-       register u_long u;
-#else
-       register u_short u;
-#endif
+       register u_int16_t u;
 
 
-       u = *p++ << 8;
-       return ((u_short)(u | *p));
+       GETSHORT(u, msgp);
+       return (u);
 }
 
 }
 
-u_long
+u_int32_t
 _getlong(msgp)
 _getlong(msgp)
-       u_char *msgp;
+       register u_char *msgp;
 {
 {
-       register u_char *p = (u_char *) msgp;
-       register u_long u;
+       register u_int32_t u;
 
 
-       u = *p++; u <<= 8;
-       u |= *p++; u <<= 8;
-       u |= *p++; u <<= 8;
-       return (u | *p);
+       GETLONG(u, msgp);
+       return (u);
 }
 
 }
 
-
-putshort(s, msgp)
-       register u_short s;
+void
+#if defined(__STDC__) || defined(__cplusplus)
+__putshort(register u_short s, register u_char *msgp)
+#else
+__putshort(s, msgp)
+       register u_int16_t s;
        register u_char *msgp;
        register u_char *msgp;
+#endif
 {
 {
-
-       msgp[1] = s;
-       msgp[0] = s >> 8;
+       PUTSHORT(s, msgp);
 }
 
 }
 
-putlong(l, msgp)
-       register u_long l;
+void
+__putlong(l, msgp)
+       register u_int32_t l;
        register u_char *msgp;
 {
        register u_char *msgp;
 {
-
-       msgp[3] = l;
-       msgp[2] = (l >>= 8);
-       msgp[1] = (l >>= 8);
-       msgp[0] = l >> 8;
+       PUTLONG(l, msgp);
 }
 }