Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!bcm!soma!masscomp-request
From: sob@cortex.neuro.bcm.tmc.edu (Stan Barber)
Newsgroups: comp.sys.masscomp
Subject: name server resolver library for MASSCOMP (part 1 of 7)
Message-ID: <3469@soma.bcm.tmc.edu>
Date: 5 Jul 88 00:56:24 GMT
Sender: masscomp@soma.bcm.tmc.edu
Lines: 909
Approved: masscomp@soma.bcm.tmc.edu

If you are on the internet and want your Masscomp to understand the Domain
Name Service, here is the first step. This is the resolver library.
This code is based on BIND 4.8 with all patches to date.

Enjoy.


#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	tools/Makefile.libc
#	tools/Makefile.resol
#	tools/installit
#	tools/makefile
#	tools/manroff
#	tools/mkdep
#	tools/nsquery.c
#	tools/nstest.c
# This archive created: Mon Jul  4 20:24:39 1988
export PATH; PATH=/bin:/usr/bin:$PATH
if test ! -d 'tools'
then
	echo shar: "creating directory 'tools'"
	mkdir 'tools'
fi
echo shar: "entering directory 'tools'"
cd 'tools'
echo shar: "extracting 'Makefile.libc'" '(1536 characters)'
if test -f 'Makefile.libc'
then
	echo shar: "will not over-write existing file 'Makefile.libc'"
else
sed 's/^	X//' << \SHAR_EOF > 'Makefile.libc'
	X#
	X# Copyright (c) 1987 Regents of the University of California.
	X# All rights reserved.
	X#
	X# Redistribution and use in source and binary forms are permitted
	X# provided that this notice is preserved and that due credit is given
	X# to the University of California at Berkeley. The name of the University
	X# may not be used to endorse or promote products derived from this
	X# software without specific prior written permission. This software
	X# is provided ``as is'' without express or implied warranty.
	X#
	X#	@(#)Makefile	4.7 (Berkeley) 4/6/88
	X#
	XSHELL=/bin/sh
	XCFLAGS=	-O -I../include
	XRES=	
	XLIBC=	/lib/libc.a
	XSRCS=	nsquery.c nstest.c
	XOBJS=	nsquery.o nstest.o
	X
	Xall: nsquery nstest nslookup
	X
	Xnsquery: ${LIBC}
	X	${CC} ${CFLAGS} -o $@ nsquery.c ${RES}
	X
	X# test programs and utilities
	Xnstest: ${LIBC}
	X	@echo "The resolver routines in libc must be compiled with the -DDEBUG"
	X	@echo "option or nstest will not have any output."
	X	${CC} ${CFLAGS}  -o $@ nstest.c ${RES}
	X
	Xnslookup: FRC
	X	cd nslookup; make ${MFLAGS} RES=${RES}
	X
	Xclean: FRC
	X	cd nslookup; make ${MFLAGS} clean
	X	rm -f ${OBJS} core nsquery nstest
	X
	Xdepend: FRC
	X	cd nslookup; make ${MFLAGS} depend
	X	./mkdep -p ${CFLAGS} ${SRCS}
	X
	Xinstall: FRC
	X	cd nslookup; make ${MFLAGS} DESTDIR=${DESTDIR} install
	X
	Xlint: FRC
	X	cd nslookup; make ${MFLAGS} lint
	X	lint ${CFLAGS} ${SRCS}
	X
	Xtags: FRC
	X	cd nslookup; make ${MFLAGS} tags
	X	ctags ${SRCS}
	X
	XFRC:
	X
	X# DO NOT DELETE THIS LINE -- mkdep uses it.
	X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
	X
	Xnsquery.c:
	Xnstest.c:
	X
	X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
SHAR_EOF
if test 1536 -ne "`wc -c < 'Makefile.libc'`"
then
	echo shar: "error transmitting 'Makefile.libc'" '(should have been 1536 characters)'
fi
fi
echo shar: "extracting 'Makefile.resol'" '(1617 characters)'
if test -f 'Makefile.resol'
then
	echo shar: "will not over-write existing file 'Makefile.resol'"
