home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / ns2tab / part01 < prev    next >
Encoding:
Text File  |  1993-04-03  |  59.1 KB  |  2,295 lines

  1. Newsgroups: comp.sources.unix
  2. From: i3558@newsie.dc.dk (Soeren Michael Roug)
  3. Subject: v26i092: ns2tab - Increasing the usefullnes of the nameserver, Part01/03
  4. Sender: unix-sources-moderator@vix.com
  5. Approved: paul@vix.com
  6.  
  7. Submitted-By: i3558@newsie.dc.dk (Soeren Michael Roug)
  8. Posting-Number: Volume 26, Issue 92
  9. Archive-Name: ns2tab/part01
  10.  
  11. Have you ever had one of the following needs?:
  12.  
  13. - To coordinate /usr/lib/aliases with /etc/group.
  14. - To extract a /etc/hosts table from the nameserver.
  15. - To provide slightly different /etc/group files on different systems.
  16. - To provide slightly different /usr/lib/aliases on different systems.
  17. - To update the GECOS field in /etc/passwd on several computers at once.
  18. - To have a central point where you maintain NFS hardmounts. With all
  19.   the different filesystem table formats out there that could not be done.
  20. - To provide different /etc/printcap files on different systems.
  21.  
  22. Then this piece of software is for you!
  23.  
  24. The principle is, as in Hesiod, to load the information in the BIND
  25. nameserver and then extract the information again in various styles.
  26.  
  27. If you find it usefull, then send a short note to <smr@dc.dk>. You don't
  28. have to write that you like it, but I will use the responses to determine
  29. how many resources to use to bring out new [and improved] versions.
  30.  
  31. Also, I would like to get suggestions for new types of tables, see also
  32. the TODO file.
  33.  
  34. BTW. There is NO WARRANTY on this package of any kind, so don't come
  35. to me, if you have overwritten your filesystem table with an error message.
  36.  
  37.     March 22, 1993
  38.     Sincerely,
  39.  
  40.     Soren Roug <smr@dc.dk>
  41.     Datacentralen A/S
  42.     Denmark
  43.  
  44. #! /bin/sh
  45. # This is a shell archive.  Remove anything before this line, then unpack
  46. # it by saving it into a file and typing "sh file".  To overwrite existing
  47. # files, type "sh file -c".  You can also feed this as standard input via
  48. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  49. # will see the following message at the end:
  50. #        "End of archive 1 (of 3)."
  51. # Contents:  MANIFEST Makefile README TODO debug.c ns2tab.8 p_time.c
  52. #   prime.c readv.c res.h send.c skip.c subr.c vtable.c vtable.h
  53. # Wrapped by i3558@ulrik.dc.dk on Fri Mar 26 15:05:32 1993
  54. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  55. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  56.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  57. else
  58. echo shar: Extracting \"'MANIFEST'\" \(828 characters\)
  59. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  60. X   File Name        Archive #    Description
  61. X-----------------------------------------------------------
  62. X MANIFEST                   1    This file
  63. X Makefile                   1    
  64. X README                     1    
  65. X TODO                       1    Ideas to improve this product
  66. X debug.c                    1    
  67. X getinfo.c                  2    
  68. X hash.c                     2    Hash package
  69. X list.c                     3    
  70. X main.c                     2    
  71. X ns2tab.8                   1    Man page
  72. X p_time.c                   1    
  73. X prime.c                    1    Primes
  74. X readv.c                    1    Emulation of readv(2) and writev(2)
  75. X res.h                      1    
  76. X send.c                     1    
  77. X skip.c                     1    
  78. X subr.c                     1    
  79. X vtable.c                   1    Variable length tables
  80. X vtable.h                   1    Variable length tables
  81. END_OF_FILE
  82. if test 828 -ne `wc -c <'MANIFEST'`; then
  83.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  84. fi
  85. # end of 'MANIFEST'
  86. fi
  87. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  88.   echo shar: Will not clobber existing file \"'Makefile'\"
  89. else
  90. echo shar: Extracting \"'Makefile'\" \(982 characters\)
  91. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  92. XCFLAGS=    -g -DBSD=43 -DSYSV -DEMULATE_HESIOD    #SCO & SYSV4
  93. X#LIBS=    $(RES) -lsocket                    #SCO
  94. X#RES=                            #SCO
  95. X#SUPS= readv.o                        #SCO
  96. XRES= -lresolv                        #SYSV4
  97. XLIBS=    -L/usr/ucblib $(RES) -lsocket -lnsl -lucb    #SYSV4
  98. XSUPS=                            #SYSV4 & BSD
  99. X#CFLAGS= -O -DBSD=43 -DEMULATE_HESIOD            #BSD
  100. X#RES=                            #BSD
  101. X#LIBS=    $(RES)                        #BSD
  102. X
  103. XSRCS=    main.c getinfo.c debug.c send.c skip.c list.c subr.c \
  104. X   hash.c prime.c vtable.c p_time.c readv.c
  105. XOBJS=    main.o getinfo.o debug.o send.o skip.o list.o subr.o \
  106. X   hash.o prime.o vtable.o p_time.o $(SUPS)
  107. XPROGRAM= ns2tab
  108. X
  109. Xall: $(PROGRAM)
  110. X
  111. X$(PROGRAM): $(OBJS)
  112. X    $(CC) -o $@ $(OBJS) $(LIBS)
  113. X
  114. Xclean:
  115. X    rm -f $(OBJS) core $(PROGRAM) ID
  116. X
  117. Xcleandir: clean
  118. X    rm -f tags .depend
  119. X
  120. Xdepend: $(SRCS)
  121. X    mkdep $(CFLAGS) $(SRCS)
  122. X
  123. Xinstall:
  124. X    install -s -o bin -g bin -m 755 $(PROGRAM) $(DESTDIR)/usr/local/bin
  125. X#    install -c -o bin -g bin -m 444 $(PROGRAM).8 \
  126. X#     $(DESTDIR)/usr/local/man/man8
  127. X
  128. Xlint: $(SRCS)
  129. X    lint $(SRCS)
  130. X
  131. Xtags: $(CSRCS)
  132. X    ctags $(CSRCS)
  133. X
  134. Xmakekit: ;makekit -m
  135. END_OF_FILE
  136. if test 982 -ne `wc -c <'Makefile'`; then
  137.     echo shar: \"'Makefile'\" unpacked with wrong size!
  138. fi
  139. # end of 'Makefile'
  140. fi
  141. if test -f 'README' -a "${1}" != "-c" ; then 
  142.   echo shar: Will not clobber existing file \"'README'\"
  143. else
  144. echo shar: Extracting \"'README'\" \(1350 characters\)
  145. sed "s/^X//" >'README' <<'END_OF_FILE'
  146. XThis is the README file for ns2tab version 1.0
  147. X
  148. XHave you ever had one of the following needs?:
  149. X
  150. X- To coordinate /usr/lib/aliases with /etc/group.
  151. X- To extract a /etc/hosts table from the nameserver.
  152. X- To provide slightly different /etc/group files on different systems.
  153. X- To provide slightly different /usr/lib/aliases on different systems.
  154. X- To update the GECOS field in /etc/passwd on several computers at once.
  155. X- To have a central point where you maintain NFS hardmounts. With all
  156. X  the different filesystem table formats out there that could not be done.
  157. X- To provide different /etc/printcap files on different systems.
  158. X
  159. XThen this piece of software is for you!
  160. X
  161. XThe principle is, as in Hesiod, to load the information in the BIND
  162. Xnameserver and then extract the information again in various styles.
  163. X
  164. XIf you find it usefull, then send a short note to <smr@dc.dk>. You don't
  165. Xhave to write that you like it, but I will use the responses to determine
  166. Xhow many resources to use to bring out new [and improved] versions.
  167. X
  168. XAlso, I would like to get suggestions for new types of tables, see also
  169. Xthe TODO file.
  170. X
  171. XBTW. There is NO WARRANTY on this package of any kind, so don't come
  172. Xto me, if you have overwritten your filesystem table with an error message.
  173. X
  174. X    March 22, 1993
  175. X    Sincerely,
  176. X
  177. X    Soren Roug <smr@dc.dk>
  178. X    Datacentralen A/S
  179. X    Denmark
  180. END_OF_FILE
  181. if test 1350 -ne `wc -c <'README'`; then
  182.     echo shar: \"'README'\" unpacked with wrong size!
  183. fi
  184. # end of 'README'
  185. fi
  186. if test -f 'TODO' -a "${1}" != "-c" ; then 
  187.   echo shar: Will not clobber existing file \"'TODO'\"
  188. else
  189. echo shar: Extracting \"'TODO'\" \(417 characters\)
  190. sed "s/^X//" >'TODO' <<'END_OF_FILE'
  191. X- Full emulation of Hesiod.
  192. X
  193. X- Software that can use these tables and install them the correct place.
  194. X
  195. X- Examples of correct use.
  196. X
  197. X- An /etc/ethers extraction facility.
  198. X
  199. X- An automount map extraction facility for those automounters that doesn't
  200. X  have NIS.
  201. X
  202. X- I need a little program that can get the serial number from a domain.
  203. X  With this I can test for updates, and if nothing has changed, avoid
  204. X  a costly XFER.
  205. END_OF_FILE
  206. if test 417 -ne `wc -c <'TODO'`; then
  207.     echo shar: \"'TODO'\" unpacked with wrong size!
  208. fi
  209. # end of 'TODO'
  210. fi
  211. if test -f 'debug.c' -a "${1}" != "-c" ; then 
  212.   echo shar: Will not clobber existing file \"'debug.c'\"
  213. else
  214. echo shar: Extracting \"'debug.c'\" \(10002 characters\)
  215. sed "s/^X//" >'debug.c' <<'END_OF_FILE'
  216. X/*
  217. X * Copyright (c) 1985,1989 Regents of the University of California.
  218. X * All rights reserved.
  219. X *
  220. X * Redistribution and use in source and binary forms are permitted provided
  221. X * that: (1) source distributions retain this entire copyright notice and
  222. X * comment, and (2) distributions including binaries display the following
  223. X * acknowledgement:  ``This product includes software developed by the
  224. X * University of California, Berkeley and its contributors'' in the
  225. X * documentation or other materials provided with the distribution and in
  226. X * all advertising materials mentioning features or use of this software.
  227. X * Neither the name of the University nor the names of its contributors may
  228. X * be used to endorse or promote products derived from this software without
  229. X * specific prior written permission.
  230. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  231. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  232. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  233. X */
  234. X
  235. X#ifndef lint
  236. Xstatic char sccsid[] = "@(#)debug.c    5.22 (Berkeley) 6/29/90";
  237. X#endif /* not lint */
  238. X
  239. X/*
  240. X *******************************************************************************
  241. X *
  242. X *  debug.c --
  243. X *
  244. X *    Routines to print out packets received from a name server query.
  245. X *
  246. X *      Modified version of 4.3BSD BIND res_debug.c 5.30 6/27/90
  247. X *
  248. X *******************************************************************************
  249. X */
  250. X
  251. X#include <sys/types.h>
  252. X#include <netinet/in.h>
  253. X#include <stdio.h>
  254. X#include <arpa/nameser.h>
  255. X#include <arpa/inet.h>
  256. X#include <resolv.h>
  257. X#include <netdb.h>
  258. X#include "res.h"
  259. X
  260. X#ifndef __STDC__
  261. Xextern char ctime();
  262. X#endif
  263. X
  264. X/*
  265. X *  Imported from res_debug.c
  266. X */
  267. Xextern char *_res_resultcodes[];
  268. Xextern char *_res_opcodes[];
  269. X
  270. X/*
  271. X *  Used to highlight the start of a record when printing it.
  272. X */
  273. X#define INDENT "    ->  "
  274. X
  275. X
  276. X
  277. X/*
  278. X * Print the contents of a query.
  279. X * This is intended to be primarily a debugging routine.
  280. X */
  281. X
  282. XPrint_query(msg, eom, printHeader)
  283. X    char *msg, *eom;
  284. X    int printHeader;
  285. X{
  286. X    Fprint_query(msg, eom, printHeader,stdout);
  287. X}
  288. X
  289. XFprint_query(msg, eom, printHeader,file)
  290. X    char *msg, *eom;
  291. X    int printHeader;
  292. X    FILE *file;
  293. X{
  294. X    register char *cp;
  295. X    register HEADER *hp;
  296. X    register int n;
  297. X    short qclass;
  298. X    short type;
  299. X
  300. X    /*
  301. X     * Print header fields.
  302. X     */
  303. X    hp = (HEADER *)msg;
  304. X    cp = msg + sizeof(HEADER);
  305. X    if (printHeader || (_res.options & RES_DEBUG2)) {
  306. X        fprintf(file,"    HEADER:\n");
  307. X        fprintf(file,"\topcode = %s", _res_opcodes[hp->opcode]);
  308. X        fprintf(file,", id = %d", ntohs(hp->id));
  309. X        fprintf(file,", rcode = %s\n", _res_resultcodes[hp->rcode]);
  310. X        fprintf(file,"\theader flags: ");
  311. X        if (hp->qr) {
  312. X            fprintf(file," response");
  313. X        } else {
  314. X            fprintf(file," query");
  315. X        }
  316. X        if (hp->aa)
  317. X            fprintf(file,", auth. answer");
  318. X        if (hp->tc)
  319. X            fprintf(file,", truncation");
  320. X        if (hp->rd)
  321. X            fprintf(file,", want recursion");
  322. X        if (hp->ra)
  323. X            fprintf(file,", recursion avail.");
  324. X        if (hp->pr)
  325. X            fprintf(file,", primary");
  326. X        fprintf(file,"\n\tquestions = %d", ntohs(hp->qdcount));
  327. X        fprintf(file,",  answers = %d", ntohs(hp->ancount));
  328. X        fprintf(file,",  authority records = %d", ntohs(hp->nscount));
  329. X        fprintf(file,",  additional = %d\n\n", ntohs(hp->arcount));
  330. X    }
  331. X
  332. X    /*
  333. X     * Print question records.
  334. X     */
  335. X    if (n = ntohs(hp->qdcount)) {
  336. X        fprintf(file,"    QUESTIONS:\n");
  337. X        while (--n >= 0) {
  338. X            fprintf(file,"\t");
  339. X            cp = Print_cdname(cp, msg, eom, file);
  340. X            if (cp == NULL)
  341. X                return;
  342. X            type = _getshort(cp);
  343. X            cp += sizeof(u_short);
  344. X            qclass = _getshort(cp);
  345. X            cp += sizeof(u_short);
  346. X            fprintf(file,", type = %s", p_type(type));
  347. X            fprintf(file,", class = %s\n", p_class(qclass));
  348. X        }
  349. X    }
  350. X    /*
  351. X     * Print authoritative answer records
  352. X     */
  353. X    if (n = ntohs(hp->ancount)) {
  354. X        fprintf(file,"    ANSWERS:\n");
  355. X        while (--n >= 0) {
  356. X            fprintf(file, INDENT);
  357. X            cp = Print_rr(cp, msg, eom, file);
  358. X            if (cp == NULL)
  359. X                return;
  360. X        }
  361. X    }
  362. X    /*
  363. X     * print name server records
  364. X     */
  365. X    if (n = ntohs(hp->nscount)) {
  366. X        fprintf(file,"    AUTHORITY RECORDS:\n");
  367. X        while (--n >= 0) {
  368. X            fprintf(file, INDENT);
  369. X            cp = Print_rr(cp, msg, eom, file);
  370. X            if (cp == NULL)
  371. X                return;
  372. X        }
  373. X    }
  374. X    /*
  375. X     * print additional records
  376. X     */
  377. X    if (n = ntohs(hp->arcount)) {
  378. X        fprintf(file,"    ADDITIONAL RECORDS:\n");
  379. X        while (--n >= 0) {
  380. X            fprintf(file, INDENT);
  381. X            cp = Print_rr(cp, msg, eom, file);
  382. X            if (cp == NULL)
  383. X                return;
  384. X        }
  385. X    }
  386. X    fprintf(file,"\n------------\n");
  387. X}
  388. X
  389. Xchar *
  390. XPrint_cdname_sub(cp, msg, eom, file, format)
  391. X    char *cp, *msg, *eom;
  392. X    FILE *file;
  393. X    int format;
  394. X{
  395. X    int n;
  396. X    char name[MAXDNAME];
  397. X    extern char *strcpy();
  398. X
  399. X    if ((n = dn_expand(msg, eom, cp, name, sizeof(name))) < 0)
  400. X        return (NULL);
  401. X    if (name[0] == '\0') {
  402. X        (void) strcpy(name, "(root)");
  403. X    }
  404. X    if (format) {
  405. X        fprintf(file, "%-30s", name);
  406. X    } else {
  407. X        fputs(name, file);
  408. X    }
  409. X    return (cp + n);
  410. X}
  411. X
  412. Xchar *
  413. XPrint_cdname(cp, msg, eom, file)
  414. X    char *cp, *msg, *eom;
  415. X    FILE *file;
  416. X{
  417. X    return(Print_cdname_sub(cp, msg, eom, file, 0));
  418. X}
  419. X
  420. Xchar *
  421. XPrint_cdname2(cp, msg, eom, file)
  422. X    char *cp, *msg, *eom;
  423. X    FILE *file;
  424. X{
  425. X    return(Print_cdname_sub(cp, msg, eom, file, 1));
  426. X}
  427. X
  428. X/*
  429. X * Print resource record fields in human readable form.
  430. X */
  431. Xchar *
  432. XPrint_rr(cp, msg, eom, file)
  433. X    char *cp, *msg, *eom;
  434. X    FILE *file;
  435. X{
  436. X    int type, qclass, dlen, n, c;
  437. X    unsigned long rrttl, ttl;
  438. X    struct in_addr inaddr;
  439. X    char *cp1, *cp2;
  440. X    int debug;
  441. X
  442. X    if ((cp = Print_cdname(cp, msg, eom, file)) == NULL) {
  443. X        fprintf(file, "(name truncated?)\n");
  444. X        return (NULL);            /* compression error */
  445. X    }
  446. X
  447. X    type = _getshort(cp);
  448. X    cp += sizeof(u_short);
  449. X    qclass = _getshort(cp);
  450. X    cp += sizeof(u_short);
  451. X    rrttl = _getlong(cp);
  452. X    cp += sizeof(u_long);
  453. X    dlen = _getshort(cp);
  454. X    cp += sizeof(u_short);
  455. X
  456. X    debug = _res.options & (RES_DEBUG|RES_DEBUG2);
  457. X    if (debug) {
  458. X        if (_res.options & RES_DEBUG2) {
  459. X        fprintf(file,"\n\ttype = %s, class = %s, dlen = %d",
  460. X                p_type(type), p_class(qclass), dlen);
  461. X        }
  462. X        if (type == T_SOA) {
  463. X        fprintf(file,"\n\tttl = %lu (%s)", rrttl, P_time(rrttl));
  464. X        }
  465. X        (void) putc('\n', file);
  466. X    } 
  467. X
  468. X    cp1 = cp;
  469. X
  470. X    /*
  471. X     * Print type specific data, if appropriate
  472. X     */
  473. X    switch (type) {
  474. X    case T_A:
  475. X        switch (qclass) {
  476. X        case C_IN:
  477. X            bcopy(cp, (char *)&inaddr, sizeof(inaddr));
  478. X            if (dlen == 4) {
  479. X                fprintf(file,"\tinternet address = %s\n",
  480. X                    inet_ntoa(inaddr));
  481. X                cp += dlen;
  482. X            } else if (dlen == 7) {
  483. X                fprintf(file,"\tinternet address = %s",
  484. X                    inet_ntoa(inaddr));
  485. X                fprintf(file,", protocol = %d", cp[4]);
  486. X                fprintf(file,", port = %d\n",
  487. X                    (cp[5] << 8) + cp[6]);
  488. X                cp += dlen;
  489. X            }
  490. X            break;
  491. X        default:
  492. X            fprintf(file,"\taddress, class = %d, len = %d\n",
  493. X                qclass, dlen);
  494. X            cp += dlen;
  495. X        }
  496. X        break;
  497. X
  498. X    case T_CNAME:
  499. X        fprintf(file,"\tcanonical name = ");
  500. X        goto doname;
  501. X
  502. X    case T_MG:
  503. X        fprintf(file,"\tmail group member = ");
  504. X        goto doname;
  505. X    case T_MB:
  506. X        fprintf(file,"\tmail box = ");
  507. X        goto doname;
  508. X    case T_MR:
  509. X        fprintf(file,"\tmailbox rename = ");
  510. X        goto doname;
  511. X    case T_MX:
  512. X        fprintf(file,"\tpreference = %u",_getshort(cp));
  513. X        cp += sizeof(u_short);
  514. X        fprintf(file,", mail exchanger = ");
  515. X        goto doname;
  516. X    case T_NS:
  517. X        fprintf(file,"\tnameserver = ");
  518. X        goto doname;
  519. X    case T_PTR:
  520. X        fprintf(file,"\tname = ");
  521. Xdoname:
  522. X        cp = Print_cdname(cp, msg, eom, file);
  523. X        (void) putc('\n', file);
  524. X        break;
  525. X
  526. X    case T_HINFO:
  527. X        if (n = *cp++) {
  528. X            fprintf(file,"\tCPU = %.*s", n, cp);
  529. X            cp += n;
  530. X        }
  531. X        if (n = *cp++) {
  532. X            fprintf(file,"\tOS = %.*s\n", n, cp);
  533. X            cp += n;
  534. X        }
  535. X        break;
  536. X
  537. X    case T_SOA:
  538. X        if (!debug)
  539. X            (void) putc('\n', file);
  540. X        fprintf(file,"\torigin = ");
  541. X        cp = Print_cdname(cp, msg, eom, file);
  542. X        fprintf(file,"\n\tmail addr = ");
  543. X        cp = Print_cdname(cp, msg, eom, file);
  544. X        fprintf(file,"\n\tserial = %lu", _getlong(cp));
  545. X        cp += sizeof(u_long);
  546. X        ttl = _getlong(cp);
  547. X        fprintf(file,"\n\trefresh = %lu (%s)", ttl, P_time(ttl));
  548. X        cp += sizeof(u_long);
  549. X        ttl = _getlong(cp);
  550. X        fprintf(file,"\n\tretry   = %lu (%s)", ttl, P_time(ttl));
  551. X        cp += sizeof(u_long);
  552. X        ttl = _getlong(cp);
  553. X        fprintf(file,"\n\texpire  = %lu (%s)", ttl, P_time(ttl));
  554. X        cp += sizeof(u_long);
  555. X        ttl = _getlong(cp);
  556. X        fprintf(file,"\n\tminimum ttl = %lu (%s)\n", ttl, P_time(ttl));
  557. X        cp += sizeof(u_long);
  558. X        break;
  559. X
  560. X    case T_MINFO:
  561. X        if (!debug)
  562. X            (void) putc('\n', file);
  563. X        fprintf(file,"\trequests = ");
  564. X        cp = Print_cdname(cp, msg, eom, file);
  565. X        fprintf(file,"\n\terrors = ");
  566. X        cp = Print_cdname(cp, msg, eom, file);
  567. X        (void) putc('\n', file);
  568. X        break;
  569. X
  570. X    case T_UINFO:
  571. X        fprintf(file,"\tuser info = %s\n", cp);
  572. X        cp += dlen;
  573. X        break;
  574. X
  575. X    case T_UID:
  576. X    case T_GID:
  577. X        if (dlen == 4) {
  578. X            fprintf(file,"\t%cid = %lu\n",type == T_UID ? 'u' : 'g',
  579. X                _getlong(cp));
  580. X            cp += sizeof(int);
  581. X        } else {
  582. X            fprintf(file,"\t%cid of length %d?\n",
  583. X                type == T_UID ? 'u' : 'g', dlen);
  584. X            cp += dlen;
  585. X        }
  586. X        break;
  587. X
  588. X    case T_WKS: {
  589. X        struct protoent *protoPtr;
  590. X
  591. X        if (dlen < sizeof(u_long) + 1)
  592. X            break;
  593. X        if (!debug)
  594. X            (void) putc('\n', file);
  595. X        bcopy(cp, (char *)&inaddr, sizeof(inaddr));
  596. X        cp += sizeof(u_long);
  597. X        if ((protoPtr = getprotobynumber(*cp)) != NULL) {
  598. X            fprintf(file,"\tinet address = %s, protocol = %s\n\t",
  599. X            inet_ntoa(inaddr), protoPtr->p_name);
  600. X        } else {
  601. X            fprintf(file,"\tinet address = %s, protocol = %d\n\t",
  602. X            inet_ntoa(inaddr), *cp);
  603. X        }
  604. X        cp++;
  605. X        n = 0;
  606. X        while (cp < cp1 + dlen) {
  607. X            c = *cp++;
  608. X            do {
  609. X                struct servent *s;
  610. X
  611. X                 if (c & 0200) {
  612. X                    s = getservbyport(n, NULL);
  613. X                    if (s != NULL) {
  614. X                        fprintf(file,"  %s", s->s_name);
  615. X                    } else {
  616. X                        fprintf(file," #%d", n);
  617. X                    }
  618. X                }
  619. X                 c <<= 1;
  620. X            } while (++n & 07);
  621. X        }
  622. X        putc('\n',file);
  623. X        }
  624. X        break;
  625. X
  626. X    case T_NULL:
  627. X        fprintf(file, "\tNULL (dlen %d)\n", dlen);
  628. X        cp += dlen;
  629. X        break;
  630. X
  631. X    default:
  632. X        fprintf(file,"\t??? unknown type %d ???\n", type);
  633. X        cp += dlen;
  634. X    }
  635. X    if (_res.options & RES_DEBUG && type != T_SOA) {
  636. X        fprintf(file,"\tttl = %lu (%s)\n", rrttl, P_time(rrttl));
  637. X    }
  638. X    if (cp != cp1 + dlen) {
  639. X        fprintf(file,
  640. X            "\n*** Error: record size incorrect (%d != %d)\n\n",
  641. X            cp - cp1, dlen);
  642. X        cp = NULL;
  643. X    }
  644. X    return (cp);
  645. X}
  646. END_OF_FILE
  647. if test 10002 -ne `wc -c <'debug.c'`; then
  648.     echo shar: \"'debug.c'\" unpacked with wrong size!
  649. fi
  650. # end of 'debug.c'
  651. fi
  652. if test -f 'ns2tab.8' -a "${1}" != "-c" ; then 
  653.   echo shar: Will not clobber existing file \"'ns2tab.8'\"
  654. else
  655. echo shar: Extracting \"'ns2tab.8'\" \(6917 characters\)
  656. sed "s/^X//" >'ns2tab.8' <<'END_OF_FILE'
  657. X.TH NS2ALIASES 8 "April 4, 1992"
  658. X.UC 6
  659. X.SH NAME
  660. Xns2tab \- Extract a sendmail aliases table from the nameserver
  661. X.SH SYNOPSIS
  662. X.B ns2tab
  663. X[ 
  664. X.I option ...
  665. X]
  666. X.SH DESCRIPTION
  667. X.I Ns2tab
  668. Xis a program to query Internet domain name servers and print the
  669. Xinformation retrieved in different formats. Supported formats include
  670. Xaliases(5) for sendmail, /etc/group, /etc/passwd, /etc/hosts and
  671. Xaliases.text for the Elm mailer.
  672. X.sp 1
  673. X.SH ARGUMENTS
  674. XIf given no arguments, \fIns2tab\fP will query the domain found in
  675. X/etc/resolv.conf and print on stdout an aliases-table.
  676. XBehaviour can be modified by the \fBstyle\fP=XX argument, where XX is
  677. Xone of:
  678. X.IP aliases
  679. XOutput is in /usr/lib/aliases format, which also is compatiple
  680. Xwith an mh-alias file. Information is gathered from MB, MR, MINFO, MG
  681. Xand UINFO resource records. Maillists with no members are ignored.
  682. X.IP elm
  683. XThis is a slightly different way of representing the same information
  684. Xfor elm.
  685. XThis style will only be used if you don't intend to have have an
  686. X/usr/lib/aliases or equivalent.
  687. X.IP lelm
  688. XKnown as local elm, because it make elm expect that the recipients will
  689. Xbe expanded into real adresslists by the mail agent. In short, if you use
  690. Xthis, then you must also generate an /usr/lib/aliases file (if you use
  691. Xsendmail).
  692. X.IP group
  693. XOutputs maillists in group format.
  694. XIf any members are groups (They have a MINFO record) they will be expanded
  695. Xunless there is a UID. This will be done recursively. Beware that this
  696. Xopens an alley to loop referencing.
  697. XInformation is gathered from MINFO, MG, GID and UINFO resource records.
  698. X.IP nrgroup
  699. XNonrecursive group format.
  700. X.IP pwupd
  701. XRuns through the passwd table using getpwent(3), looks up each name
  702. Xin the nameserver, and outputs the account-line with the GECOS field
  703. Xreplaced with the value of the UINFO resource record.
  704. X.IP hosts
  705. XAs you would expect: /usr/hosts. To avoid excessive long lines host-aliases
  706. Xare not domain-expanded.
  707. XInformation is gathered from A, CNAME and HINFO records.
  708. X.LP
  709. XThe next set of styles are only relevant if you have linked in Hesiod
  710. Xemulation. The intent is to allow you to use Hesiod, even though not all
  711. Xof your computers support it. The query class does not have to HS, but
  712. Xcan be anything supported by your nameserver. This way you can get
  713. XHesiod functionality even if none of your computers support it.
  714. XNote that \fIns2tab\fP defaults to query the IN class.
  715. X.IP fstab
  716. X.I Ns2tab
  717. Xwill prepend \fBfilsys\fP to your current domain, look for TXT records
  718. Xand print in /etc/fstab style as in Ultrix 4.x and BSD4.2.
  719. X.IP checklist
  720. XSame, but output is in /etc/checklist format as used on HP/UX and others:
  721. X.IP filesys
  722. XSCO Unix V.3.2 /etc/default/filesys format.
  723. X.IP vfstab
  724. XUNIX V.4 /etc/vfstab format.
  725. X.IP passwd
  726. X.I Ns2tab
  727. Xprepends \fBpasswd\fP and outputs password file entries.
  728. X.IP printcap
  729. XOutput is in /etc/printcap format.
  730. X.LP
  731. X.B server=\fIserver\fP
  732. Xwill set the server to query. If not used \fIns2tab\fP will default
  733. Xto a value found in /etc/resolv.conf
  734. XRemember to query an autoritative server, otherwise you get no output.
  735. X.LP
  736. X.B out=\fIfilename\fP
  737. XOpens a file where all output will go.
  738. X.LP
  739. X.B domain=\fIdomain\fP
  740. XThe domain to query. If specified more than once \fIns2tab\fP will
  741. Xload the additional domains into the same internal tables, overwriting
  742. Xif there is any redundant data. This feature allow you to have special
  743. Xversions of the same file for a single or a cluster of computers.
  744. XConsider: ns2tab domain=dc.dk load domain=cluster1.dc.dk style=group
  745. X.LP
  746. X.B class=\fI{IN,CHAOS,HS,ANY}\fP
  747. XSets the query class. \fINs2tab\fP assume IN semantics for all
  748. Xressource records no matter what class you use.
  749. X.LP
  750. X.B suffix=\fIdomain\fP
  751. XUse this argument if the domain to query is subjugated a higher level
  752. Xdomain. (meaning: it doesn't have its own SOA).
  753. X.LP
  754. X.B load
  755. XExplicitly load the resource records.
  756. X.I Ns2tab
  757. Xwill do it automatically if when it is time to print.
  758. X.B print
  759. XPrint in the style previously set.
  760. XIt will allow you to print several styles in the same run.
  761. X.SH EXAMPLES
  762. XGiven the following nameserver records, the format for each style is
  763. Xshown below.
  764. X.RS .5i
  765. X.nf
  766. Xbob    MR    robert
  767. Xrnews    MR    "|/usr/local/bin/uurec"
  768. Xrobert    MB    hostx
  769. X    UINFO    "Robert Robespierre,MH-2323,3998"
  770. X
  771. Xwheel    MINFO    wagner    root
  772. X    GID    0
  773. X    UINFO    "Root task force"
  774. X    MG    robert
  775. X    MG    james
  776. X
  777. Xdyer.filsys    IN    TXT    "NFS /mit/dyer eurydice w /mit/dyer"
  778. X
  779. X\fBAliases format:\fP
  780. Xbob: robert
  781. Xrnews: "|/usr/local/bin/uurec"
  782. X# robert +- Robert Robespierre,MH-2323,3998
  783. Xrobert: robert@hostx
  784. X# Root task force
  785. Xwheel-request: wagner
  786. Xowner-wheel: root
  787. Xwheel: robert,james
  788. X.sp 1
  789. X\fBelm format:\fP
  790. Xbob =  = robert
  791. Xrnews =  = "|/usr/local/bin/uurec"
  792. Xrobert = Robert Robespierre,MH-2323,3998 = robert@hostx
  793. Xwheel-request = wheel Request = wagner
  794. Xowner-wheel = wheel Errors = root
  795. Xwheel = Root task force = robert, james
  796. X.sp 1
  797. X\fBgroup format:\fP
  798. Xwheel:*:0:robert,james
  799. X.sp 1
  800. X\fBfstab format:\fP
  801. X/mit/dyer@eurydice:/mit/dyer:rw:0:0:nfs:hard,intr:
  802. X.sp 1
  803. X- and if robert has a \fBpasswd\fP entry like:
  804. Xrobert:Idh.wiU8oiJww:3028:1:Robert Robespierre,MH-4572,3652:/u/robert:
  805. Xit will become:
  806. Xrobert:Idh.wiU8oiJww:3028:1:Robert Robespierre,MH-2323,3998:/u/robert:
  807. X.fi
  808. X.RE
  809. X.sp 1
  810. XTry: ns2tab server=dc.dk dom=dc.dk out=/tmp/aliases style=aliases
  811. Xout=/tmp/elm style=elm
  812. X.SH DIAGNOSTICS
  813. XIf the lookup request was not successful, an error message is printed.
  814. XPossible errors are:
  815. X.IP "Timed out" 5
  816. XThe server did not respond to a request after a certain amount of
  817. Xtime (changed with \fBtimeout=\fIvalue\fR) 
  818. Xand a certain number of retries (changed with \fBretry=\fIvalue\fR).
  819. X.IP "No response from server" 5
  820. XNo name server is running on the server machine.
  821. X.IP "No records" 5
  822. XThe server does not have resource records of the current query type for the
  823. Xhost, although the host name is valid.
  824. XThe query type is specified with the \fBquerytype\fP command.
  825. X.IP "Non-existent domain" 5
  826. XThe host or domain name does not exist.
  827. X.IP "Connection refused" 5
  828. X.ns
  829. X.IP "Network is unreachable" 5
  830. XThe connection to the name server could not be made 
  831. Xat the current time.
  832. X.IP "Server failure" 5
  833. XThe name server found an internal inconsistency in its database
  834. Xand could not return a valid answer.
  835. X.IP "Refused" 5
  836. XThe name server refused to service the request.
  837. X.IP "Format error" 5
  838. XThe name server found that the request packet was not in the proper format.
  839. XIt may indicate an error in \fIns2tab\fP.
  840. X.sp 1
  841. X.SH FILES
  842. X.ta \w'/etc/resolv.confXXX'u
  843. X/etc/resolv.conf    initial domain name and 
  844. X    name server addresses.
  845. X.SH ENVIRONMENT
  846. X.ta \w'LOCALDOMAINXXXX'u
  847. XLOCALDOMAIN    overrides default domain.
  848. X.SH BUGS
  849. XI'm sure I left some in.. but I've forgotten where..
  850. X.SH SEE ALSO
  851. Xresolver(3), resolver(5), named(8), nslookup(8), 
  852. X.br
  853. XRFC-1034  ``Domain Names \- Concepts and Facilities''
  854. X.br
  855. XRFC-1035  ``Domain Names \- Implementation and Specification''
  856. X.br
  857. X``The \fIHesiod\fP Name Server'' by Stephen P. Dryer
  858. X.SH AUTHOR
  859. XSoren Roug, based on the nslookup program developed by
  860. XAndrew Cherenson
  861. END_OF_FILE
  862. if test 6917 -ne `wc -c <'ns2tab.8'`; then
  863.     echo shar: \"'ns2tab.8'\" unpacked with wrong size!
  864. fi
  865. # end of 'ns2tab.8'
  866. fi
  867. if test -f 'p_time.c' -a "${1}" != "-c" ; then 
  868.   echo shar: Will not clobber existing file \"'p_time.c'\"
  869. else
  870. echo shar: Extracting \"'p_time.c'\" \(982 characters\)
  871. sed "s/^X//" >'p_time.c' <<'END_OF_FILE'
  872. X#include <sys/types.h>
  873. X#include <netinet/in.h>
  874. X#include <stdio.h>
  875. X#include <arpa/nameser.h>
  876. X#include <arpa/inet.h>
  877. X#include <resolv.h>
  878. X
  879. Xstatic  char nbuf[40];
  880. X/*
  881. X * Return a mnemonic for a time to live
  882. X */
  883. Xchar *
  884. XP_time(value)
  885. X    u_long value;
  886. X{
  887. X    int secs, mins, hours;
  888. X    register char *p;
  889. X
  890. X    if (value == 0) {
  891. X        strcpy(nbuf, "0 secs");
  892. X        return(nbuf);
  893. X    }
  894. X
  895. X    secs = value % 60;
  896. X    value /= 60;
  897. X    mins = value % 60;
  898. X    value /= 60;
  899. X    hours = value % 24;
  900. X    value /= 24;
  901. X
  902. X#define    PLURALIZE(x)    x, (x == 1) ? "" : "s"
  903. X    p = nbuf;
  904. X    if (value) {
  905. X        (void)sprintf(p, "%d day%s", PLURALIZE(value));
  906. X        while (*++p);
  907. X    }
  908. X    if (hours) {
  909. X        if (value)
  910. X            *p++ = ' ';
  911. X        (void)sprintf(p, "%d hour%s", PLURALIZE(hours));
  912. X        while (*++p);
  913. X    }
  914. X    if (mins) {
  915. X        if (value || hours)
  916. X            *p++ = ' ';
  917. X        (void)sprintf(p, "%d min%s", PLURALIZE(mins));
  918. X        while (*++p);
  919. X    }
  920. X    if (secs || ! (value || hours || mins)) {
  921. X        if (value || hours || mins)
  922. X            *p++ = ' ';
  923. X        (void)sprintf(p, "%d sec%s", PLURALIZE(secs));
  924. X    }
  925. X    return(nbuf);
  926. X}
  927. END_OF_FILE
  928. if test 982 -ne `wc -c <'p_time.c'`; then
  929.     echo shar: \"'p_time.c'\" unpacked with wrong size!
  930. fi
  931. # end of 'p_time.c'
  932. fi
  933. if test -f 'prime.c' -a "${1}" != "-c" ; then 
  934.   echo shar: Will not clobber existing file \"'prime.c'\"
  935. else
  936. echo shar: Extracting \"'prime.c'\" \(1560 characters\)
  937. sed "s/^X//" >'prime.c' <<'END_OF_FILE'
  938. X/*
  939. X**
  940. X**    Copyright (c) 1987, Robert L. McQueer
  941. X**        All Rights Reserved
  942. X**
  943. X** Permission granted for use, modification and redistribution of this
  944. X** software provided that no use is made for commercial gain without the
  945. X** written consent of the author, that all copyright notices remain intact,
  946. X** and that all changes are clearly documented.  No warranty of any kind
  947. X** concerning any use which may be made of this software is offered or implied.
  948. X**
  949. X*/
  950. X
  951. X/* return smallest prime >= i */
  952. Xint
  953. Xnext_prime(int i)
  954. X{
  955. X    if (i <= 2)
  956. X        return (2);
  957. X    if ((i%2) == 0)
  958. X        ++i;
  959. X    while (! is_prime(i))
  960. X        i += 2;
  961. X    return (i);
  962. X}
  963. X
  964. X/*
  965. X** simply check all factors <= the square root of the number, with
  966. X** a minor wrinkle:
  967. X**
  968. X** we split our checks into two separate chains which cover all
  969. X** numbers with no factors of 2 or 3, avoiding many of the non-
  970. X** prime factors.  factor1 winds up being all integers = 5 mod 6,
  971. X** factor2 all integers >= 7 which = 1 mod 6.  Anything = 0,2,3 or
  972. X** 4 mod 6 divides by 2 or 3.
  973. X**
  974. X** this gives a rather small number of redundant factor checks for
  975. X** reasonable sized arguments (say < 10000).  Only for extremely large
  976. X** numbers would the extra overhead justify a "smarter" algorithm.
  977. X**
  978. X** only valid for i >= 2.
  979. X*/
  980. Xint
  981. Xis_prime(int i)
  982. X{
  983. X    int factor1,factor2;
  984. X
  985. X    if (i == 2 || i == 3)
  986. X        return(1);
  987. X
  988. X    if ((i%3) == 0 || (i%2) == 0)
  989. X        return(0);
  990. X
  991. X    factor1 = 5;
  992. X    factor2 = 7;
  993. X    while ((factor1 * factor1) <= i)
  994. X    {
  995. X        if ((i % factor1) == 0)
  996. X            return (0);
  997. X        if ((i % factor2) == 0)
  998. X            return (0);
  999. X        factor1 += 6;
  1000. X        factor2 += 6;
  1001. X    }
  1002. X
  1003. X    return (1);
  1004. X}
  1005. END_OF_FILE
  1006. if test 1560 -ne `wc -c <'prime.c'`; then
  1007.     echo shar: \"'prime.c'\" unpacked with wrong size!
  1008. fi
  1009. # end of 'prime.c'
  1010. fi
  1011. if test -f 'readv.c' -a "${1}" != "-c" ; then 
  1012.   echo shar: Will not clobber existing file \"'readv.c'\"
  1013. else
  1014. echo shar: Extracting \"'readv.c'\" \(1130 characters\)
  1015. sed "s/^X//" >'readv.c' <<'END_OF_FILE'
  1016. X#include <sys/types.h>
  1017. X#include <sys/uio.h>
  1018. X#include <errno.h>
  1019. X
  1020. Xint readv(fd, iov, iovcnt)
  1021. X     int fd;
  1022. X     struct iovec *iov;
  1023. X     int iovcnt;
  1024. X{
  1025. X  int i,len, total;
  1026. X  char *base;
  1027. X
  1028. X  errno = 0;
  1029. X  for (i=0,total=0; i<iovcnt; i++,iov++) {
  1030. X    len = iov->iov_len;
  1031. X    base = iov->iov_base;
  1032. X    while (len > 0) {
  1033. X      register int nbytes;
  1034. X      nbytes = read(fd, base, len);
  1035. X      if (nbytes < 0 && total == 0) {
  1036. X    return(-1);
  1037. X      }
  1038. X      if (nbytes <= 0) {
  1039. X    return(total);
  1040. X      }
  1041. X      errno = 0;
  1042. X      len   -= nbytes;
  1043. X      total += nbytes;
  1044. X      base  += nbytes;
  1045. X    }
  1046. X  }
  1047. X  return(total);
  1048. X}
  1049. X
  1050. Xint
  1051. Xwritev(fd,iov,iovcnt)
  1052. X     int fd;
  1053. X     struct iovec *iov;
  1054. X     int iovcnt;
  1055. X{
  1056. X  int i,len,total;
  1057. X  char *base;
  1058. X
  1059. X  errno = 0;
  1060. X  for (i=0,total=0; i<iovcnt; i++, iov++) {
  1061. X    len = iov->iov_len;
  1062. X    base = iov->iov_base;
  1063. X    while (len > 0) {
  1064. X      register int nbytes;
  1065. X      nbytes = write(fd, base, len);
  1066. X      if (nbytes < 0 && total == 0) {
  1067. X    return(-1);
  1068. X      }
  1069. X      if (nbytes <= 0) {
  1070. X    return(total);
  1071. X      }
  1072. X
  1073. X      errno = 0;
  1074. X      len   -= nbytes;
  1075. X      total += nbytes;
  1076. X      base  += nbytes;
  1077. X    }
  1078. X  }
  1079. X  return(total);
  1080. X}
  1081. END_OF_FILE
  1082. if test 1130 -ne `wc -c <'readv.c'`; then
  1083.     echo shar: \"'readv.c'\" unpacked with wrong size!
  1084. fi
  1085. # end of 'readv.c'
  1086. fi
  1087. if test -f 'res.h' -a "${1}" != "-c" ; then 
  1088.   echo shar: Will not clobber existing file \"'res.h'\"
  1089. else
  1090. echo shar: Extracting \"'res.h'\" \(2625 characters\)
  1091. sed "s/^X//" >'res.h' <<'END_OF_FILE'
  1092. X/*
  1093. X *******************************************************************************
  1094. X *
  1095. X *  res.h --
  1096. X *
  1097. X *    Definitions used by modules of the name server lookup program.
  1098. X *
  1099. X *    Copyright (c) 1985
  1100. X *    Andrew Cherenson
  1101. X *    U.C. Berkeley
  1102. X *    CS298-26  Fall 1985
  1103. X * 
  1104. X *******************************************************************************
  1105. X */
  1106. X
  1107. X#define TRUE    1
  1108. X#define FALSE    0
  1109. Xtypedef int Boolean;
  1110. X
  1111. X/*
  1112. X *  Define return statuses in addtion to the ones defined in namserv.h
  1113. X *   let SUCCESS be a synonym for NOERROR
  1114. X *
  1115. X *    TIME_OUT    - a socket connection timed out.
  1116. X *    NO_INFO        - the server didn't find any info about the host.
  1117. X *    ERROR        - one of the following types of errors:
  1118. X *               dn_expand, res_mkquery failed
  1119. X *               bad command line, socket operation failed, etc.
  1120. X *    NONAUTH        - the server didn't have the desired info but
  1121. X *              returned the name(s) of some servers who should.
  1122. X *    NO_RESPONSE    - the server didn't respond.
  1123. X *
  1124. X */
  1125. X
  1126. X#define  SUCCESS        0
  1127. X#define  TIME_OUT        -1
  1128. X#define  NO_INFO        -2
  1129. X#define  ERROR            -3
  1130. X#define  NONAUTH        -4
  1131. X#define  NO_RESPONSE        -5
  1132. X
  1133. X/*
  1134. X *  Define additional options for the resolver state structure.
  1135. X *
  1136. X *   RES_DEBUG2        more verbose debug level
  1137. X */
  1138. X
  1139. X#define RES_DEBUG2    0x80000000
  1140. X
  1141. X/*
  1142. X *  Maximum length of server, host and file names.
  1143. X */
  1144. X
  1145. X#define NAME_LEN 256
  1146. X
  1147. X
  1148. X/*
  1149. X * Modified struct hostent from <netdb.h>
  1150. X *
  1151. X * "Structures returned by network data base library.  All addresses
  1152. X * are supplied in host order, and returned in network order (suitable
  1153. X * for use in system calls)."
  1154. X */
  1155. X
  1156. Xtypedef struct    {
  1157. X    char    *name;        /* official name of host */
  1158. X    char    **domains;    /* domains it serves */
  1159. X    char    **addrList;    /* list of addresses from name server */
  1160. X} ServerInfo;
  1161. X
  1162. Xtypedef struct    {
  1163. X    char    *name;        /* official name of host */
  1164. X    char    **aliases;    /* alias list */
  1165. X    char    **addrList;    /* list of addresses from name server */
  1166. X    int    addrType;    /* host address type */
  1167. X    int    addrLen;    /* length of address */
  1168. X    ServerInfo **servers;
  1169. X} HostInfo;
  1170. X
  1171. X
  1172. X/*
  1173. X *  FilePtr is used for directing listings to a file.
  1174. X *  It is global so the Control-C handler can close it.
  1175. X */
  1176. X
  1177. Xextern FILE *filePtr;
  1178. X
  1179. X/*
  1180. X * TCP/UDP port of server.
  1181. X */
  1182. Xextern unsigned short nsport;
  1183. X
  1184. X/*
  1185. X *  External routines:
  1186. X */
  1187. X
  1188. Xextern Boolean IsAddr();
  1189. Xextern int  Print_query();
  1190. Xextern char *Print_cdname();
  1191. Xextern char *Print_cdname2();    /* fixed width */
  1192. Xextern char *Print_rr();
  1193. Xextern char *DecodeType();    /* descriptive version of p_type */
  1194. Xextern char *DecodeError();
  1195. Xextern void NsError();
  1196. Xextern void PrintServer();
  1197. Xextern void PrintHostInfo();
  1198. Xextern void ShowOptions();
  1199. Xextern void FreeHostInfoPtr();
  1200. Xextern FILE *OpenFile();
  1201. Xextern char *res_skip();
  1202. END_OF_FILE
  1203. if test 2625 -ne `wc -c <'res.h'`; then
  1204.     echo shar: \"'res.h'\" unpacked with wrong size!
  1205. fi
  1206. # end of 'res.h'
  1207. fi
  1208. if test -f 'send.c' -a "${1}" != "-c" ; then 
  1209.   echo shar: Will not clobber existing file \"'send.c'\"
  1210. else
  1211. echo shar: Extracting \"'send.c'\" \(8182 characters\)
  1212. sed "s/^X//" >'send.c' <<'END_OF_FILE'
  1213. X/*
  1214. X * Copyright (c) 1985, 1989 Regents of the University of California.
  1215. X * All rights reserved.
  1216. X *
  1217. X * Redistribution and use in source and binary forms are permitted provided
  1218. X * that: (1) source distributions retain this entire copyright notice and
  1219. X * comment, and (2) distributions including binaries display the following
  1220. X * acknowledgement:  ``This product includes software developed by the
  1221. X * University of California, Berkeley and its contributors'' in the
  1222. X * documentation or other materials provided with the distribution and in
  1223. X * all advertising materials mentioning features or use of this software.
  1224. X * Neither the name of the University nor the names of its contributors may
  1225. X * be used to endorse or promote products derived from this software without
  1226. X * specific prior written permission.
  1227. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  1228. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  1229. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1230. X */
  1231. X
  1232. X#ifndef lint
  1233. Xstatic char sccsid[] = "@(#)send.c    5.17 (Berkeley) 6/29/90";
  1234. X#endif /* not lint */
  1235. X
  1236. X/*
  1237. X *******************************************************************************
  1238. X *
  1239. X *  send.c --
  1240. X *
  1241. X *    Routine to send request packets to a name server.
  1242. X *
  1243. X *    Based on "@(#)res_send.c  6.25 (Berkeley) 6/1/90".
  1244. X *
  1245. X *******************************************************************************
  1246. X */
  1247. X
  1248. X
  1249. X/*
  1250. X * Send query to name server and wait for reply.
  1251. X */
  1252. X
  1253. X#include <sys/types.h>
  1254. X#include <sys/param.h>
  1255. X#include <sys/time.h>
  1256. X#include <sys/socket.h>
  1257. X#include <sys/uio.h>
  1258. X#include <netinet/in.h>
  1259. X#include <stdio.h>
  1260. X#include <errno.h>
  1261. X#include <arpa/nameser.h>
  1262. X#include <arpa/inet.h>
  1263. X#include <resolv.h>
  1264. X#include "res.h"
  1265. X
  1266. X#ifdef ultrix
  1267. X#define nsaddr_list(i)  ns_list[(i)].addr
  1268. X#else
  1269. X#define nsaddr_list(i)  nsaddr_list[(i)]
  1270. X#endif
  1271. X
  1272. Xextern int errno;
  1273. X
  1274. Xstatic int s = -1;    /* socket used for communications */
  1275. X
  1276. X
  1277. X#ifndef FD_SET
  1278. X#define    NFDBITS        32
  1279. X#define    FD_SETSIZE    32
  1280. X#define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  1281. X#define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  1282. X#define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  1283. X#define FD_ZERO(p)    bzero((char *)(p), sizeof(*(p)))
  1284. X#endif
  1285. X
  1286. X#define SR 1        /* SendRequest style */
  1287. X
  1288. X#ifndef DEBUG
  1289. X#define DEBUG
  1290. X#endif
  1291. X
  1292. Xunsigned short nsport = NAMESERVER_PORT;
  1293. X
  1294. X
  1295. X
  1296. X/*
  1297. X *******************************************************************************
  1298. X *
  1299. X *   SendRequest --
  1300. X *
  1301. X *    Sends a request packet to a name server whose address
  1302. X *    is specified by the first argument and returns with
  1303. X *    the answer packet.
  1304. X *
  1305. X *  Results:
  1306. X *    SUCCESS        - the request was sent and an answer
  1307. X *              was received.
  1308. X *    TIME_OUT    - the virtual circuit connection timed-out
  1309. X *              or a reply to a datagram wasn't received.
  1310. X *
  1311. X *
  1312. X *******************************************************************************
  1313. X */
  1314. X
  1315. Xint
  1316. XSendRequest(nsAddrPtr, buf, buflen, answer, anslen, trueLenPtr)
  1317. X    struct in_addr    *nsAddrPtr;
  1318. X    char        *buf;
  1319. X    int        buflen;
  1320. X    char        *answer;
  1321. X    u_int        anslen;
  1322. X    int        *trueLenPtr;
  1323. X{
  1324. X    register int n;
  1325. X    int try, resplen, ns;
  1326. X    int gotsomewhere = 0, connected = 0;
  1327. X    int connreset = 0;
  1328. X    u_short id, len;
  1329. X    char *cp;
  1330. X    fd_set dsmask;
  1331. X    struct timeval timeout;
  1332. X    HEADER *hp = (HEADER *) buf;
  1333. X    HEADER *anhp = (HEADER *) answer;
  1334. X    struct iovec iov[2];
  1335. X    int terrno = ETIMEDOUT;
  1336. X    char junk[512];
  1337. X
  1338. X#if SR
  1339. X    struct sockaddr_in sin;
  1340. X
  1341. X    if (_res.options & RES_DEBUG2) {
  1342. X        printf("------------\nSendRequest(), len %d\n", buflen);
  1343. X        Print_query(buf, buf+buflen, 1);
  1344. X    }
  1345. X    sin.sin_family    = AF_INET;
  1346. X    sin.sin_port    = htons(nsport);
  1347. X    sin.sin_addr    = *nsAddrPtr;
  1348. X#else
  1349. X#ifdef DEBUG
  1350. X    if (_res.options & RES_DEBUG) {
  1351. X        printf("res_send()\n");
  1352. X        p_query(buf);
  1353. X    }
  1354. X#endif
  1355. X    if (!(_res.options & RES_INIT))
  1356. X        if (res_init() == -1) {
  1357. X            return(-1);
  1358. X        }
  1359. X#endif /* SR */
  1360. X    id = hp->id;
  1361. X    /*
  1362. X     * Send request, RETRY times, or until successful
  1363. X     */
  1364. X    for (try = 0; try < _res.retry; try++) {
  1365. X#if !SR
  1366. X       for (ns = 0; ns < _res.nscount; ns++) {
  1367. X#ifdef DEBUG
  1368. X        if (_res.options & RES_DEBUG)
  1369. X            printf("Querying server (# %d) address = %s\n", ns+1,
  1370. X                  inet_ntoa(_res.nsaddr_list(ns).sin_addr));
  1371. X#endif
  1372. X#endif /* !SR */
  1373. X    usevc:
  1374. X        {
  1375. X            int truncated = 0;
  1376. X
  1377. X            /*
  1378. X             * Use virtual circuit;
  1379. X             * at most one attempt per server.
  1380. X             */
  1381. X            try = _res.retry;
  1382. X            if (s < 0) {
  1383. X                s = socket(AF_INET, SOCK_STREAM, 0);
  1384. X                if (s < 0) {
  1385. X                    terrno = errno;
  1386. X#ifdef DEBUG
  1387. X                    if (_res.options & RES_DEBUG)
  1388. X                        perror("socket (vc) failed");
  1389. X#endif
  1390. X                    continue;
  1391. X                }
  1392. X#if SR
  1393. X                if (connect(s, &sin,
  1394. X#else
  1395. X                if (connect(s, &(_res.nsaddr_list(ns)),
  1396. X#endif
  1397. X                   sizeof(struct sockaddr)) < 0) {
  1398. X                    terrno = errno;
  1399. X#ifdef DEBUG
  1400. X                    if (_res.options & RES_DEBUG)
  1401. X                        perror("connect failed");
  1402. X#endif
  1403. X                    (void) close(s);
  1404. X                    s = -1;
  1405. X                    continue;
  1406. X                }
  1407. X            }
  1408. X            /*
  1409. X             * Send length & message
  1410. X             */
  1411. X            len = htons((u_short)buflen);
  1412. X            iov[0].iov_base = (caddr_t)&len;
  1413. X            iov[0].iov_len = sizeof(len);
  1414. X            iov[1].iov_base = buf;
  1415. X            iov[1].iov_len = buflen;
  1416. X            if (writev(s, iov, 2) != sizeof(len) + buflen) {
  1417. X                terrno = errno;
  1418. X#ifdef DEBUG
  1419. X                if (_res.options & RES_DEBUG)
  1420. X                    perror("write failed");
  1421. X#endif
  1422. X                (void) close(s);
  1423. X                s = -1;
  1424. X                continue;
  1425. X            }
  1426. X            /*
  1427. X             * Receive length & response
  1428. X             */
  1429. X            cp = answer;
  1430. X            len = sizeof(short);
  1431. X            while (len != 0 &&
  1432. X                (n = read(s, (char *)cp, (int)len)) > 0) {
  1433. X                cp += n;
  1434. X                len -= n;
  1435. X            }
  1436. X            if (n <= 0) {
  1437. X                terrno = errno;
  1438. X#ifdef DEBUG
  1439. X                if (_res.options & RES_DEBUG)
  1440. X                    perror("read failed");
  1441. X#endif
  1442. X                (void) close(s);
  1443. X                s = -1;
  1444. X                /*
  1445. X                 * A long running process might get its TCP
  1446. X                 * connection reset if the remote server was
  1447. X                 * restarted.  Requery the server instead of
  1448. X                 * trying a new one.  When there is only one
  1449. X                 * server, this means that a query might work
  1450. X                 * instead of failing.  We only allow one reset
  1451. X                 * per query to prevent looping.
  1452. X                 */
  1453. X                if (terrno == ECONNRESET && !connreset) {
  1454. X                    connreset = 1;
  1455. X                    ns--;
  1456. X                }
  1457. X                continue;
  1458. X            }
  1459. X            cp = answer;
  1460. X            if ((resplen = ntohs(*(u_short *)cp)) > anslen) {
  1461. X#ifdef DEBUG
  1462. X                if (_res.options & RES_DEBUG)
  1463. X                    fprintf(stderr, "response truncated\n");
  1464. X#endif
  1465. X                len = anslen;
  1466. X                truncated = 1;
  1467. X            } else
  1468. X                len = resplen;
  1469. X            while (len != 0 &&
  1470. X               (n = read(s, (char *)cp, (int)len)) > 0) {
  1471. X                cp += n;
  1472. X                len -= n;
  1473. X            }
  1474. X            if (n <= 0) {
  1475. X                terrno = errno;
  1476. X#ifdef DEBUG
  1477. X                if (_res.options & RES_DEBUG)
  1478. X                    perror("read failed");
  1479. X#endif
  1480. X                (void) close(s);
  1481. X                s = -1;
  1482. X                continue;
  1483. X            }
  1484. X            if (truncated) {
  1485. X                /*
  1486. X                 * Flush rest of answer
  1487. X                 * so connection stays in synch.
  1488. X                 */
  1489. X                anhp->tc = 1;
  1490. X                len = resplen - anslen;
  1491. X                while (len != 0) {
  1492. X                    n = (len > sizeof(junk) ?
  1493. X                        sizeof(junk) : len);
  1494. X                    if ((n = read(s, junk, n)) > 0)
  1495. X                        len -= n;
  1496. X                    else
  1497. X                        break;
  1498. X                }
  1499. X            }
  1500. X        }
  1501. X#if SR
  1502. X        if (_res.options & RES_DEBUG) {
  1503. X            if (_res.options & RES_DEBUG2)
  1504. X            printf("------------\nGot answer (%d bytes):\n",
  1505. X                resplen);
  1506. X            else
  1507. X            printf("------------\nGot answer:\n");
  1508. X            Print_query(answer, answer+resplen, 1);
  1509. X        }
  1510. X        (void) close(s);
  1511. X        s = -1;
  1512. X        *trueLenPtr = resplen;
  1513. X        return (SUCCESS);
  1514. X#else
  1515. X#ifdef DEBUG
  1516. X        if (_res.options & RES_DEBUG) {
  1517. X            printf("got answer:\n");
  1518. X            p_query(answer);
  1519. X        }
  1520. X#endif
  1521. X        /*
  1522. X         * If using virtual circuits, we assume that the first server
  1523. X         * is preferred * over the rest (i.e. it is on the local
  1524. X         * machine) and only keep that one open.
  1525. X         * If we have temporarily opened a virtual circuit,
  1526. X         * or if we haven't been asked to keep a socket open,
  1527. X         * close the socket.
  1528. X         */
  1529. X        if ( ((_res.options & RES_USEVC) == 0 || ns != 0) ||
  1530. X            (_res.options & RES_STAYOPEN) == 0) {
  1531. X            (void) close(s);
  1532. X            s = -1;
  1533. X        }
  1534. X        return (resplen);
  1535. X       }
  1536. X#endif /* SR */
  1537. X    }
  1538. X    if (s >= 0) {
  1539. X        (void) close(s);
  1540. X        s = -1;
  1541. X    }
  1542. X#if SR
  1543. X    if (errno == ECONNREFUSED)
  1544. X        return NO_RESPONSE;
  1545. X    else
  1546. X        return ERROR;
  1547. X#else
  1548. X    errno = terrno;
  1549. X    return (-1);
  1550. X#endif
  1551. X}
  1552. X
  1553. X/*
  1554. X * This routine is for closing the socket if a virtual circuit is used and
  1555. X * the program wants to close it.
  1556. X *
  1557. X * Called from the interrupt handler.
  1558. X */
  1559. XSendRequest_close()
  1560. X{
  1561. X    if (s != -1) {
  1562. X        (void) close(s);
  1563. X        s = -1;
  1564. X    }
  1565. X}
  1566. END_OF_FILE
  1567. if test 8182 -ne `wc -c <'send.c'`; then
  1568.     echo shar: \"'send.c'\" unpacked with wrong size!
  1569. fi
  1570. # end of 'send.c'
  1571. fi
  1572. if test -f 'skip.c' -a "${1}" != "-c" ; then 
  1573.   echo shar: Will not clobber existing file \"'skip.c'\"
  1574. else
  1575. echo shar: Extracting \"'skip.c'\" \(4295 characters\)
  1576. sed "s/^X//" >'skip.c' <<'END_OF_FILE'
  1577. X/*
  1578. X * Copyright (c) 1985 Regents of the University of California.
  1579. X * All rights reserved.
  1580. X *
  1581. X * Redistribution and use in source and binary forms are permitted provided
  1582. X * that: (1) source distributions retain this entire copyright notice and
  1583. X * comment, and (2) distributions including binaries display the following
  1584. X * acknowledgement:  ``This product includes software developed by the
  1585. X * University of California, Berkeley and its contributors'' in the
  1586. X * documentation or other materials provided with the distribution and in
  1587. X * all advertising materials mentioning features or use of this software.
  1588. X * Neither the name of the University nor the names of its contributors may
  1589. X * be used to endorse or promote products derived from this software without
  1590. X * specific prior written permission.
  1591. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  1592. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  1593. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1594. X */
  1595. X
  1596. X#ifndef lint
  1597. Xstatic char sccsid[] = "@(#)skip.c    5.9 (Berkeley) 8/3/90";
  1598. X#endif /* not lint */
  1599. X
  1600. X/*
  1601. X *******************************************************************************
  1602. X *
  1603. X *  skip.c --
  1604. X *
  1605. X *    Routines to skip over portions of a query buffer.
  1606. X *
  1607. X *    Note: this file has been submitted for inclusion in
  1608. X *    BIND resolver library. When this has been done, this file
  1609. X *    is no longer necessary (assuming there haven't been any
  1610. X *    changes).
  1611. X *
  1612. X *    Adapted from 4.3BSD BIND res_debug.c
  1613. X *
  1614. X *******************************************************************************
  1615. X */
  1616. X
  1617. X#include <sys/types.h>
  1618. X#include <netinet/in.h>
  1619. X#include <stdio.h>
  1620. X#include <arpa/nameser.h>
  1621. X
  1622. Xchar *res_skip_rr();
  1623. X
  1624. X
  1625. X/*
  1626. X *******************************************************************************
  1627. X *
  1628. X *  res_skip --
  1629. X *
  1630. X *     Skip the contents of a query.
  1631. X *
  1632. X *     Interpretation of numFieldsToSkip argument:
  1633. X *            res_skip returns pointer to:
  1634. X *        1 ->  start of question records.
  1635. X *        2 ->  start of authoritative answer records.
  1636. X *        3 ->  start of additional records.
  1637. X *        4 ->  first byte after end of additional records.
  1638. X *
  1639. X *   Results:
  1640. X *    (address)    - success operation.
  1641. X *      NULL         - a resource record had an incorrect format.
  1642. X *
  1643. X *******************************************************************************
  1644. X */
  1645. X
  1646. Xchar *
  1647. Xres_skip(msg, numFieldsToSkip, eom)
  1648. X    char *msg;
  1649. X    int numFieldsToSkip;
  1650. X    char *eom;
  1651. X{
  1652. X    register char *cp;
  1653. X    register HEADER *hp;
  1654. X    register int tmp;
  1655. X    register int n;
  1656. X
  1657. X    /*
  1658. X     * Skip the header fields.
  1659. X     */
  1660. X    hp = (HEADER *)msg;
  1661. X    cp = msg + sizeof(HEADER);
  1662. X
  1663. X    /*
  1664. X     * skip question records.
  1665. X     */
  1666. X    if (n = ntohs(hp->qdcount) ) {
  1667. X        while (--n >= 0 && cp < eom) {
  1668. X            tmp = dn_skipname(cp, eom);
  1669. X            if (tmp == -1) return(NULL);
  1670. X            cp += tmp;
  1671. X            cp += sizeof(u_short);    /* type     */
  1672. X            cp += sizeof(u_short);    /* class     */
  1673. X        }
  1674. X    }
  1675. X    if (--numFieldsToSkip <= 0) return(cp);
  1676. X
  1677. X    /*
  1678. X     * skip authoritative answer records
  1679. X     */
  1680. X    if (n = ntohs(hp->ancount)) {
  1681. X        while (--n >= 0 && cp < eom) {
  1682. X            cp = res_skip_rr(cp, eom);
  1683. X            if (cp == NULL) return(NULL);
  1684. X        }
  1685. X    }
  1686. X    if (--numFieldsToSkip == 0) return(cp);
  1687. X
  1688. X    /*
  1689. X     * skip name server records
  1690. X     */
  1691. X    if (n = ntohs(hp->nscount)) {
  1692. X        while (--n >= 0 && cp < eom) {
  1693. X            cp = res_skip_rr(cp, eom);
  1694. X            if (cp == NULL) return(NULL);
  1695. X        }
  1696. X    }
  1697. X    if (--numFieldsToSkip == 0) return(cp);
  1698. X
  1699. X    /*
  1700. X     * skip additional records
  1701. X     */
  1702. X    if (n = ntohs(hp->arcount)) {
  1703. X        while (--n >= 0 && cp < eom) {
  1704. X            cp = res_skip_rr(cp, eom);
  1705. X            if (cp == NULL) return(NULL);
  1706. X        }
  1707. X    }
  1708. X
  1709. X    return(cp);
  1710. X}
  1711. X
  1712. X
  1713. X/*
  1714. X *******************************************************************************
  1715. X *
  1716. X *  res_skip_rr --
  1717. X *
  1718. X *     Skip over resource record fields.
  1719. X *
  1720. X *   Results:
  1721. X *    (address)    - success operation.
  1722. X *      NULL         - a resource record had an incorrect format.
  1723. X *******************************************************************************
  1724. X */
  1725. X
  1726. Xchar *
  1727. Xres_skip_rr(cp, eom)
  1728. X    char *cp;
  1729. X    char *eom;
  1730. X{
  1731. X    int tmp;
  1732. X    int dlen;
  1733. X
  1734. X    if ((tmp = dn_skipname(cp, eom)) == -1)
  1735. X        return (NULL);            /* compression error */
  1736. X    cp += tmp;
  1737. X    if ((cp + RRFIXEDSZ) > eom)
  1738. X        return (NULL);
  1739. X    cp += sizeof(u_short);    /*     type     */
  1740. X    cp += sizeof(u_short);    /*     class     */
  1741. X    cp += sizeof(u_long);    /*     ttl     */
  1742. X    dlen = _getshort(cp);
  1743. X    cp += sizeof(u_short);    /*     dlen     */
  1744. X    cp += dlen;
  1745. X    if (cp > eom)
  1746. X        return (NULL);
  1747. X    return (cp);
  1748. X}
  1749. END_OF_FILE
  1750. if test 4295 -ne `wc -c <'skip.c'`; then
  1751.     echo shar: \"'skip.c'\" unpacked with wrong size!
  1752. fi
  1753. # end of 'skip.c'
  1754. fi
  1755. if test -f 'subr.c' -a "${1}" != "-c" ; then 
  1756.   echo shar: Will not clobber existing file \"'subr.c'\"
  1757. else
  1758. echo shar: Extracting \"'subr.c'\" \(7036 characters\)
  1759. sed "s/^X//" >'subr.c' <<'END_OF_FILE'
  1760. X/*
  1761. X * Copyright (c) 1985,1989 Regents of the University of California.
  1762. X * All rights reserved.
  1763. X *
  1764. X * Redistribution and use in source and binary forms are permitted provided
  1765. X * that: (1) source distributions retain this entire copyright notice and
  1766. X * comment, and (2) distributions including binaries display the following
  1767. X * acknowledgement:  ``This product includes software developed by the
  1768. X * University of California, Berkeley and its contributors'' in the
  1769. X * documentation or other materials provided with the distribution and in
  1770. X * all advertising materials mentioning features or use of this software.
  1771. X * Neither the name of the University nor the names of its contributors may
  1772. X * be used to endorse or promote products derived from this software without
  1773. X * specific prior written permission.
  1774. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  1775. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  1776. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1777. X */
  1778. X
  1779. X/*
  1780. X *******************************************************************************
  1781. X *
  1782. X *  subr.c --
  1783. X *
  1784. X *    Miscellaneous subroutines for the name server
  1785. X *    lookup program.
  1786. X *
  1787. X *    Copyright (c) 1985
  1788. X *    Andrew Cherenson
  1789. X *    U.C. Berkeley
  1790. X *    CS298-26  Fall 1985
  1791. X *
  1792. X *******************************************************************************
  1793. X */
  1794. X
  1795. X#include <sys/types.h>
  1796. X#include <netdb.h>
  1797. X#include <sys/socket.h>
  1798. X#include <netinet/in.h>
  1799. X#include <stdio.h>
  1800. X#include <arpa/nameser.h>
  1801. X#include <arpa/inet.h>
  1802. X#include <signal.h>
  1803. X#include <setjmp.h>
  1804. X#include <stdlib.h>
  1805. X#include <string.h>
  1806. X#include "res.h"
  1807. X
  1808. X/*
  1809. X *******************************************************************************
  1810. X *
  1811. X *  OpenFile --
  1812. X *
  1813. X *    Parses a command string for a file name and opens
  1814. X *    the file.
  1815. X *
  1816. X *  Results:
  1817. X *    file pointer    - the open was successful.
  1818. X *    NULL        - there was an error opening the file or
  1819. X *              the input string was invalid.
  1820. X *
  1821. X *******************************************************************************
  1822. X */
  1823. X
  1824. XFILE *
  1825. XOpenFile(string, file)
  1826. X    char *string;
  1827. X    char *file;
  1828. X{
  1829. X    char    *redirect;
  1830. X    FILE    *tmpPtr;
  1831. X
  1832. X    /*
  1833. X     *  Open an output file if we see '>' or >>'.
  1834. X     *  Check for overwrite (">") or concatenation (">>").
  1835. X     */
  1836. X
  1837. X    redirect = strchr(string, '>');
  1838. X    if (redirect == NULL) {
  1839. X        return(NULL);
  1840. X    }
  1841. X    if (redirect[1] == '>') {
  1842. X        sscanf(redirect, ">> %s", file);
  1843. X        tmpPtr = fopen(file, "a+");
  1844. X    } else {
  1845. X        sscanf(redirect, "> %s", file);
  1846. X        tmpPtr = fopen(file, "w");
  1847. X    }
  1848. X
  1849. X    if (tmpPtr != NULL) {
  1850. X        redirect[0] = '\0';
  1851. X    }
  1852. X
  1853. X    return(tmpPtr);
  1854. X}
  1855. X
  1856. X/*
  1857. X *******************************************************************************
  1858. X *
  1859. X *  DecodeError --
  1860. X *
  1861. X *    Converts an error code into a character string.
  1862. X *
  1863. X *******************************************************************************
  1864. X */
  1865. X
  1866. Xchar *
  1867. XDecodeError(result)
  1868. X    int result;
  1869. X{
  1870. X    switch (result) {
  1871. X        case NOERROR:    return("Success"); break;
  1872. X        case FORMERR:    return("Format error"); break;
  1873. X        case SERVFAIL:    return("Server failed"); break;
  1874. X        case NXDOMAIN:    return("Non-existent domain"); break;
  1875. X        case NOTIMP:    return("Not implemented"); break;
  1876. X        case REFUSED:    return("Query refused"); break;
  1877. X        case NOCHANGE:    return("No change"); break;
  1878. X        case TIME_OUT:    return("Timed out"); break;
  1879. X        case NO_INFO:    return("No information"); break;
  1880. X        case ERROR:        return("Unspecified error"); break;
  1881. X        case NONAUTH:    return("Non-authoritative answer"); break;
  1882. X        case NO_RESPONSE:    return("No response from server"); break;
  1883. X        default:        break;
  1884. X    }
  1885. X    return("BAD ERROR VALUE");
  1886. X}
  1887. X
  1888. X
  1889. Xint
  1890. XStringToClass(qclass, dflt)
  1891. X    char *qclass;
  1892. X    int dflt;
  1893. X{
  1894. X    if (strcasecmp(qclass, "IN") == 0)
  1895. X        return(C_IN);
  1896. X    if (strcasecmp(qclass, "CHAOS") == 0)
  1897. X        return(C_CHAOS);
  1898. X    if (strcasecmp(qclass, "ANY") == 0)
  1899. X        return(C_ANY);
  1900. X#ifndef C_HS
  1901. X#define C_HS 4
  1902. X#endif
  1903. X    if (strcasecmp(qclass, "HS") == 0)
  1904. X        return(C_HS);
  1905. X    fprintf(stderr, "unknown query class: %s\n", qclass);
  1906. X    return(dflt);
  1907. X}
  1908. X
  1909. X
  1910. X/*
  1911. X *******************************************************************************
  1912. X *
  1913. X *  StringToType --
  1914. X *
  1915. X *    Converts a string form of a query type name to its
  1916. X *    corresponding integer value.
  1917. X *
  1918. X *******************************************************************************
  1919. X */
  1920. X
  1921. Xint
  1922. XStringToType(type, dflt)
  1923. X    char *type;
  1924. X    int dflt;
  1925. X{
  1926. X    if (strcasecmp(type, "A") == 0)
  1927. X        return(T_A);
  1928. X    if (strcasecmp(type, "NS") == 0)
  1929. X        return(T_NS);            /* authoritative server */
  1930. X    if (strcasecmp(type, "MX") == 0)
  1931. X        return(T_MX);            /* mail exchanger */
  1932. X    if (strcasecmp(type, "CNAME") == 0)
  1933. X        return(T_CNAME);        /* canonical name */
  1934. X    if (strcasecmp(type, "SOA") == 0)
  1935. X        return(T_SOA);            /* start of authority zone */
  1936. X    if (strcasecmp(type, "MB") == 0)
  1937. X        return(T_MB);            /* mailbox domain name */
  1938. X    if (strcasecmp(type, "MG") == 0)
  1939. X        return(T_MG);            /* mail group member */
  1940. X    if (strcasecmp(type, "MR") == 0)
  1941. X        return(T_MR);            /* mail rename name */
  1942. X    if (strcasecmp(type, "WKS") == 0)
  1943. X        return(T_WKS);            /* well known service */
  1944. X    if (strcasecmp(type, "PTR") == 0)
  1945. X        return(T_PTR);            /* domain name pointer */
  1946. X    if (strcasecmp(type, "HINFO") == 0)
  1947. X        return(T_HINFO);        /* host information */
  1948. X    if (strcasecmp(type, "MINFO") == 0)
  1949. X        return(T_MINFO);        /* mailbox information */
  1950. X    if (strcasecmp(type, "AXFR") == 0)
  1951. X        return(T_AXFR);            /* zone transfer */
  1952. X    if (strcasecmp(type, "MAILA") == 0)
  1953. X        return(T_MAILA);        /* mail agent */
  1954. X    if (strcasecmp(type, "MAILB") == 0)
  1955. X        return(T_MAILB);        /* mail box */
  1956. X    if (strcasecmp(type, "ANY") == 0)
  1957. X        return(T_ANY);            /* matches any type */
  1958. X    if (strcasecmp(type, "UINFO") == 0)
  1959. X        return(T_UINFO);        /* user info */
  1960. X    if (strcasecmp(type, "UID") == 0)
  1961. X        return(T_UID);            /* user id */
  1962. X    if (strcasecmp(type, "GID") == 0)
  1963. X        return(T_GID);            /* group id */
  1964. X    fprintf(stderr, "unknown query type: %s\n", type);
  1965. X    return(dflt);
  1966. X}
  1967. X
  1968. X/*
  1969. X *******************************************************************************
  1970. X *
  1971. X *  DecodeType --
  1972. X *
  1973. X *    Converts a query type to a descriptive name.
  1974. X *    (A more verbose form of p_type.)
  1975. X *
  1976. X *
  1977. X *******************************************************************************
  1978. X */
  1979. X
  1980. Xstatic  char nbuf[20];
  1981. X
  1982. Xchar *
  1983. XDecodeType(type)
  1984. X    int type;
  1985. X{
  1986. X    switch (type) {
  1987. X    case T_A:
  1988. X        return("address");
  1989. X    case T_NS:
  1990. X        return("name server");
  1991. X    case T_CNAME:
  1992. X        return("canonical name");
  1993. X    case T_SOA:
  1994. X        return("start of authority");
  1995. X    case T_MB:
  1996. X        return("mailbox");
  1997. X    case T_MG:
  1998. X        return("mail group member");
  1999. X    case T_MR:
  2000. X        return("mail rename");
  2001. X    case T_NULL:
  2002. X        return("null");
  2003. X    case T_WKS:
  2004. X        return("well-known service");
  2005. X    case T_PTR:
  2006. X        return("domain name pointer");
  2007. X    case T_HINFO:
  2008. X        return("host information");
  2009. X    case T_MINFO:
  2010. X        return("mailbox information");
  2011. X    case T_MX:
  2012. X        return("mail exchanger");
  2013. X    case T_UINFO:
  2014. X        return("user information");
  2015. X    case T_UID:
  2016. X        return("user ID");
  2017. X    case T_GID:
  2018. X        return("group ID");
  2019. X    case T_AXFR:
  2020. X        return("zone transfer");
  2021. X    case T_MAILB:
  2022. X        return("mailbox-related data");
  2023. X    case T_MAILA:
  2024. X        return("mail agent");
  2025. X    case T_ANY:
  2026. X        return("\"any\"");
  2027. X    default:
  2028. X        (void) sprintf(nbuf, "%d", type);
  2029. X        return (nbuf);
  2030. X    }
  2031. X}
  2032. END_OF_FILE
  2033. if test 7036 -ne `wc -c <'subr.c'`; then
  2034.     echo shar: \"'subr.c'\" unpacked with wrong size!
  2035. fi
  2036. # end of 'subr.c'
  2037. fi
  2038. if test -f 'vtable.c' -a "${1}" != "-c" ; then 
  2039.   echo shar: Will not clobber existing file \"'vtable.c'\"
  2040. else
  2041. echo shar: Extracting \"'vtable.c'\" \(3648 characters\)
  2042. sed "s/^X//" >'vtable.c' <<'END_OF_FILE'
  2043. X/*
  2044. X * VARIABLE LENGTH TABLES
  2045. X *
  2046. X * Features: Grows according to how many records you put into it.
  2047. X *           It it not possible to have empty slots in the table.
  2048. X */
  2049. X#include <stdio.h>
  2050. X#include <stdlib.h>
  2051. X#include <assert.h>
  2052. X#include "vtable.h"
  2053. X#include <string.h>
  2054. X#ifndef SYSV
  2055. X#include <memory.h>
  2056. X#endif
  2057. X
  2058. Xvtable *
  2059. XVTableCreate(int recsize)
  2060. X{
  2061. X   vtable *vt;
  2062. X
  2063. X   assert(recsize);
  2064. X   vt = (vtable *)malloc(sizeof(vtable));
  2065. X   assert(vt);
  2066. X   memset(vt,0,sizeof(vtable));
  2067. X   vt->rec_size = recsize;
  2068. X   vt->cmp = (vtablecmp)memcmp;
  2069. X   vt->magic = 0xdb;
  2070. X   return vt;
  2071. X}
  2072. X
  2073. XVTableSet(vtable *vt,int recsize)
  2074. X{
  2075. X   memset(vt,0,sizeof(vtable));
  2076. X   vt->rec_size = recsize;
  2077. X   vt->cmp = (vtablecmp)memcmp;
  2078. X   vt->magic = 0xdb;
  2079. X}
  2080. X
  2081. Xint
  2082. XVTableAlloc(vtable *vt,int nelem)
  2083. X{
  2084. X /* Allocate more space */
  2085. X    if(nelem <= 0 || nelem == vt->num_slots)
  2086. X         return 0;
  2087. X    if(nelem < vt->num_slots)
  2088. X    {
  2089. X    if(vt->end > nelem)
  2090. X       return 1;
  2091. X    }
  2092. X    vt->num_slots = nelem;
  2093. X    if(vt->end == 0)
  2094. X    vt->data = malloc(vt->num_slots * vt->rec_size);
  2095. X    else
  2096. X    vt->data = realloc(vt->data,vt->num_slots * vt->rec_size);
  2097. X    return 0;
  2098. X}
  2099. X
  2100. Xvoid VTableSetCmp(vtable *vt,vtablecmp cmp)
  2101. X{
  2102. X   vt->cmp = cmp;
  2103. X}
  2104. X
  2105. Xvoid
  2106. XVTableAppend(vtable *vt,char *data)
  2107. X{
  2108. X    assert(vt && (vt->magic == 0xdb));
  2109. X    if(vt->num_slots == vt->end)
  2110. X    { /* Allocate more space */
  2111. X        vt->num_slots += (vt->num_slots / 2) + 2;
  2112. X        if(vt->end == 0)
  2113. X        vt->data = malloc(vt->num_slots * vt->rec_size);
  2114. X    else
  2115. X        vt->data = realloc(vt->data,vt->num_slots * vt->rec_size);
  2116. X    }
  2117. X    memcpy(vt->data + (vt->rec_size * vt->end),data,vt->rec_size);
  2118. X    vt->end++;
  2119. X}
  2120. X
  2121. X/*
  2122. X * Only to be used if your table was created with VTableCreate
  2123. X */
  2124. Xvoid
  2125. XVTableDestroy(vtable *vt)
  2126. X{
  2127. X    assert(vt && (vt->magic == 0xdb));
  2128. X    if(vt->data) free(vt->data);
  2129. X    vt->data = NULL;
  2130. X    vt->num_slots = 0;
  2131. X    vt->magic = 0;
  2132. X    free(vt);
  2133. X}
  2134. X
  2135. Xvoid
  2136. XVTableClean(vtable *vt)
  2137. X{
  2138. X    if(vt->data) free(vt->data);
  2139. X/*  vt->rec_size = 0; */
  2140. X    vt->data = NULL;
  2141. X    vt->num_slots = 0;
  2142. X    vt->end = 0;
  2143. X}
  2144. X
  2145. Xchar *
  2146. XVTableIndex(vtable *vt,int inx)
  2147. X{
  2148. X    if(!vt->data) return NULL;
  2149. X    if((inx >= vt->end)|| inx <0) return NULL;
  2150. X    return vt->data + (inx * vt->rec_size);
  2151. X}
  2152. X
  2153. X/*
  2154. X * This function is designed for a while loop.
  2155. X */
  2156. Xchar *
  2157. XVTableNext(vtable *vt,int *inx,int step)
  2158. X{
  2159. X   char *rec;
  2160. X
  2161. X    assert(vt && (vt->magic == 0xdb));
  2162. X    rec = VTableIndex(vt,*inx);
  2163. X    if(rec)
  2164. X        (*inx)+= step;
  2165. X    return rec;
  2166. X}
  2167. X
  2168. Xchar *
  2169. XVTableLookup(vtable *vt,char *key)
  2170. X{
  2171. X    register int position;
  2172. X
  2173. X    if(!vt->data) return (char*)0;
  2174. X    for(position = 0; position < vt->end; position++)
  2175. X    {
  2176. X    if(!(*vt->cmp)(key,vt->data + (position * vt->rec_size),vt->rec_size))
  2177. X        break;
  2178. X    }
  2179. X    if(position == vt->end) return (char*)0;
  2180. X
  2181. X    return vt->data + (position * vt->rec_size);
  2182. X}
  2183. X
  2184. Xvoid
  2185. XVTableRemove(vtable *vt,char *rec)
  2186. X{
  2187. X    register int position;
  2188. X
  2189. X    if(!vt->data) return;
  2190. X    for(position = 0; position < vt->end; position++)
  2191. X    {
  2192. X    if(!(*vt->cmp)(rec,vt->data + (position * vt->rec_size),vt->rec_size))
  2193. X        break;
  2194. X    }
  2195. X    if(position == vt->end) return;
  2196. X
  2197. X    VTableIRemove(vt,position);
  2198. X    return ;
  2199. X}
  2200. X
  2201. Xvoid
  2202. XVTableIRemove(vtable *vt,int position)
  2203. X{
  2204. X    if(position >= vt->end || position < 0) return;
  2205. X
  2206. X    if(!vt->data) return;
  2207. X    /* Ripple children down one space from "position" */
  2208. X    vt->end--;
  2209. X    if((vt->end - position) > 0)
  2210. X    {
  2211. X    bcopy(vt->data + ((position+1) * vt->rec_size),
  2212. X        vt->data + (position * vt->rec_size),
  2213. X        (vt->end - position) * vt->rec_size);
  2214. X    }
  2215. X    return ;
  2216. X}
  2217. X
  2218. Xint
  2219. XVTableSize(vtable *vt)
  2220. X{
  2221. X    return vt->end;
  2222. X}
  2223. X
  2224. X/*
  2225. X * Keep the allocated space.
  2226. X */
  2227. Xvoid
  2228. XVTableZero(vtable *vt)
  2229. X{
  2230. X    vt->end = 0;
  2231. X}
  2232. END_OF_FILE
  2233. if test 3648 -ne `wc -c <'vtable.c'`; then
  2234.     echo shar: \"'vtable.c'\" unpacked with wrong size!
  2235. fi
  2236. # end of 'vtable.c'
  2237. fi
  2238. if test -f 'vtable.h' -a "${1}" != "-c" ; then 
  2239.   echo shar: Will not clobber existing file \"'vtable.h'\"
  2240. else
  2241. echo shar: Extracting \"'vtable.h'\" \(744 characters\)
  2242. sed "s/^X//" >'vtable.h' <<'END_OF_FILE'
  2243. X#ifndef _VTABLE_H_
  2244. X#define _VTABLE_H_
  2245. Xtypedef int (*vtablecmp)(void*,void*,int);
  2246. X/*
  2247. X * Variable length tables;
  2248. X */
  2249. Xtypedef struct {
  2250. X   int magic;
  2251. X   int end;
  2252. X   char *data;
  2253. X   int rec_size;
  2254. X   int num_slots;
  2255. X   vtablecmp cmp;
  2256. X} vtable;
  2257. X
  2258. Xvtable *VTableCreate(int recsize);
  2259. Xint     VTableSet(vtable *,int recsize);
  2260. Xvoid    VTableAppend(vtable *,char *data);
  2261. Xvoid    VTableDestroy(vtable *);
  2262. Xchar *  VTableIndex(vtable *,int inx);
  2263. Xchar *  VTableNext(vtable *,int *inx,int step);
  2264. Xvoid    VTableRemove(vtable *,char *rec);
  2265. Xvoid    VTableIRemove(vtable *,int position);
  2266. X
  2267. Xextern int VTableSize(vtable *vt);
  2268. Xextern void VTableZero(vtable *vt);
  2269. Xextern void VTableSetCmp(vtable *,vtablecmp);
  2270. Xextern int VTableAlloc(vtable *,int);
  2271. X#endif /* _VTABLE_H_ */
  2272. END_OF_FILE
  2273. if test 744 -ne `wc -c <'vtable.h'`; then
  2274.     echo shar: \"'vtable.h'\" unpacked with wrong size!
  2275. fi
  2276. # end of 'vtable.h'
  2277. fi
  2278. echo shar: End of archive 1 \(of 3\).
  2279. cp /dev/null ark1isdone
  2280. MISSING=""
  2281. for I in 1 2 3 ; do
  2282.     if test ! -f ark${I}isdone ; then
  2283.     MISSING="${MISSING} ${I}"
  2284.     fi
  2285. done
  2286. if test "${MISSING}" = "" ; then
  2287.     echo You have unpacked all 3 archives.
  2288.     rm -f ark[1-9]isdone
  2289. else
  2290.     echo You still need to unpack the following archives:
  2291.     echo "        " ${MISSING}
  2292. fi
  2293. ##  End of shell archive.
  2294. exit 0
  2295.