BSD 4_4 release
[unix-history] / usr / src / lib / libc / net / res_query.c
index dface1e..4980af1 100644 (file)
@@ -1,37 +1,72 @@
-/*
- * Copyright (c) 1988 Regents of the University of California.
- * All rights reserved.
+/*-
+ * Copyright (c) 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * 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.
  *
  *
- * 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.
+ * 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.
+ * -
+ * 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_query.c        5.7 (Berkeley) 6/1/90";
+static char sccsid[] = "@(#)res_query.c        8.1 (Berkeley) 6/4/93";
+static char rcsid[] = "$Id: res_query.c,v 1.1 1993/06/01 09:42:14 vixie Exp vixie $";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/param.h>
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/param.h>
-#include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/in.h>
-#include <ctype.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
 #include <netdb.h>
 #include <netdb.h>
+#include <resolv.h>
 #include <stdio.h>
 #include <stdio.h>
+#include <ctype.h>
 #include <errno.h>
 #include <errno.h>
+#include <stdlib.h>
 #include <string.h>
 #include <string.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
 
 #if PACKETSZ > 1024
 #define MAXPACKET      PACKETSZ
 
 #if PACKETSZ > 1024
 #define MAXPACKET      PACKETSZ
@@ -39,7 +74,6 @@ static char sccsid[] = "@(#)res_query.c       5.7 (Berkeley) 6/1/90";
 #define MAXPACKET      1024
 #endif
 
 #define MAXPACKET      1024
 #endif
 
-extern int errno;
 int h_errno;
 
 /*
 int h_errno;
 
 /*
@@ -65,7 +99,7 @@ res_query(name, class, type, answer, anslen)
                return (-1);
 #ifdef DEBUG
        if (_res.options & RES_DEBUG)
                return (-1);
 #ifdef DEBUG
        if (_res.options & RES_DEBUG)
-               printf("res_query(%s, %d, %d)\n", name, class, type);
+               printf(";; res_query(%s, %d, %d)\n", name, class, type);
 #endif
        n = res_mkquery(QUERY, name, class, type, (char *)NULL, 0, NULL,
            buf, sizeof(buf));
 #endif
        n = res_mkquery(QUERY, name, class, type, (char *)NULL, 0, NULL,
            buf, sizeof(buf));
@@ -73,16 +107,16 @@ res_query(name, class, type, answer, anslen)
        if (n <= 0) {
 #ifdef DEBUG
                if (_res.options & RES_DEBUG)
        if (n <= 0) {
 #ifdef DEBUG
                if (_res.options & RES_DEBUG)
-                       printf("res_query: mkquery failed\n");
+                       printf(";; res_query: mkquery failed\n");
 #endif
                h_errno = NO_RECOVERY;
                return (n);
        }
 #endif
                h_errno = NO_RECOVERY;
                return (n);
        }
-       n = res_send(buf, n, answer, anslen);
+       n = res_send(buf, n, (char *)answer, anslen);
        if (n < 0) {
 #ifdef DEBUG
                if (_res.options & RES_DEBUG)
        if (n < 0) {
 #ifdef DEBUG
                if (_res.options & RES_DEBUG)
-                       printf("res_query: send error\n");
+                       printf(";; res_query: send error\n");
 #endif
                h_errno = TRY_AGAIN;
                return(n);
 #endif
                h_errno = TRY_AGAIN;
                return(n);
@@ -92,7 +126,7 @@ res_query(name, class, type, answer, anslen)
        if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
 #ifdef DEBUG
                if (_res.options & RES_DEBUG)
        if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
 #ifdef DEBUG
                if (_res.options & RES_DEBUG)
-                       printf("rcode = %d, ancount=%d\n", hp->rcode,
+                       printf(";; rcode = %d, ancount=%d\n", hp->rcode,
                            ntohs(hp->ancount));
 #endif
                switch (hp->rcode) {
                            ntohs(hp->ancount));
 #endif
                switch (hp->rcode) {
@@ -125,6 +159,7 @@ res_query(name, class, type, answer, anslen)
  * Only useful for queries in the same name hierarchy as the local host
  * (not, for example, for host address-to-name lookups in domain in-addr.arpa).
  */
  * Only useful for queries in the same name hierarchy as the local host
  * (not, for example, for host address-to-name lookups in domain in-addr.arpa).
  */
+int
 res_search(name, class, type, answer, anslen)
        char *name;             /* domain name */
        int class, type;        /* class and type of query */
 res_search(name, class, type, answer, anslen)
        char *name;             /* domain name */
        int class, type;        /* class and type of query */
@@ -133,17 +168,17 @@ res_search(name, class, type, answer, anslen)
 {
        register char *cp, **domain;
        int n, ret, got_nodata = 0;
 {
        register char *cp, **domain;
        int n, ret, got_nodata = 0;
-       char *hostalias();
+       char *__hostalias();
 
        if ((_res.options & RES_INIT) == 0 && res_init() == -1)
                return (-1);
 
        errno = 0;
 
        if ((_res.options & RES_INIT) == 0 && res_init() == -1)
                return (-1);
 
        errno = 0;
-       h_errno = HOST_NOT_FOUND;               /* default, if we never query */
+       h_errno = HOST_NOT_FOUND;       /* default, if we never query */
        for (cp = name, n = 0; *cp; cp++)
                if (*cp == '.')
                        n++;
        for (cp = name, n = 0; *cp; cp++)
                if (*cp == '.')
                        n++;
-       if (n == 0 && (cp = hostalias(name)))
+       if (n == 0 && (cp = __hostalias(name)))
                return (res_query(cp, class, type, answer, anslen));
 
        /*
                return (res_query(cp, class, type, answer, anslen));
 
        /*
@@ -212,7 +247,7 @@ res_querydomain(name, domain, class, type, answer, anslen)
 
 #ifdef DEBUG
        if (_res.options & RES_DEBUG)
 
 #ifdef DEBUG
        if (_res.options & RES_DEBUG)
-               printf("res_querydomain(%s, %s, %d, %d)\n",
+               printf(";; res_querydomain(%s, %s, %d, %d)\n",
                    name, domain, class, type);
 #endif
        if (domain == NULL) {
                    name, domain, class, type);
 #endif
        if (domain == NULL) {
@@ -234,8 +269,8 @@ res_querydomain(name, domain, class, type, answer, anslen)
 }
 
 char *
 }
 
 char *
-hostalias(name)
-       register char *name;
+__hostalias(name)
+       register const char *name;
 {
        register char *C1, *C2;
        FILE *fp;
 {
        register char *C1, *C2;
        FILE *fp;