else
sed 's/^	X//' << \SHAR_EOF > 'Makefile.resol'
	X#
	X# Copyright (c) 1987 Regents of the University of California.
	X# All rights reserved.
	X#
	X# Redistribution and use in source and binary forms are permitted
	X# provided that this notice is preserved and that due credit is given
	X# to the University of California at Berkeley. The name of the University
	X# may not be used to endorse or promote products derived from this
	X# software without specific prior written permission. This software
	X# is provided ``as is'' without express or implied warranty.
	X#
	X#	@(#)Makefile	4.7 (Berkeley) 4/6/88
	X#
	XSHELL=/bin/sh
	XCFLAGS=	-O -DEXOS -DSYS5 -I../include -I/usr/include/NET-5000
	XRES=	../res/libresolv.a
	XLIBS=	-lsocket
	XLIBC=	/lib/libc.a
	XSRCS=	nsquery.c nstest.c
	XOBJS=	nsquery.o nstest.o
	X
	Xall: nsquery nstest nslookup
	X
	Xnsquery: ${LIBC}
	X	${CC} ${CFLAGS} -o $@ nsquery.c ${RES}
	X
	X# test programs and utilities
	Xnstest: ${LIBC}
	X	@echo "The resolver routines in libresolv.a must be compiled with the -DDEBUG"
	X	@echo "option or nstest will not have any output."
	X	${CC} ${CFLAGS}  -o $@ nstest.c ${RES}
	X
	Xnslookup: FRC
	X	cd nslookup; make ${MFLAGS} RES=../${RES}
	X
	Xclean: FRC
	X	cd nslookup; make ${MFLAGS} clean
	X	rm -f ${OBJS} core nsquery nstest
	X
	Xdepend: FRC
	X	cd nslookup; make ${MFLAGS} depend
	X	./mkdep -p ${CFLAGS} ${SRCS}
	X
	Xinstall: FRC
	X	cd nslookup; make ${MFLAGS} DESTDIR=${DESTDIR} install
	X
	Xlint: FRC
	X	cd nslookup; make ${MFLAGS} lint
	X	lint ${CFLAGS} ${SRCS}
	X
	Xtags: FRC
	X	cd nslookup; make ${MFLAGS} tags
	X	ctags ${SRCS}
	X
	XFRC:
	X
	X# DO NOT DELETE THIS LINE -- mkdep uses it.
	X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
	X
	Xnsquery.c:
	Xnstest.c:
	X
	X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
SHAR_EOF
if test 1617 -ne "`wc -c < 'Makefile.resol'`"
then
	echo shar: "error transmitting 'Makefile.resol'" '(should have been 1617 characters)'
fi
fi
echo shar: "extracting 'installit'" '(1284 characters)'
if test -f 'installit'
then
	echo shar: "will not over-write existing file 'installit'"
else
sed 's/^	X//' << \SHAR_EOF > 'installit'
	X#! /bin/sh
	X#
	X#	'@(#)installit	2.4	10/15/87'
	X#	From install.sh	4.8	(Berkeley)	3/6/86
	X#	on the 4.3 BSD distribution (with permission)
	X#
	XPATH=/bin:/etc:/usr/bin:/usr/ucb
	Xexport PATH
	Xcmd=""
	Xstripbefore=""
	Xstripafter=""
	Xchmod="chmod 755"
	Xchown="#"
	Xchgrp="#"
	Xwhile true ; do
	X	case $1 in
	X		-s )	if test $cmd 
	X			then	stripafter="strip"
	X			else	stripbefore="strip"
	X			fi
	X			shift
	X			;;
	X		-c )	if test $cmd 
	X			then	echo "install: multiple specifications of -c"
	X				exit 1
	X			fi
	X			cmd="cp"
	X			stripafter=$stripbefore
	X			stripbefore=""
	X			shift
	X			;;
	X		-m )	chmod="chmod $2"
	X			shift
	X			shift
	X			;;
	X		-o )	chown="chown $2"
	X			shift
	X			shift
	X			;;
	X		-g )	chgrp="chgrp $2"
	X			shift
	X			shift
	X			;;
	X		* )	break
	X			;;
	X	esac
	Xdone
	Xif test $cmd 
	Xthen true
	Xelse cmd="mv"
	Xfi
	X
	Xif test ! ${2-""} 
	Xthen	echo "install: no destination specified"
	X	exit 1
	Xfi
	Xif test ${3-""} 
	Xthen	echo "install: too many files specified -> $*"
	X	exit 1
	Xfi
	Xif test $1 = $2 -o $2 = . 
	Xthen	echo "install: can't move $1 onto itself"
	X	exit 1
	Xfi
	Xif test '!' -f $1 
	Xthen	echo "install: can't open $1"
	X	exit 1
	Xfi
	Xif test -d $2 
	Xthen	file=$2/`basename $1`
	Xelse	file=$2
	Xfi
	X/bin/rm -f $file
	Xif test $stripbefore 
	Xthen	$stripbefore $1
	Xfi
	X$cmd $1 $file
	Xif test $stripafter 
	Xthen	$stripafter $file
	Xfi
	X$chown $file
	X$chgrp $file
	X$chmod $file
