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 5 of 7) Message-ID: <3473@soma.bcm.tmc.edu> Date: 5 Jul 88 01:01:56 GMT Sender: masscomp@soma.bcm.tmc.edu Lines: 1606 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: # res/Makefile.libc # res/Makefile.resol # res/makefile # res/res_debug.c # res/res_comp.c # res/res_compat.c # res/herror.c # res/strcasecmp.c # This archive created: Mon Jul 4 20:32:08 1988 export PATH; PATH=/bin:/usr/bin:$PATH if test ! -d 'res' then echo shar: "creating directory 'res'" mkdir 'res' fi echo shar: "entering directory 'res'" cd 'res' echo shar: "extracting 'Makefile.libc'" '(4950 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) 1988 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 5.16 (Berkeley) 3/14/88 X# XSRCS= getnetbyaddr.c getnetent.c getnetbyname.c getproto.c getprotoent.c \ X getprotoname.c getservent.c getservbyport.c getservbyname.c \ X herror.c rcmd.c rexec.c ruserpass.c res_comp.c res_debug.c \ X res_init.c res_mkquery.c res_query.c res_send.c XOBJS= getnetbyaddr.o getnetent.o getnetbyname.o getproto.o getprotoent.o \ X getprotoname.o getservent.o getservbyport.o getservbyname.o \ X herror.o rcmd.o rexec.o ruserpass.o res_comp.o res_debug.o \ X res_init.o res_mkquery.o res_query.o res_send.o X XCFLAGS= -O ${DEFS} -I../include # Craig Finset, MSC, April 1988 XTAGSFILE=tags X X.c.o: X ${CC} -p -c ${CFLAGS} $*.c X -ld -X -r $*.o X mv a.out profiled/$*.o X ${CC} ${CFLAGS} -c $*.c X -ld -x -r $*.o X mv a.out $*.o X Xnetlib netlib_p: ${OBJS} X @echo "building profiled netlib" X @cd profiled; ar cru ../netlib_p ${OBJS} X @echo "building normal netlib" X @ar cru netlib ${OBJS} X Xtags: X cwd=`pwd`; \ X for i in ${SRCS}; do \ X ctags -a -f ${TAGSFILE} $$cwd/$$i; \ X done X Xclean: X rm -f *.o profiled/*.o errs a.out core netlib netlib_p tags X Xdepend: X mkdep ${CFLAGS} ${SRCS} X X# DO NOT DELETE THIS LINE -- mkdep uses it. X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. X Xgetnetbyaddr.o: getnetbyaddr.c /usr/include/netdb.h Xgetnetent.o: getnetent.c /usr/include/stdio.h /usr/include/sys/types.h Xgetnetent.o: /usr/include/sys/socket.h /usr/include/netdb.h Xgetnetent.o: /usr/include/ctype.h Xgetnetbyname.o: getnetbyname.c /usr/include/netdb.h Xgetproto.o: getproto.c /usr/include/netdb.h Xgetprotoent.o: getprotoent.c /usr/include/stdio.h /usr/include/sys/types.h Xgetprotoent.o: /usr/include/sys/socket.h /usr/include/netdb.h Xgetprotoent.o: /usr/include/ctype.h Xgetprotoname.o: getprotoname.c /usr/include/netdb.h Xgetservent.o: getservent.c /usr/include/stdio.h /usr/include/sys/param.h Xgetservent.o: /usr/include/sys/types.h /usr/include/signal.h Xgetservent.o: /usr/include/machine/trap.h /usr/include/sys/types.h Xgetservent.o: /usr/include/sys/socket.h /usr/include/netdb.h Xgetservent.o: /usr/include/ctype.h Xgetservbyport.o: getservbyport.c /usr/include/netdb.h Xgetservbyname.o: getservbyname.c /usr/include/netdb.h Xherror.o: herror.c /usr/include/sys/types.h /usr/include/sys/uio.h Xrcmd.o: rcmd.c /usr/include/stdio.h /usr/include/ctype.h /usr/include/pwd.h Xrcmd.o: /usr/include/sys/param.h /usr/include/sys/types.h /usr/include/signal.h Xrcmd.o: /usr/include/machine/trap.h /usr/include/sys/file.h Xrcmd.o: /usr/include/sys/signal.h /usr/include/sys/socket.h Xrcmd.o: /usr/include/sys/stat.h /usr/include/netinet/in.h /usr/include/netdb.h Xrcmd.o: /usr/include/errno.h Xrexec.o: rexec.c /usr/include/sys/types.h /usr/include/sys/socket.h Xrexec.o: /usr/include/netinet/in.h /usr/include/stdio.h /usr/include/netdb.h Xrexec.o: /usr/include/errno.h Xruserpass.o: ruserpass.c /usr/include/stdio.h /usr/include/utmp.h Xruserpass.o: /usr/include/ctype.h /usr/include/sys/types.h Xruserpass.o: /usr/include/sys/stat.h /usr/include/errno.h Xres_comp.o: res_comp.c /usr/include/sys/types.h /usr/include/stdio.h Xres_comp.o: /usr/include/arpa/nameser.h Xres_debug.o: res_debug.c /usr/include/sys/types.h /usr/include/netinet/in.h Xres_debug.o: /usr/include/stdio.h /usr/include/arpa/nameser.h Xres_init.o: res_init.c /usr/include/sys/types.h /usr/include/sys/socket.h Xres_init.o: /usr/include/netinet/in.h /usr/include/stdio.h Xres_init.o: /usr/include/arpa/nameser.h /usr/include/resolv.h Xres_mkquery.o: res_mkquery.c /usr/include/stdio.h /usr/include/sys/types.h Xres_mkquery.o: /usr/include/netinet/in.h /usr/include/arpa/nameser.h Xres_mkquery.o: /usr/include/resolv.h Xres_query.o: res_query.c /usr/include/sys/param.h /usr/include/sys/types.h Xres_query.o: /usr/include/signal.h /usr/include/machine/trap.h Xres_query.o: /usr/include/sys/socket.h /usr/include/netinet/in.h Xres_query.o: /usr/include/ctype.h /usr/include/netdb.h /usr/include/stdio.h Xres_query.o: /usr/include/errno.h /usr/include/strings.h Xres_query.o: /usr/include/arpa/inet.h /usr/include/arpa/nameser.h Xres_query.o: /usr/include/resolv.h Xres_send.o: res_send.c /usr/include/sys/param.h /usr/include/sys/types.h Xres_send.o: /usr/include/signal.h /usr/include/machine/trap.h Xres_send.o: /usr/include/sys/time.h /usr/include/time.h Xres_send.o: /usr/include/sys/socket.h /usr/include/sys/uio.h Xres_send.o: /usr/include/netinet/in.h /usr/include/stdio.h /usr/include/errno.h Xres_send.o: /usr/include/arpa/nameser.h /usr/include/resolv.h X X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY SHAR_EOF if test 4950 -ne "`wc -c < 'Makefile.libc'`" then echo shar: "error transmitting 'Makefile.libc'" '(should have been 4950 characters)' fi fi echo shar: "extracting 'Makefile.resol'" '(2051 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) 1988 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# from @(#)Makefile 5.16 (Berkeley) 3/14/88 X# XSHELL= /bin/sh XSRCS= herror.c res_comp.c res_debug.c res_init.c res_mkquery.c res_query.c \ X res_send.c strcasecmp.c named/gethnamadr.c named/sethostent.c \ X res_compat.c XOBJS= herror.o res_comp.o res_debug.o res_init.o res_mkquery.o res_query.o \ X res_send.o strcasecmp.o gethnamadr.o sethostent.o res_compat.o X# add -DDEBUG if you want the debugging code included X# add -DSYS5 if you are compiling under System V X# add -DEXOS if your computer has an EXCELAN board in it and you X# are using the EXCELAN host software X# XDEFS= -DSYS5 -DEXOS -DDEBUG XCFLAGS= -O ${DEFS} -I../include -I/usr/include/NET-5000 X# use echo is SYSTEM V, ranlib if 4.XBSD XRANLIB= echo X Xlibresolv.a: ${OBJS} X ar cru libresolv.a ${OBJS} X Xinstall: libresolv.a X cp libresolv.a ${DESTDIR}/usr/lib X chown bin ${DESTDIR}/usr/lib/libresolv.a X chgrp bin ${DESTDIR}/usr/lib/libresolv.a X chmod 644 ${DESTDIR}/usr/lib/libresolv.a X ${RANLIB} ${DESTDIR}/usr/lib/libresolv.a X X.c.o: X ${CC} ${CFLAGS} -c $*.c X -ld -x -r $*.o X mv a.out $*.o X Xgethnamadr.o: named/gethnamadr.c X ${CC} -c ${CFLAGS} named/gethnamadr.c X -ld -x -r gethnamadr.o X mv a.out gethnamadr.o X Xsethostent.o: named/sethostent.c X ${CC} -c ${CFLAGS} named/sethostent.c X -ld -x -r sethostent.o X mv a.out sethostent.o X Xclean: FRC X rm -f *.o errs a.out core libresolv.a tags X Xdepend: FRC X ../tools/mkdep -f Makfile.resolv ${CFLAGS} ${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 X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY SHAR_EOF if test 2051 -ne "`wc -c < 'Makefile.resol'`" then echo shar: "error transmitting 'Makefile.resol'" '(should have been 2051 characters)' fi fi echo shar: "extracting 'makefile'" '(2094 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) 1988 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# from @(#)Makefile 5.16 (Berkeley) 3/14/88 X# XSHELL= /bin/sh XSRCS= herror.c res_comp.c res_debug.c res_init.c res_mkquery.c res_query.c \ X res_send.c strcasecmp.c named/gethnamadr.c named/sethostent.c \ X res_compat.c XOBJS= herror.o res_comp.o res_debug.o res_init.o res_mkquery.o res_query.o \ X res_send.o strcasecmp.o gethnamadr.o sethostent.o res_compat.o X# add -DDEBUG if you want the debugging code included X# add -DSYS5 if you are compiling under System V X# add -DEXOS if your computer has an EXCELAN board in it and you X# are using the EXCELAN host software X# add -DMASSCOMP is your computer is a MASSCOMP X# XDEFS= -DSYS5 -DMASSCOMP -DDEBUG XCFLAGS= -O ${DEFS} -I../include X# use echo is SYSTEM V, ranlib if 4.XBSD or MASSCOMP XRANLIB= ranlib X Xlibresolv.a: ${OBJS} X ar cru libresolv.a ${OBJS} X Xinstall: libresolv.a X cp libresolv.a ${DESTDIR}/usr/lib X chown bin ${DESTDIR}/usr/lib/libresolv.a X chgrp bin ${DESTDIR}/usr/lib/libresolv.a X chmod 644 ${DESTDIR}/usr/lib/libresolv.a X ${RANLIB} ${DESTDIR}/usr/lib/libresolv.a X X.c.o: X ${CC} ${CFLAGS} -c $*.c X -ld -x -r $*.o X mv a.out $*.o X Xgethnamadr.o: named/gethnamadr.c X ${CC} -c ${CFLAGS} named/gethnamadr.c X -ld -x -r gethnamadr.o X mv a.out gethnamadr.o X Xsethostent.o: named/sethostent.c X ${CC} -c ${CFLAGS} named/sethostent.c X -ld -x -r sethostent.o X mv a.out sethostent.o X Xclean: FRC X rm -f *.o errs a.out core libresolv.a tags X Xdepend: FRC X ../tools/mkdep -f Makfile.resolv ${CFLAGS} ${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 X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY SHAR_EOF if test 2094 -ne "`wc -c < 'makefile'`" then echo shar: "error transmitting 'makefile'" '(should have been 2094 characters)' fi fi echo shar: "extracting 'res_debug.c'" '(12802 characters)' if test -f 'res_debug.c' then echo shar: "will not over-write existing file 'res_debug.c'" else sed 's/^ X//' << \SHAR_EOF > 'res_debug.c' X/* X * Copyright (c) 1985 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 X#if defined(LIBC_SCCS) && !defined(lint) Xstatic char sccsid[] = "@(#)res_debug.c 5.22 (Berkeley) 3/7/88"; X#endif /* LIBC_SCCS and not lint */ X X#if defined(lint) && !defined(DEBUG) X#define DEBUG X#endif X X#includeX#ifdef EXOS X#include X#undef XFER X#endif X#include X#include X#include X#ifdef XFER X#include X#include Xextern char *malloc(); X#endif /* XFER */ X Xextern char *p_cdname(), *p_rr(), *p_type(), *p_class(), *p_time(); Xextern char *inet_ntoa(); X Xchar *_res_opcodes[] = { X "QUERY", X "IQUERY", X "CQUERYM", X "CQUERYU", X "4", X "5", X "6", X "7", X "8", X "UPDATEA", X "UPDATED", X "UPDATEDA", X "UPDATEM", X "UPDATEMA", X "ZONEINIT", X "ZONEREF", X}; X Xchar *_res_resultcodes[] = { X "NOERROR", X "FORMERR", X "SERVFAIL", X "NXDOMAIN", X "NOTIMP", X "REFUSED", X "6", X "7", X "8", X "9", X "10", X "11", X "12", X "13", X "14", X "NOCHANGE", X}; X Xp_query(msg) X char *msg; X{ X#ifdef DEBUG X fp_query(msg,stdout); X#endif X} X X/* X * Print the contents of a query. X * This is intended to be primarily a debugging routine. X */ Xfp_query(msg,file) X char *msg; X FILE *file; X{ X#ifdef DEBUG X register char *cp; X register HEADER *hp; X register int n; X X /* X * Print header fields. X */ X hp = (HEADER *)msg; X cp = msg + sizeof(HEADER); X fprintf(file,"HEADER:\n"); X fprintf(file,"\topcode = %s", _res_opcodes[hp->opcode]); X fprintf(file,", id = %d", ntohs(hp->id)); X fprintf(file,", rcode = %s\n", _res_resultcodes[hp->rcode]); X fprintf(file,"\theader flags: "); X if (hp->qr) X fprintf(file," qr"); X if (hp->aa) X fprintf(file," aa"); X if (hp->tc) X fprintf(file," tc"); X if (hp->rd) X fprintf(file," rd"); X if (hp->ra) X fprintf(file," ra"); X if (hp->pr) X fprintf(file," pr"); X fprintf(file,"\n\tqdcount = %d", ntohs(hp->qdcount)); X fprintf(file,", ancount = %d", ntohs(hp->ancount)); X fprintf(file,", nscount = %d", ntohs(hp->nscount)); X fprintf(file,", arcount = %d\n\n", ntohs(hp->arcount)); X /* X * Print question records. X */ X if (n = ntohs(hp->qdcount)) { X fprintf(file,"QUESTIONS:\n"); X while (--n >= 0) { X fprintf(file,"\t"); X cp = p_cdname(cp, msg, file); X if (cp == NULL) X return; X fprintf(file,", type = %s", p_type(_getshort(cp))); X cp += sizeof(u_short); X fprintf(file,", class = %s\n\n", p_class(_getshort(cp))); X cp += sizeof(u_short); X } X } X /* X * Print authoritative answer records X */ X if (n = ntohs(hp->ancount)) { X fprintf(file,"ANSWERS:\n"); X while (--n >= 0) { X fprintf(file,"\t"); X cp = p_rr(cp, msg, file); X if (cp == NULL) X return; X } X } X /* X * print name server records X */ X if (n = ntohs(hp->nscount)) { X fprintf(file,"NAME SERVERS:\n"); X while (--n >= 0) { X fprintf(file,"\t"); X cp = p_rr(cp, msg, file); X if (cp == NULL) X return; X } X } X /* X * print additional records X */ X if (n = ntohs(hp->arcount)) { X fprintf(file,"ADDITIONAL RECORDS:\n"); X while (--n >= 0) { X fprintf(file,"\t"); X cp = p_rr(cp, msg, file); X if (cp == NULL) X return; X } X } X#endif X} X Xchar * Xp_cdname(cp, msg, file) X char *cp, *msg; X FILE *file; X{ X#ifdef DEBUG X char name[MAXDNAME]; X int n; X X if ((n = dn_expand(msg, msg + 512, cp, name, sizeof(name))) < 0) X return (NULL); X if (name[0] == '\0') { X name[0] = '.'; X name[1] = '\0'; X } X fputs(name, file); X return (cp + n); X#endif X} X X/* X * Print resource record fields in human readable form. X */ Xchar * Xp_rr(cp, msg, file) X char *cp, *msg; X FILE *file; X{ X#ifdef DEBUG X int type, class, dlen, n, c; X struct in_addr inaddr; X char *cp1; X X if ((cp = p_cdname(cp, msg, file)) == NULL) X return (NULL); /* compression error */ X fprintf(file,"\n\ttype = %s", p_type(type = _getshort(cp))); X cp += sizeof(u_short); X fprintf(file,", class = %s", p_class(class = _getshort(cp))); X cp += sizeof(u_short); X fprintf(file,", ttl = %s", p_time(_getlong(cp))); X cp += sizeof(u_long); X fprintf(file,", dlen = %d\n", dlen = _getshort(cp)); X cp += sizeof(u_short); X cp1 = cp; X /* X * Print type specific data, if appropriate X */ X switch (type) { X case T_A: X switch (class) { X case C_IN: X#ifdef SYS5 X (void)memcpy((char *)&inaddr, cp, sizeof(inaddr)); X#else X bcopy(cp, (char *)&inaddr, sizeof(inaddr)); X#endif X if (dlen == 4) { X fprintf(file,"\tinternet address = %s\n", X inet_ntoa(inaddr)); X cp += dlen; X } else if (dlen == 7) { X fprintf(file,"\tinternet address = %s", X inet_ntoa(inaddr)); X fprintf(file,", protocol = %d", cp[4]); X fprintf(file,", port = %d\n", X (cp[5] << 8) + cp[6]); X cp += dlen; X } X break; X default: X cp += dlen; X } X break; X case T_CNAME: X case T_MB: X#ifdef OLDRR X case T_MD: X case T_MF: X#endif /* OLDRR */ X case T_MG: X case T_MR: X case T_NS: X case T_PTR: X fprintf(file,"\tdomain name = "); X cp = p_cdname(cp, msg, file); X fprintf(file,"\n"); X break; X X case T_HINFO: X if (n = *cp++) { X fprintf(file,"\tCPU=%.*s\n", n, cp); X cp += n; X } X if (n = *cp++) { X fprintf(file,"\tOS=%.*s\n", n, cp); X cp += n; X } X break; X X case T_SOA: X fprintf(file,"\torigin = "); X cp = p_cdname(cp, msg, file); X fprintf(file,"\n\tmail addr = "); X cp = p_cdname(cp, msg, file); X fprintf(file,"\n\tserial=%ld", _getlong(cp)); X cp += sizeof(u_long); X fprintf(file,", refresh=%s", p_time(_getlong(cp))); X cp += sizeof(u_long); X fprintf(file,", retry=%s", p_time(_getlong(cp))); X cp += sizeof(u_long); X fprintf(file,", expire=%s", p_time(_getlong(cp))); X cp += sizeof(u_long); X fprintf(file,", min=%s\n", p_time(_getlong(cp))); X cp += sizeof(u_long); X break; X X case T_MX: X fprintf(file,"\tpreference = %ld,",_getshort(cp)); X cp += sizeof(u_short); X fprintf(file," name = "); X cp = p_cdname(cp, msg, file); X break; X X case T_MINFO: X fprintf(file,"\trequests = "); X cp = p_cdname(cp, msg, file); X fprintf(file,"\n\terrors = "); X cp = p_cdname(cp, msg, file); X break; X X case T_UINFO: X fprintf(file,"\t%s\n", cp); X cp += dlen; X break; X X case T_UID: X case T_GID: X if (dlen == 4) { X fprintf(file,"\t%ld\n", _getlong(cp)); X cp += sizeof(int); X } X break; X X case T_WKS: X if (dlen < sizeof(u_long) + 1) X break; X#ifdef SYS5 X (void)memcpy ((char *)&inaddr, cp, sizeof(inaddr)); X#else X bcopy(cp, (char *)&inaddr, sizeof(inaddr)); X#endif X cp += sizeof(u_long); X fprintf(file,"\tinternet address = %s, protocol = %d\n\t", X inet_ntoa(inaddr), *cp++); X n = 0; X while (cp < cp1 + dlen) { X c = *cp++; X do { X if (c & 0200) X fprintf(file," %d", n); X c <<= 1; X } while (++n & 07); X } X putc('\n',file); X break; X X#ifdef ALLOW_T_UNSPEC X case T_UNSPEC: X { X int NumBytes = 8; X char *DataPtr; X int i; X X if (dlen < NumBytes) NumBytes = dlen; X fprintf(file, "\tFirst %d bytes of hex data:", X NumBytes); X for (i = 0, DataPtr = cp; i < NumBytes; i++, DataPtr++) X fprintf(file, " %x", *DataPtr); X fputs("\n", file); X cp += dlen; X } X break; X#endif /* ALLOW_T_UNSPEC */ X X default: X fprintf(file,"\t???\n"); X cp += dlen; X } X if (cp != cp1 + dlen) X fprintf(file,"packet size error (%#x != %#x)\n", cp, cp1+dlen); X fprintf(file,"\n"); X return (cp); X#endif X} X Xstatic char nbuf[20]; X X/* X * Return a string for the type X */ Xchar * Xp_type(type) X int type; X{ X switch (type) { X case T_A: X return("A"); X case T_NS: /* authoritative server */ X return("NS"); X#ifdef OLDRR X case T_MD: /* mail destination */ X return("MD"); X case T_MF: /* mail forwarder */ X return("MF"); X#endif /* OLDRR */ X case T_CNAME: /* connonical name */ X return("CNAME"); X case T_SOA: /* start of authority zone */ X return("SOA"); X case T_MB: /* mailbox domain name */ X return("MB"); X case T_MG: /* mail group member */ X return("MG"); X case T_MX: /* mail routing info */ X return("MX"); X case T_MR: /* mail rename name */ X return("MR"); X case T_NULL: /* null resource record */ X return("NULL"); X case T_WKS: /* well known service */ X return("WKS"); X case T_PTR: /* domain name pointer */ X return("PTR"); X case T_HINFO: /* host information */ X return("HINFO"); X case T_MINFO: /* mailbox information */ X return("MINFO"); X case T_AXFR: /* zone transfer */ X return("AXFR"); X case T_MAILB: /* mail box */ X return("MAILB"); X case T_MAILA: /* mail address */ X return("MAILA"); X case T_ANY: /* matches any type */ X return("ANY"); X case T_UINFO: X return("UINFO"); X case T_UID: X return("UID"); X case T_GID: X return("GID"); X#ifdef ALLOW_T_UNSPEC X case T_UNSPEC: X return("UNSPEC"); X#endif /* ALLOW_T_UNSPEC */ X default: X (void)sprintf(nbuf, "%d", type); X return(nbuf); X } X} X X/* X * Return a mnemonic for class X */ Xchar * Xp_class(class) X int class; X{ X X switch (class) { X case C_IN: /* internet class */ X return("IN"); X case C_ANY: /* matches any class */ X return("ANY"); X default: X (void)sprintf(nbuf, "%d", class); X return(nbuf); X } X} X X#ifdef XFER X/* X * Make a copy of a string and return a pointer to it. X */ Xstatic char * Xsavestr(str) X char *str; X{ X char *cp; X X cp = malloc((unsigned)strlen(str) + 1); X if (cp == NULL) { X syslog(LOG_ERR, "savestr: %m"); X exit(1); X } X (void) strcpy(cp, str); X return (cp); X} X Xchar * Xp_protocal(num) X int num; X{ X static char number[8]; X struct protoent *pp; X extern struct protoent *cgetprotobynumber(); X X pp = cgetprotobynumber(num); X if(pp == 0) { X (void) sprintf(number, "%d", num); X return(number); X } X return(pp->p_name); X} X Xchar * Xp_service(port, proto) X u_short port; X char *proto; X{ X static char number[8]; X struct servent *ss; X extern struct servent *cgetservbyport(); X X ss = cgetservbyport((int)htons(port), proto); X if(ss == 0) { X (void) sprintf(number, "%d", port); X return(number); X } X return(ss->s_name); X} X X Xstruct valuelist { X struct valuelist *next, *prev; X char *name; X char *proto; X short port; X} *servicelist, *protolist; X Xbuildservicelist() X{ X struct servent *sp; X struct valuelist *slp; X X setservent(1); X while (sp = getservent()) { X slp = (struct valuelist *)malloc(sizeof(struct valuelist)); X slp->name = savestr(sp->s_name); X slp->proto = savestr(sp->s_proto); X slp->port = ntohs(sp->s_port); X slp->next = servicelist; X slp->prev = NULL; X if (servicelist) { X servicelist->prev = slp; X } X servicelist = slp; X } X endservent(); X} X Xbuildprotolist() X{ X struct protoent *pp; X struct valuelist *slp; X X setprotoent(1); X while (pp = getprotoent()) { X slp = (struct valuelist *)malloc(sizeof(struct valuelist)); X slp->name = savestr(pp->p_name); X slp->port = pp->p_proto; X slp->next = protolist; X slp->prev = NULL; X if (protolist) { X protolist->prev = slp; X } X protolist = slp; X } X endprotoent(); X} X Xstruct servent * Xcgetservbyport(port, proto) X u_short port; X char *proto; X{ X register struct valuelist **list = &servicelist; X register struct valuelist *lp = *list; X static struct servent serv; X X port = htons(port); X for (; lp != NULL; lp = lp->next) { X if (port != lp->port) X continue; X if (strcasecmp(lp->proto, proto) == 0) { X if (lp != *list) { X lp->prev->next = lp->next; X if (lp->next) X lp->next->prev = lp->prev; X (*list)->prev = lp; X lp->next = *list; X *list = lp; X } X serv.s_name = lp->name; X serv.s_port = htons(lp->port); X serv.s_proto = lp->proto; X return(&serv); X } X } X return(0); X} X Xstruct protoent * Xcgetprotobynumber(proto) X register int proto; X{ X X register struct valuelist **list = &protolist; X register struct valuelist *lp = *list; X static struct protoent prot; X X for (; lp != NULL; lp = lp->next) X if (lp->port == proto) { X if (lp != *list) { X lp->prev->next = lp->next; X if (lp->next) X lp->next->prev = lp->prev; X (*list)->prev = lp; X lp->next = *list; X *list = lp; X } X prot.p_name = lp->name; X prot.p_proto = lp->port; X return(&prot); X } X return(0); X} X X#endif /* XFER */ X X/* X * Return a mnemonic for a time to live X */ Xchar * Xp_time(value) X unsigned long value; X{ X int secs, mins, hours; X static char buf[128]; X X secs = value % 60; X value /= 60; X mins = value % 60; X value /= 60; X hours = value % 24; X value /= 24; X X# define PLURALIZE(x) x, (x==1)?"":"s" X if (value) X (void) sprintf(buf, "%d day%s", PLURALIZE(value)); X else X strcpy(buf, ""); X if (hours) { X (void) sprintf(nbuf, " %d hour%s", PLURALIZE(hours)); X (void) strcat(buf, nbuf); X } X if (mins) { X (void) sprintf(nbuf, " %d min%s", PLURALIZE(mins)); X (void) strcat(buf, nbuf); X } X if (secs) { X (void) sprintf(nbuf, " %d sec%s", PLURALIZE(secs)); X (void) strcat(buf, nbuf); X } X return (buf); X} X SHAR_EOF if test 12802 -ne "`wc -c < 'res_debug.c'`" then echo shar: "error transmitting 'res_debug.c'" '(should have been 12802 characters)' fi fi echo shar: "extracting 'res_comp.c'" '(6673 characters)' if test -f 'res_comp.c' then echo shar: "will not over-write existing file 'res_comp.c'" else sed 's/^ X//' << \SHAR_EOF > 'res_comp.c' X/* X * Copyright (c) 1985 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 X#if defined(LIBC_SCCS) && !defined(lint) Xstatic char sccsid[] = "@(#)res_comp.c 6.13 (Berkeley) 3/13/88"; X#endif /* LIBC_SCCS and not lint */ X X#include X#ifdef EXOS X#include X#endif X#include X#include X X X/* X * Expand compressed domain name 'comp_dn' to full domain name. X * 'msg' is a pointer to the begining of the message, X * 'eomorig' points to the first location after the message, X * 'exp_dn' is a pointer to a buffer of size 'length' for the result. X * Return size of compressed name or -1 if there was an error. X */ Xdn_expand(msg, eomorig, comp_dn, exp_dn, length) X u_char *msg, *eomorig, *comp_dn, *exp_dn; X int length; X{ X register u_char *cp, *dn; X register int n, c; X u_char *eom; X int len = -1, checked = 0; X X dn = exp_dn; X cp = comp_dn; X eom = exp_dn + length - 1; X /* X * fetch next label in domain name X */ X while (n = *cp++) { X /* X * Check for indirection X */ X switch (n & INDIR_MASK) { X case 0: X if (dn != exp_dn) { X if (dn >= eom) X return (-1); X *dn++ = '.'; X } X if (dn+n >= eom) X return (-1); X checked += n + 1; X while (--n >= 0) { X if ((c = *cp++) == '.') { X if (dn+n+1 >= eom) X return (-1); X *dn++ = '\\'; X } X *dn++ = c; X if (cp >= eomorig) /* out of range */ X return(-1); X } X break; X X case INDIR_MASK: X if (len < 0) X len = cp - comp_dn + 1; X cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); X if (cp < msg || cp >= eomorig) /* out of range */ X return(-1); X checked += 2; X /* X * Check for loops in the compressed name; X * if we've looked at the whole message, X * there must be a loop. X */ X if (checked >= eomorig - msg) X return (-1); X break; X X default: X return (-1); /* flag error */ X } X } X *dn = '\0'; X if (len < 0) X len = cp - comp_dn; X return (len); X} X X/* X * Compress domain name 'exp_dn' into 'comp_dn'. X * Return the size of the compressed name or -1. X * 'length' is the size of the array pointed to by 'comp_dn'. X * 'dnptrs' is a list of pointers to previous compressed names. dnptrs[0] X * is a pointer to the beginning of the message. The list ends with NULL. X * 'lastdnptr' is a pointer to the end of the arrary pointed to X * by 'dnptrs'. Side effect is to update the list of pointers for X * labels inserted into the message as we compress the name. X * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' X * is NULL, we don't update the list. X */ Xdn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr) X u_char *exp_dn, *comp_dn; X int length; X u_char **dnptrs, **lastdnptr; X{ X register u_char *cp, *dn; X register int c, l; X u_char **cpp, **lpp, *sp, *eob; X u_char *msg; X X dn = exp_dn; X cp = comp_dn; X eob = cp + length; X if (dnptrs != NULL) { X if ((msg = *dnptrs++) != NULL) { X for (cpp = dnptrs; *cpp != NULL; cpp++) X ; X lpp = cpp; /* end of list to search */ X } X } else X msg = NULL; X for (c = *dn++; c != '\0'; ) { X /* look to see if we can use pointers */ X if (msg != NULL) { X if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) { X if (cp+1 >= eob) X return (-1); X *cp++ = (l >> 8) | INDIR_MASK; X *cp++ = l % 256; X return (cp - comp_dn); X } X /* not found, save it */ X if (lastdnptr != NULL && cpp < lastdnptr-1) { X *cpp++ = cp; X *cpp = NULL; X } X } X sp = cp++; /* save ptr to length byte */ X do { X if (c == '.') { X c = *dn++; X break; X } X if (c == '\\') { X if ((c = *dn++) == '\0') X break; X } X if (cp >= eob) X return (-1); X *cp++ = c; X } while ((c = *dn++) != '\0'); X /* catch trailing '.'s but not '..' */ X if ((l = cp - sp - 1) == 0 && c == '\0') { X cp--; X break; X } X if (l <= 0 || l > MAXLABEL) X return (-1); X *sp = l; X } X if (cp >= eob) X return (-1); X *cp++ = '\0'; X return (cp - comp_dn); X} X X/* X * Skip over a compressed domain name. Return the size or -1. X */ Xdn_skipname(comp_dn, eom) X u_char *comp_dn, *eom; X{ X register u_char *cp; X register int n; X X cp = comp_dn; X while (cp < eom && (n = *cp++)) { X /* X * check for indirection X */ X switch (n & INDIR_MASK) { X case 0: /* normal case, n == len */ X cp += n; X continue; X default: /* illegal type */ X return (-1); X case INDIR_MASK: /* indirection */ X cp++; X } X break; X } X return (cp - comp_dn); X} X X/* X * Search for expanded name from a list of previously compressed names. X * Return the offset from msg if found or -1. X * dnptrs is the pointer to the first name on the list, X * not the pointer to the start of the message. X */ Xstatic Xdn_find(exp_dn, msg, dnptrs, lastdnptr) X u_char *exp_dn, *msg; X u_char **dnptrs, **lastdnptr; X{ X register u_char *dn, *cp, **cpp; X register int n; X u_char *sp; X X for (cpp = dnptrs; cpp < lastdnptr; cpp++) { X dn = exp_dn; X sp = cp = *cpp; X while (n = *cp++) { X /* X * check for indirection X */ X switch (n & INDIR_MASK) { X case 0: /* normal case, n == len */ X while (--n >= 0) { X if (*dn == '\\') X dn++; X if (*dn++ != *cp++) X goto next; X } X if ((n = *dn++) == '\0' && *cp == '\0') X return (sp - msg); X if (n == '.') X continue; X goto next; X X default: /* illegal type */ X return (-1); X X case INDIR_MASK: /* indirection */ X cp = msg + (((n & 0x3f) << 8) | *cp); X } X } X if (*dn == '\0') X return (sp - msg); X next: ; X } X return (-1); X} X X/* X * Routines to insert/extract short/long's. Must account for byte X * order and non-alignment problems. This code at least has the X * advantage of being portable. X * X * used by sendmail. X */ X Xu_short X_getshort(msgp) X u_char *msgp; X{ X register u_char *p = (u_char *) msgp; X#ifdef vax X /* X * vax compiler doesn't put shorts in registers X */ X register u_long u; X#else X register u_short u; X#endif X X u = *p++ << 8; X return ((u_short)(u | *p)); X} X Xu_long X_getlong(msgp) X u_char *msgp; X{ X register u_char *p = (u_char *) msgp; X register u_long u; X X u = *p++; u <<= 8; X u |= *p++; u <<= 8; X u |= *p++; u <<= 8; X return (u | *p); X} X X Xputshort(s, msgp) X register u_short s; X register u_char *msgp; X{ X X msgp[1] = s; X msgp[0] = s >> 8; X} X Xputlong(l, msgp) X register u_long l; X register u_char *msgp; X{ X X msgp[3] = l; X msgp[2] = (l >>= 8); X msgp[1] = (l >>= 8); X msgp[0] = l >> 8; X} SHAR_EOF if test 6673 -ne "`wc -c < 'res_comp.c'`" then echo shar: "error transmitting 'res_comp.c'" '(should have been 6673 characters)' fi fi echo shar: "extracting 'res_compat.c'" '(2469 characters)' if test -f 'res_compat.c' then echo shar: "will not over-write existing file 'res_compat.c'" else sed 's/^ X//' << \SHAR_EOF > 'res_compat.c' X/* X * This file contains routines that will resolve compatibilities between X * System V and BSD versions of Unix. X */ X X#if defined(LIBC_SCCS) && !defined(lint) Xstatic char sccsid[] = "@(#)res_compat 1.0 (Baylor College of Medicine)"; X#endif /* LIBC_SCCS and not lint */ X X#ifdef SYS5 X#include X#include X#include X#include X#ifdef EXOS X#include X X/* X * inet_ntoa() returns a character string representing the address X * passed in the arguement. X */ X Xchar * Xinet_ntoa(in) Xstruct in_addr in; X{ X static char address[20]; X X sprintf(address, "%u.%u.%u.%u", X (in.s_addr>>24)&0xff, X (in.s_addr>>16)&0xff, X (in.s_addr>>8 )&0xff, X (in.s_addr )&0xff); X return(address); X} X X#endif EXOS X X/* X * inet_addr() returns a long given a string representation of X * an internet address X */ Xunsigned long Xinet_addr(cp) Xregister char * cp; X{ X unsigned long val, base, n; X register char c; X unsigned long octet[4], *octetptr = octet; X#ifndef htonl X extern unsigned long htonl(); X#endif htonl Xagain: X /* X * Collect number up to ``.''. X * Values are specified as for C: X * 0x=hex, 0=octal, other=decimal. X */ X val = 0; base = 10; X if (*cp == '0') X base = 8, cp++; X if (*cp == 'x' || *cp == 'X') X base = 16, cp++; X while (c = *cp) { X if (isdigit(c)) { X val = (val * base) + (c - '0'); X cp++; X continue; X } X if (base == 16 && isxdigit(c)) { X val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); X cp++; X continue; X } X break; X } X if (*cp == '.') { X /* X * Internet format: X * a.b.c.d X * a.b.c (with c treated as 16-bits) X * a.b (with b treated as 24 bits) X */ X if (octetptr >= octet + 4) X return (-1); X *octetptr++ = val, cp++; X goto again; X } X /* X * Check for trailing characters. X */ X if (*cp && !isspace(*cp)) X return (-1); X *octetptr++ = val; X /* X * Concoct the address according to X * the number of octet specified. X */ X n = octetptr - octet; X switch (n) { X X case 1: /* a -- 32 bits */ X val = octet[0]; X break; X X case 2: /* a.b -- 8.24 bits */ X val = (octet[0] << 24) | (octet[1] & 0xffffff); X break; X X case 3: /* a.b.c -- 8.8.16 bits */ X val = (octet[0] << 24) | ((octet[1] & 0xff) << 16) | X (octet[2] & 0xffff); X break; X X case 4: /* a.b.c.d -- 8.8.8.8 bits */ X val = (octet[0] << 24) | ((octet[1] & 0xff) << 16) | X ((octet[2] & 0xff) << 8) | (octet[3] & 0xff); X break; X X default: X return (-1); X } X val = htonl(val); X return (val); X} X#endif SYS5 SHAR_EOF if test 2469 -ne "`wc -c < 'res_compat.c'`" then echo shar: "error transmitting 'res_compat.c'" '(should have been 2469 characters)' fi fi echo shar: "extracting 'herror.c'" '(1599 characters)' if test -f 'herror.c' then echo shar: "will not over-write existing file 'herror.c'" else sed 's/^ X//' << \SHAR_EOF > 'herror.c' X/* X * Copyright (c) 1987 Regents of the University of California. X * All rights reserved. The Berkeley software License Agreement X * specifies the terms and conditions for redistribution. X */ X X#if defined(LIBC_SCCS) && !defined(lint) Xstatic char sccsid[] = "@(#)herror.c 6.1 (Berkeley) 12/4/87"; X#endif LIBC_SCCS and not lint X X#include X#ifndef SYS5 X#include X#endif X Xchar *h_errlist[] = { X "Error 0", X "Unknown host", /* 1 HOST_NOT_FOUND */ X "Host name lookup failure", /* 2 TRY_AGAIN */ X "Unknown server error", /* 3 NO_RECOVERY */ X "No address associated with name", /* 4 NO_ADDRESS */ X}; Xint h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; X Xextern int h_errno; X X/* X * herror -- X * print the error indicated by the h_errno value. X */ Xherror(s) X char *s; X{ X#ifdef SYS5 X int len; X char * hmsg; X if (s == (char * ) h_errno) len = 0; X /* X * compensate for persons who X * don't read instructions! X */ X else len = strlen(s); X if (len > 0){ X if (write(2,s, (unsigned) len) != len) X return; X if (write(2, ": ",2) != 2) X return; X } X hmsg = "Unknown error"; X if (h_errno < h_nerr && h_errno > 0) X hmsg = h_errlist[h_errno]; X write(2,hmsg,(unsigned)strlen(hmsg)); X write(2,"\n",1); X#else X struct iovec iov[4]; X register struct iovec *v = iov; X X if (s && *s) { X v->iov_base = s; X v->iov_len = strlen(s); X v++; X v->iov_base = ": "; X v->iov_len = 2; X v++; X } X v->iov_base = h_errno < h_nerr ? h_errlist[h_errno] : "Unknown error"; X v->iov_len = strlen(v->iov_base); X v++; X v->iov_base = "\n"; X v->iov_len = 1; X writev(2, iov, (v - iov) + 1); X#endif X} SHAR_EOF if test 1599 -ne "`wc -c < 'herror.c'`" then echo shar: "error transmitting 'herror.c'" '(should have been 1599 characters)' fi fi echo shar: "extracting 'strcasecmp.c'" '(3014 characters)' if test -f 'strcasecmp.c' then echo shar: "will not over-write existing file 'strcasecmp.c'" else sed 's/^ X//' << \SHAR_EOF > 'strcasecmp.c' X/* X * Copyright (c) 1987 Regents of the University of California. X * All rights reserved. The Berkeley software License Agreement X * specifies the terms and conditions for redistribution. X */ X X#if defined(LIBC_SCCS) && !defined(lint) Xstatic char sccsid[] = "@(#)strcasecmp.c 1.3 (Berkeley) 8/3/87"; X#endif LIBC_SCCS and not lint X X/* X * This array is designed for mapping upper and lower case letter X * together for a case independent comparison. The mappings are X * based upon ascii character sequences. X */ Xstatic char charmap[] = { X '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', X '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', X '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', X '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', X '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', X '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', X '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', X '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', X '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', X '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', X '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', X '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', X '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', X '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', X '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', X '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', X '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', X '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', X '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', X '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', X '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', X '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', X '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', X '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', X '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', X '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', X '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', X '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', X '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', X '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', X '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', X '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', X}; X Xstrcasecmp(s1, s2) X register char *s1, *s2; X{ X register char *cm = charmap; X X while (cm[*s1] == cm[*s2++]) X if (*s1++ == '\0') X return(0); X return(cm[*s1] - cm[*--s2]); X} X Xstrncasecmp(s1, s2, n) X register char *s1, *s2; X register int n; X{ X register char *cm = charmap; X X while (--n >= 0 && cm[*s1] == cm[*s2++]) X if (*s1++ == '\0') X return(0); X return(n < 0 ? 0 : cm[*s1] - cm[*--s2]); X} SHAR_EOF if test 3014 -ne "`wc -c < 'strcasecmp.c'`" then echo shar: "error transmitting 'strcasecmp.c'" '(should have been 3014 characters)' fi fi exit 0 # End of shell archive