BSD 4_3_Net_2 release
[unix-history] / usr / src / lib / libc / net / res_comp.c
index efe5163..42b2e8b 100644 (file)
@@ -2,28 +2,44 @@
  * 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: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement:  ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * 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
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_comp.c 6.18 (Berkeley) 6/27/90";
+static char sccsid[] = "@(#)res_comp.c 6.22 (Berkeley) 3/19/91";
 #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 dn_find();
 
 
 static dn_find();
 
@@ -35,7 +51,8 @@ static dn_find();
  * 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;
@@ -44,7 +61,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
@@ -78,7 +95,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;
@@ -114,16 +131,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) {
@@ -191,13 +208,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
@@ -307,21 +324,24 @@ _getlong(msgp)
        return (u | *p);
 }
 
        return (u | *p);
 }
 
-
-putshort(s, msgp)
+void
+#ifdef __STDC__
+__putshort(register u_short s, register u_char *msgp)
+#else
+__putshort(s, msgp)
        register u_short s;
        register u_char *msgp;
        register u_short s;
        register u_char *msgp;
+#endif
 {
 {
-
        msgp[1] = s;
        msgp[0] = s >> 8;
 }
 
        msgp[1] = s;
        msgp[0] = s >> 8;
 }
 
-putlong(l, msgp)
+void
+__putlong(l, msgp)
        register u_long l;
        register u_char *msgp;
 {
        register u_long l;
        register u_char *msgp;
 {
-
        msgp[3] = l;
        msgp[2] = (l >>= 8);
        msgp[1] = (l >>= 8);
        msgp[3] = l;
        msgp[2] = (l >>= 8);
        msgp[1] = (l >>= 8);