hesinfo.c revision 1.1
11.1Slukem/* $NetBSD: hesinfo.c,v 1.1 1999/01/25 22:45:55 lukem Exp $ */ 21.1Slukem 31.1Slukem/* Copyright 1988, 1996 by the Massachusetts Institute of Technology. 41.1Slukem * 51.1Slukem * Permission to use, copy, modify, and distribute this 61.1Slukem * software and its documentation for any purpose and without 71.1Slukem * fee is hereby granted, provided that the above copyright 81.1Slukem * notice appear in all copies and that both that copyright 91.1Slukem * notice and this permission notice appear in supporting 101.1Slukem * documentation, and that the name of M.I.T. not be used in 111.1Slukem * advertising or publicity pertaining to distribution of the 121.1Slukem * software without specific, written prior permission. 131.1Slukem * M.I.T. makes no representations about the suitability of 141.1Slukem * this software for any purpose. It is provided "as is" 151.1Slukem * without express or implied warranty. 161.1Slukem */ 171.1Slukem 181.1Slukem/* This file is a simple driver for the Hesiod library. */ 191.1Slukem 201.1Slukem 211.1Slukem#include <sys/cdefs.h> 221.1Slukem#ifndef lint 231.1Slukem#if 0 241.1Slukemstatic char rcsid[] = "#Id: hesinfo.c,v 1.8 1996/12/08 21:29:54 ghudson Exp #"; 251.1Slukem#else 261.1Slukem__RCSID("$NetBSD: hesinfo.c,v 1.1 1999/01/25 22:45:55 lukem Exp $"); 271.1Slukem#endif 281.1Slukem#endif /* not lint */ 291.1Slukem 301.1Slukem#include <err.h> 311.1Slukem#include <errno.h> 321.1Slukem#include <hesiod.h> 331.1Slukem#include <stdio.h> 341.1Slukem#include <stdlib.h> 351.1Slukem#include <string.h> 361.1Slukem#include <unistd.h> 371.1Slukem 381.1Slukemint main __P((int, char **)); 391.1Slukemextern char *__progname; 401.1Slukem 411.1Slukemint 421.1Slukemmain(argc, argv) 431.1Slukem int argc; 441.1Slukem char **argv; 451.1Slukem{ 461.1Slukem char **list, **p, *bindname, *name, *type; 471.1Slukem int lflag = 0, errflg = 0, bflag = 0, c; 481.1Slukem void *context; 491.1Slukem 501.1Slukem while ((c = getopt(argc, argv, "lb")) != -1) { 511.1Slukem switch (c) { 521.1Slukem case 'l': 531.1Slukem lflag = 1; 541.1Slukem break; 551.1Slukem case 'b': 561.1Slukem bflag = 1; 571.1Slukem break; 581.1Slukem default: 591.1Slukem errflg++; 601.1Slukem break; 611.1Slukem } 621.1Slukem } 631.1Slukem if (argc - optind != 2 || errflg) { 641.1Slukem fprintf(stderr, "Usage: %s [-bl] name type\n", __progname); 651.1Slukem fprintf(stderr, "\t-l selects long format\n"); 661.1Slukem fprintf(stderr, "\t-b also does hes_to_bind conversion\n"); 671.1Slukem exit(2); 681.1Slukem } 691.1Slukem name = argv[optind]; 701.1Slukem type = argv[optind + 1]; 711.1Slukem 721.1Slukem if (hesiod_init(&context) < 0) { 731.1Slukem if (errno == ENOEXEC) 741.1Slukem warnx( 751.1Slukem "hesiod_init: Invalid Hesiod configuration file."); 761.1Slukem else 771.1Slukem warn("hesiod_init"); 781.1Slukem } 791.1Slukem /* Display bind name if requested. */ 801.1Slukem if (bflag) { 811.1Slukem if (lflag) 821.1Slukem printf("hes_to_bind(%s, %s) expands to\n", name, type); 831.1Slukem bindname = hesiod_to_bind(context, name, type); 841.1Slukem if (!bindname) { 851.1Slukem if (lflag) 861.1Slukem printf("nothing\n"); 871.1Slukem if (errno == ENOENT) 881.1Slukem warnx("hesiod_to_bind: Unknown rhs-extension."); 891.1Slukem else 901.1Slukem warn("hesiod_to_bind"); 911.1Slukem exit(1); 921.1Slukem } 931.1Slukem printf("%s\n", bindname); 941.1Slukem free(bindname); 951.1Slukem if (lflag) 961.1Slukem printf("which "); 971.1Slukem } 981.1Slukem if (lflag) 991.1Slukem printf("resolves to\n"); 1001.1Slukem 1011.1Slukem /* Do the hesiod resolve and check for errors. */ 1021.1Slukem list = hesiod_resolve(context, name, type); 1031.1Slukem if (!list) { 1041.1Slukem if (lflag) 1051.1Slukem printf("nothing\n"); 1061.1Slukem if (errno == ENOENT) 1071.1Slukem warnx("hesiod_resolve: Hesiod name not found."); 1081.1Slukem else 1091.1Slukem warn("hesiod_resolve"); 1101.1Slukem exit(1); 1111.1Slukem } 1121.1Slukem /* Display the results. */ 1131.1Slukem for (p = list; *p; p++) 1141.1Slukem printf("%s\n", *p); 1151.1Slukem 1161.1Slukem hesiod_free_list(context, list); 1171.1Slukem hesiod_end(context); 1181.1Slukem exit(0); 1191.1Slukem} 120