Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-4]: src/dist/bind/bin/nslookup Pull up revision 1.1 (new) (requ...



details:   https://anonhg.NetBSD.org/src/rev/7c67b5caacb9
branches:  netbsd-1-4
changeset: 469795:7c67b5caacb9
user:      he <he%NetBSD.org@localhost>
date:      Sat Dec 04 16:57:25 1999 +0000

description:
Pull up revision 1.1 (new) (requested by christos and veego):
  Update to BIND 8.2.2-P5.

diffstat:

 dist/bind/bin/nslookup/list.c |   703 +++++++++++++++++++++++
 dist/bind/bin/nslookup/main.c |  1216 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1919 insertions(+), 0 deletions(-)

diffs (truncated from 1927 to 300 lines):

diff -r 3c595cdc5fab -r 7c67b5caacb9 dist/bind/bin/nslookup/list.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/dist/bind/bin/nslookup/list.c     Sat Dec 04 16:57:25 1999 +0000
@@ -0,0 +1,703 @@
+/*     $NetBSD: list.c,v 1.1.1.1.2.2 1999/12/04 16:57:25 he Exp $      */
+
+/*
+ * Copyright (c) 1985, 1989
+ *    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.
+ * 
+ * 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.
+ */
+
+#ifndef lint
+static const char sccsid[] = "@(#)list.c       5.23 (Berkeley) 3/21/91";
+static const char rcsid[] = "Id: list.c,v 8.21 1999/10/15 19:49:08 vixie Exp";
+#endif /* not lint */
+
+/*
+ *******************************************************************************
+ *
+ *  list.c --
+ *
+ *     Routines to obtain info from name and finger servers.
+ *
+ *     Adapted from 4.3BSD BIND ns_init.c and from finger.c.
+ *
+ *******************************************************************************
+ */
+
+#include "port_before.h"
+
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <netinet/in.h>
+#include <arpa/nameser.h>
+#include <arpa/inet.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <netdb.h>
+#include <resolv.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "port_after.h"
+
+#include "res.h"
+
+extern char *pager;
+
+typedef union {
+       HEADER qb1;
+       u_char qb2[PACKETSZ];
+} querybuf;
+
+extern HostInfo        *defaultPtr;
+extern HostInfo        curHostInfo;
+extern int     curHostValid;
+extern int     queryType;
+extern int     queryClass;
+
+static int sockFD = -1;
+int ListSubr();
+
+/*
+ *  During a listing to a file, hash marks are printed
+ *  every HASH_SIZE records.
+ */
+
+#define HASH_SIZE 50
+
+
+/*
+ *******************************************************************************
+ *
+ *  ListHosts --
+ *  ListHostsByType --
+ *
+ *     Requests the name server to do a zone transfer so we
+ *     find out what hosts it knows about.
+ *
+ *     For ListHosts, there are five types of output:
+ *     - Internet addresses (default)
+ *     - cpu type and operating system (-h option)
+ *     - canonical and alias names  (-a option)
+ *     - well-known service names  (-s option)
+ *     - ALL records (-d option)
+ *     ListHostsByType prints records of the default type or of a speicific
+ *     type.
+ *
+ *     To see all types of information sorted by name, do the following:
+ *       ls -d domain.edu > file
+ *       view file
+ *
+ *  Results:
+ *     SUCCESS         the listing was successful.
+ *     ERROR           the server could not be contacted because
+ *                     a socket could not be obtained or an error
+ *                     occured while receiving, or the output file
+ *                     could not be opened.
+ *
+ *******************************************************************************
+ */
+
+void
+ListHostsByType(char *string, int putToFile) {
+       char *namePtr, name[NAME_LEN], option[NAME_LEN];
+       int i, j, qtype, result;
+
+       /*
+        * Parse the command line. It maybe of the form "ls -t domain"
+        * or "ls -t type domain".
+        */
+
+       /* simulate sscanf(string, " ls -t %s %s", option, name) */
+       i = matchString(" ls -t ", string);
+       if (i > 0) {
+               j = pickString(string + i, option, sizeof option);
+               if (j > 0) {
+                       j = pickString(string + i + j, name, sizeof name);
+                       if (j > 0)
+                               i = 2;
+                       else
+                               i = 1;
+               } else {
+                       i = 0;
+               }
+       }
+                       
+       if (putToFile && i == 2 && name[0] == '>')
+               i--;
+       if (i == 2) {
+               qtype = StringToType(option, -1, stderr);
+               if (qtype == -1)
+                       return;
+               namePtr = name;
+       } else if (i == 1) {
+               namePtr = option;
+               qtype = queryType;
+       } else {
+               fprintf(stderr, "*** ls: invalid request %s\n", string);
+               return;
+       }
+       result = ListSubr(qtype, namePtr, putToFile ? string : NULL);
+       if (result != SUCCESS)
+               fprintf(stderr, "*** Can't list domain %s: %s\n", 
+                       namePtr, DecodeError(result));
+}
+
+void
+ListHosts(char *string, int putToFile) {
+       char *namePtr, name[NAME_LEN], option[NAME_LEN];
+       int i, j, qtype, result;
+
+       /*
+        *  Parse the command line. It maybe of the form "ls domain",
+        *  "ls -X domain".
+        */
+
+       /* simulate i = sscanf(string, " ls %s %s", option, name) */
+       i = matchString(" ls ", string);
+       if (i > 0) {
+               j = pickString(string + i, option, sizeof option);
+               if (j > 0) {
+                       j = pickString(string + i + j, name, sizeof name);
+                       if (j > 0)
+                               i = 2;
+                       else
+                               i = 1;
+               } else {
+                       i = 0;
+               }
+       }
+       
+       if (putToFile && i == 2 && name[0] == '>')
+               i--;
+       if (i == 2) {
+               if (strcmp("-a", option) == 0)
+                       qtype = T_CNAME;
+               else if (strcmp("-h", option) == 0)
+                       qtype = T_HINFO;
+               else if (strcmp("-m", option) == 0)
+                       qtype = T_MX;
+               else if (strcmp("-p", option) == 0)
+                       qtype = T_PX;
+               else if (strcmp("-s", option) == 0)
+                       qtype = T_WKS;
+               else if (strcmp("-d", option) == 0)
+                       qtype = T_ANY;
+               else if (strcmp("-n", option) == 0)
+                       qtype = T_NAPTR;
+               else
+                       qtype = T_A;
+               namePtr = name;
+       } else if (i == 1) {
+               namePtr = option;
+               qtype = T_A;
+       } else {
+               fprintf(stderr, "*** ls: invalid request %s\n",string);
+               return;
+       }
+       result = ListSubr(qtype, namePtr, putToFile ? string : NULL);
+       if (result != SUCCESS)
+               fprintf(stderr, "*** Can't list domain %s: %s\n", 
+                       namePtr, DecodeError(result));
+}
+
+int
+ListSubr(int qtype, char *domain, char *cmd) {
+       static u_char *answer = NULL;
+       static int answerLen = 0;
+
+       ns_msg handle;
+       querybuf buf;
+       struct sockaddr_in sin;
+       HEADER *headerPtr;
+       int msglen, amtToRead, numRead, n, count, soacnt;
+       u_int len;
+       int numAnswers = 0;
+       int numRecords = 0;
+       u_char tmp[INT16SZ], *cp;
+       char soaname[2][NAME_LEN], file[PATH_MAX];
+       enum { NO_ERRORS, ERR_READING_LEN, ERR_READING_MSG, ERR_PRINTING }
+               error = NO_ERRORS;
+
+       /*
+        * Create a query packet for the requested domain name.
+        */
+       msglen = res_nmkquery(&res, QUERY, domain, queryClass, T_AXFR,
+                             NULL, 0, 0, buf.qb2, sizeof buf);
+       if (msglen < 0) {
+               if (_res.options & RES_DEBUG)
+                       fprintf(stderr, "*** ls: res_nmkquery failed\n");
+               return (ERROR);
+       }
+
+       memset(&sin, 0, sizeof sin);
+       sin.sin_family = AF_INET;
+       sin.sin_port = htons(nsport);
+
+       /*
+        * Check to see if we have the address of the server or the
+        * address of a server who knows about this domain.
+        *
+        * For now, just use the first address in the list. XXX.
+        */
+
+       if (defaultPtr->addrList != NULL)
+               sin.sin_addr = *(struct in_addr *) defaultPtr->addrList[0];



Home | Main Index | Thread Index | Old Index