SHAR_EOF
if test 1284 -ne "`wc -c < 'installit'`"
then
	echo shar: "error transmitting 'installit'" '(should have been 1284 characters)'
fi
chmod +x 'installit'
fi
echo shar: "extracting 'makefile'" '(1589 characters)'
if test -f 'makefile'
then
	echo shar: "will not over-write existing file 'makefile'"
else
sed 's/^	X//' << \SHAR_EOF > 'makefile'
	X#
	X# Copyright (c) 1987 Regents of the University of California.
	X# All rights reserved.
	X#
	X# Redistribution and use in source and binary forms are permitted
	X# provided that this notice is preserved and that due credit is given
	X# to the University of California at Berkeley. The name of the University
	X# may not be used to endorse or promote products derived from this
	X# software without specific prior written permission. This software
	X# is provided ``as is'' without express or implied warranty.
	X#
	X#	@(#)Makefile	4.7 (Berkeley) 4/6/88
	X#
	XSHELL=/bin/sh
	XCFLAGS=	-O -DSYS5 -DMASSCOMP -I../include
	XRES=	../res/libresolv.a
	XLIBS=	
	XLIBC=	/lib/libc.a
	XSRCS=	nsquery.c nstest.c
	XOBJS=	nsquery.o nstest.o
	X
	Xall: nsquery nstest nslookup
	X
	Xnsquery: ${LIBC}
	X	${CC} ${CFLAGS} -o $@ nsquery.c ${RES}
	X
	X# test programs and utilities
	Xnstest: ${LIBC}
	X	@echo "The resolver routines in libresolv.a must be compiled with the -DDEBUG"
	X	@echo "option or nstest will not have any output."
	X	${CC} ${CFLAGS}  -o $@ nstest.c ${RES}
	X
	Xnslookup: FRC
	X	cd nslookup; make ${MFLAGS} RES=../${RES}
	X
	Xclean: FRC
	X	cd nslookup; make ${MFLAGS} clean
	X	rm -f ${OBJS} core nsquery nstest
	X
	Xdepend: FRC
	X	cd nslookup; make ${MFLAGS} depend
	X	./mkdep -p ${CFLAGS} ${SRCS}
	X
	Xinstall: FRC
	X	cd nslookup; make ${MFLAGS} DESTDIR=${DESTDIR} install
	X
	Xlint: FRC
	X	cd nslookup; make ${MFLAGS} lint
	X	lint ${CFLAGS} ${SRCS}
	X
	Xtags: FRC
	X	cd nslookup; make ${MFLAGS} tags
	X	ctags ${SRCS}
	X
	XFRC:
	X
	X# DO NOT DELETE THIS LINE -- mkdep uses it.
	X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
	X
	Xnsquery.c:
	Xnstest.c:
	X
	X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
SHAR_EOF
if test 1589 -ne "`wc -c < 'makefile'`"
then
	echo shar: "error transmitting 'makefile'" '(should have been 1589 characters)'
fi
fi
echo shar: "extracting 'manroff'" '(29 characters)'
if test -f 'manroff'
then
	echo shar: "will not over-write existing file 'manroff'"
else
sed 's/^	X//' << \SHAR_EOF > 'manroff'
	X#! /bin/sh
	X
	Xnroff -man -h $*
SHAR_EOF
if test 29 -ne "`wc -c < 'manroff'`"
then
	echo shar: "error transmitting 'manroff'" '(should have been 29 characters)'
fi
chmod +x 'manroff'
fi
echo shar: "extracting 'mkdep'" '(1788 characters)'
if test -f 'mkdep'
then
	echo shar: "will not over-write existing file 'mkdep'"
else
sed 's/^	X//' << \SHAR_EOF > 'mkdep'
	X#!/bin/sh -
	X#
	X# Copyright (c) 1987 Regents of the University of California.
	X# All rights reserved.
	X#
	X# Redistribution and use in source and binary forms are permitted
	X# provided that this notice is preserved and that due credit is given
	X# to the University of California at Berkeley. The name of the University
	X# may not be used to endorse or promote products derived from this
	X# software without specific prior written permission. This software
	X# is provided ``as is'' without express or implied warranty.
	X#
	X#	@(#)mkdep.sh	5.9 (Berkeley) 1/1/88
	X#
	X
	XPATH=/bin:/usr/bin:/usr/ucb
	Xexport PATH
	X
	XMAKE=Makefile			# default makefile name is "Makefile"
	X
	Xwhile :
	X	do case "$1" in
	X		# -f allows you to select a makefile name
	X		-f)
	X			MAKE=$2
	X			shift; shift ;;
	X
	X		# the -p flag produces "program: program.c" style dependencies
	X		# so .o's don't get produced
	X		-p)
	X			SED='-e s;\.o;;'
	X			shift ;;
	X		*)
	X			break ;;
	X	esac
	Xdone
	X
	Xif [ $# = 0 ] ; then
	X	echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
	X	exit 1
	Xfi
	X
	Xif [ ! -w $MAKE ]; then
	X	echo "mkdep: no writeable file \"$MAKE\""
	X	exit 1
	Xfi
	X
	XTMP=/tmp/mkdep$$
	X
	Xtrap 'rm -f $TMP ; exit 1' 1 2 3 13 15
	X
	Xcp $MAKE ${MAKE}.bak
	X
	Xsed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
	X
	Xcat << _EOF_ >> $TMP
	X# DO NOT DELETE THIS LINE -- mkdep uses it.
	X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
	X
	X_EOF_
	X
	Xcc -M $* | /bin/sed -e "s; \./; ;g" $SED | \
	X	awk ' { \
	X		if ($1 != prev) { \
	X			if (rec != "") \
	X				print rec; rec = $0; prev = $1; \
	X		} \
	X		else { \
	X			if (length(rec $2) > 78) { \
	X				print rec; rec = $0; \
	X			} else \
	X				rec = rec " " $2 \
	X		} \
	X	} \
	X	END { \
	X		print rec \
	X	} ' >> $TMP
	X
	Xcat << _EOF_ >> $TMP
	X
	X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
	X_EOF_
	X
	X# copy to preserve permissions
	Xcp $TMP $MAKE
	Xrm -f ${MAKE}.bak $TMP
	Xexit 0
SHAR_EOF
if test 1788 -ne "`wc -c < 'mkdep'`"
then
	echo shar: "error transmitting 'mkdep'" '(should have been 1788 characters)'
fi
chmod +x 'mkdep'
fi
echo shar: "extracting 'nsquery.c'" '(1270 characters)'
if test -f 'nsquery.c'
then
	echo shar: "will not over-write existing file 'nsquery.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'nsquery.c'
	X#ifndef lint
	Xstatic char sccsid[] = "@(#)nsquery.c	4.2 (Berkeley) 11/21/87";
	X#endif
	X
	X/*
	X * Copyright (c) 1986 Regents of the University of California
	X *	All Rights Reserved
	X */
	X
	X#include 
	X#include 
	X#ifdef EXOS
	X#include 
	X#endif
	X#include 
	X#include 
	X
	X#include 
	X#include 
	X#include 
	X
	Xstruct state orig;
	Xextern struct state _res;
	Xextern int h_errno;
	X
	Xmain(c, v)
	X	char **v;
	X{
	X	char h[32];
	X	register struct hostent *hp;
	X	register char *s;
	X
	X	gethostname(h, 32);
	X	s = h;
	X	if (c < 2) {
	X		fprintf(stderr, "Usage: lookup host [server]\n");
	X		exit(1);
	X	}
	X	if (c > 2)
	X		s = v[2];
	X
	X	hp = gethostbyname(s);
	X	if (hp == NULL) {
	X		herror(h_errno);
	X		exit(1);
	X	}
	X	printanswer(hp);
	X
	X	_res.nsaddr.sin_addr = *(struct in_addr *)hp->h_addr;
	X	_res.options &= ~RES_DEFNAMES;
	X
	X	hp = gethostbyname(v[1]);
	X	if (hp == NULL) {
	X		herror(h_errno);
	X		exit(1);
	X	}
	X	printanswer(hp);
	X	exit(0);
	X}
	X
	Xprintanswer(hp)
	X	register struct hostent *hp;
	X{
	X	register char **cp;
	X	extern char *inet_ntoa();
	X
	X	printf("Name: %s\n", hp->h_name);
	X	printf("Address: %s\n", inet_ntoa(*(struct in_addr *)hp->h_addr));
	X	printf("Aliases:");
	X	for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
	X		printf(" %s", *cp);
	X	printf("\n\n");
	X}
SHAR_EOF
if test 1270 -ne "`wc -c < 'nsquery.c'`"
then
	echo shar: "error transmitting 'nsquery.c'" '(should have been 1270 characters)'
fi
fi
echo shar: "extracting 'nstest.c'" '(8264 characters)'
if test -f 'nstest.c'
then
	echo shar: "will not over-write existing file 'nstest.c'"
else
sed 's/^	X//' << \SHAR_EOF > 'nstest.c'
	X#ifndef lint
	Xstatic char sccsid[] = "@(#)nstest.c	4.6 (Berkeley) 12/7/86";
	X#endif
	X
	X/*
	X * Copyright (c) 1986 Regents of the University of California
	X *	All Rights Reserved
	X */
	X
	X#include 
	X#ifdef EXOS
	X#include 
	X#endif
	X#include 
	X#include 
	X#include 
	X#include 
	X#include 
	X
	Xextern char *inet_ntoa();
	Xchar *progname;
	XFILE *log;
	X#define MAXDATA		256   /* really should get definition from named/db.h */
	Xmain(argc, argv)
	X	char **argv;
	X{
	X	register char *cp;
	X	struct hostent *hp;
	X	short port = htons(NAMESERVER_PORT);
	X	char buf[BUFSIZ];
	X	char packet[PACKETSZ];
	X	char answer[PACKETSZ];
	X	struct rrec NewRR;
	X	char OldRRData[MAXDATA];
	X	int n, dump_packet;
	X
	X	NewRR.r_data = (char *) malloc(MAXDATA);
	X	NewRR.r_data = (char *) malloc(MAXDATA);
	X	progname = argv[0];
	X	dump_packet = 0;
	X	_res.options |= RES_DEBUG|RES_RECURSE;
	X	while (argc > 1 && argv[1][0] == '-') {
	X		argc--;
	X		cp = *++argv;
	X		while (*++cp)
	X			switch (*cp) {
	X			case 'p':
	X				if (--argc <= 0)
	X					usage();
	X				port = htons(atoi(*++argv));
	X				break;
	X
	X			case 'i':
	X				_res.options |= RES_IGNTC;
	X				break;
	X
	X			case 'v':
	X				_res.options |= RES_USEVC|RES_STAYOPEN;
	X				break;
	X
	X			case 'r':
	X				_res.options &= ~RES_RECURSE;
	X				break;
	X
	X			case 'd':
	X				dump_packet++;
	X				break;
	X
	X			default:
	X				usage();
	X			}
	X	}
	X	_res.nsaddr.sin_family = AF_INET;
	X	_res.nsaddr.sin_addr.s_addr = INADDR_ANY;
	X	_res.nsaddr.sin_port = port;
	X 	if (argc > 1)
	X 		_res.nsaddr.sin_addr.s_addr = inet_addr(argv[1]);
	X 	if (argc > 2) {
	X 		log = fopen(argv[2],"w");
	X 		if (log == NULL) perror(argv[2]);
	X 	}
	X	for (;;) {
	X		printf("> ");
	X		fflush(stdout);
	X		if ((cp = (char *)gets(buf)) == NULL)
	X			break;
	X		switch (*cp++) {
	X		case 'a':
	X			n = res_mkquery(QUERY, cp, C_ANY, T_A, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'A':
	X			n = ntohl(inet_addr(cp));
	X			putlong(n, cp);
	X			n = res_mkquery(IQUERY, "", C_IN, T_A, cp, sizeof(long),
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'f':
	X			n = res_mkquery(QUERY, cp, C_ANY, T_UINFO, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'g':
	X			n = res_mkquery(QUERY, cp, C_ANY, T_GID, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'G':
	X			*(int *)cp = htonl(atoi(cp));
	X			n = res_mkquery(IQUERY, "", C_ANY, T_GID, cp,
	X				sizeof(int), NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'c':
	X			n = res_mkquery(QUERY, cp, C_IN, T_CNAME, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'h':
	X			n = res_mkquery(QUERY, cp, C_IN, T_HINFO, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'm':
	X			n = res_mkquery(QUERY, cp, C_IN, T_MX, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'M':
	X			n = res_mkquery(QUERY, cp, C_IN, T_MAILB, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'n':
	X			n = res_mkquery(QUERY, cp, C_IN, T_NS, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'p':
	X			n = res_mkquery(QUERY, cp, C_IN, T_PTR, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 's':
	X			n = res_mkquery(QUERY, cp, C_IN, T_SOA, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'u':
	X			n = res_mkquery(QUERY, cp, C_ANY, T_UID, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'U':
	X			*(int *)cp = htonl(atoi(cp));
	X			n = res_mkquery(IQUERY, "", C_ANY, T_UID, cp,
	X				sizeof(int), NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'x':
	X			n = res_mkquery(QUERY, cp, C_IN, T_AXFR, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'w':
	X			n = res_mkquery(QUERY, cp, C_IN, T_WKS, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'b':
	X			n = res_mkquery(QUERY, cp, C_IN, T_MB, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'B':
	X			n = res_mkquery(QUERY, cp, C_IN, T_MG, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'i':
	X			n = res_mkquery(QUERY, cp, C_IN, T_MINFO, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'r':
	X			n = res_mkquery(QUERY, cp, C_IN, T_MR, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X		case '*':
	X			n = res_mkquery(QUERY, cp, C_IN, T_ANY, (char *)0, 0,
	X				NULL, packet, sizeof(packet));
	X			break;
	X
	X#ifdef ALLOW_UPDATES
	X		case '^':
	X			{
	X			    char IType[10], TempStr[50];
	X			    int Type, oldnbytes, nbytes, i;
	X#ifdef ALLOW_T_UNSPEC
	X			    printf("Data type (a = T_A, u = T_UNSPEC): ");
	X			    gets(IType);
	X			    if (IType[0] == 'u') {
	X			    	Type = T_UNSPEC;
	X			    	printf("How many data bytes? ");
	X			    	gets(TempStr); /* Throw away CR */
	X			    	sscanf(TempStr, "%d", &nbytes);
	X			    	for (i = 0; i < nbytes; i++) {
	X			    		(NewRR.r_data)[i] = (char) i;
	X			    	}
	X			    } else {
	X#endif ALLOW_T_UNSPEC
	X			    	Type = T_A;
	X			    	nbytes = sizeof(u_long);
	X			    	printf("Inet addr for new dname (e.g., 192.4.3.2): ");
	X			    	gets(TempStr);
	X			    	putlong(ntohl(inet_addr(TempStr)), NewRR.r_data);
	X#ifdef ALLOW_T_UNSPEC
	X			    }
	X#endif ALLOW_T_UNSPEC
	X			    NewRR.r_class = C_IN;
	X			    NewRR.r_type = Type;
	X			    NewRR.r_size = nbytes;
	X			    NewRR.r_ttl = 99999999;
	X			    printf("Add, modify, or modify all (a/m/M)? ");
	X			    gets(TempStr);
	X			    if (TempStr[0] == 'a') {
	X			    	n = res_mkquery(UPDATEA, cp, C_IN, Type,
	X			    			OldRRData, nbytes,
	X			    			&NewRR, packet,
	X			    			sizeof(packet));
	X			    } else {
	X			    	if (TempStr[0] == 'm') {
	X			    	    printf("How many data bytes in old RR? ");
	X			    	    gets(TempStr); /* Throw away CR */
	X			    	    sscanf(TempStr, "%d", &oldnbytes);
	X				    for (i = 0; i < oldnbytes; i++) {
	X					    OldRRData[i] = (char) i;
	X				    }
	X					n = res_mkquery(UPDATEM, cp, C_IN, Type,
	X							OldRRData, oldnbytes,
	X							&NewRR, packet,
	X							sizeof(packet));
	X				} else { /* Modify all */
	X					n = res_mkquery(UPDATEMA, cp,
	X							C_IN, Type, NULL, 0,
	X							&NewRR, packet,
	X							sizeof(packet));
	X
	X				}
	X			    }
	X			}
	X			break;
	X
	X#ifdef ALLOW_T_UNSPEC
	X		case 'D':
	X			n = res_mkquery(UPDATEDA, cp, C_IN, T_UNSPEC, (char *)0,
	X					0, NULL, packet, sizeof(packet));
	X			break;
	X
	X		case 'd':
	X			{
	X				char TempStr[100];
	X				int nbytes, i;
	X				printf("How many data bytes in oldrr data? ");
	X				gets(TempStr); /* Throw away CR */
	X				sscanf(TempStr, "%d", &nbytes);
	X				for (i = 0; i < nbytes; i++) {
	X					OldRRData[i] = (char) i;
	X				}
	X				n = res_mkquery(UPDATED, cp, C_IN, T_UNSPEC,
	X						OldRRData, nbytes, NULL, packet,
	X						sizeof(packet));
	X			}
	X			break;
	X#endif ALLOW_T_UNSPEC
	X#endif ALLOW_UPDATES
	X
	X		default:
	X			printf("a{host} - query  T_A\n");
	X			printf("A{addr} - iquery T_A\n");
	X			printf("b{user} - query  T_MB\n");
	X			printf("B{user} - query  T_MG\n");
	X			printf("f{host} - query  T_UINFO\n");
	X			printf("g{host} - query  T_GID\n");
	X			printf("G{gid}  - iquery T_GID\n");
	X			printf("h{host} - query  T_HINFO\n");
	X			printf("i{host} - query  T_MINFO\n");
	X			printf("p{host} - query  T_PTR\n");
	X			printf("m{host} - query  T_MX\n");
	X			printf("M{host} - query  T_MAILB\n");
	X			printf("n{host} - query  T_NS\n");
	X			printf("r{host} - query  T_MR\n");
	X			printf("s{host} - query  T_SOA\n");
	X			printf("u{host} - query  T_UID\n");
	X			printf("U{uid}  - iquery T_UID\n");
	X			printf("x{host} - query  T_AXFR\n");
	X			printf("w{host} - query  T_WKS\n");
	X			printf("c{host} - query  T_CNAME\n");
	X			printf("*{host} - query  T_ANY\n");
	X#ifdef ALLOW_UPDATES
	X			printf("^{host} - add/mod/moda    (T_A/T_UNSPEC)\n");
	X#ifdef ALLOW_T_UNSPEC
	X			printf("D{host} - deletea T_UNSPEC\n");
	X			printf("d{host} - delete T_UNSPEC\n");
	X#endif ALLOW_T_UNSPEC
	X#endif ALLOW_UPDATES
	X			continue;
	X		}
	X		if (n < 0) {
	X			printf("res_mkquery: buffer too small\n");
	X			continue;
	X		}
	X		if (log) {
	X			fprintf(log,"SEND QUERY\n");
	X			fp_query(packet, log);
	X		}
	X		n = res_send(packet, n, answer, sizeof(answer));
	X		if (n < 0) {
	X			printf("res_send: send error\n");
	X			if (log) fprintf(log, "res_send: send error\n");
	X		}
	X		else {
	X			if (dump_packet) {
	X				int f;
	X				f = creat("ns_packet.dump", 0644);
	X				write(f, answer, n);
	X				(void) close(f);
	X			}
	X			if (log) {
	X				fprintf(log, "GOT ANSWER\n");
	X				fp_query(answer, log);
	X			}
	X		}
	X	}
	X}
	X
	Xusage()
	X{
	X	fprintf(stderr, "Usage: %s [-v] [-i] [-r] [-d] [-p port] hostaddr\n",
	X		progname);
	X	exit(1);
	X}
SHAR_EOF
if test 8264 -ne "`wc -c < 'nstest.c'`"
then
	echo shar: "error transmitting 'nstest.c'" '(should have been 8264 characters)'
fi
fi
exit 0
#	End of shell archive