hesinfo.c revision 1.3
11.3Sjmmv/* $NetBSD: hesinfo.c,v 1.3 2004/01/05 23:23:34 jmmv 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.3Sjmmv__RCSID("$NetBSD: hesinfo.c,v 1.3 2004/01/05 23:23:34 jmmv 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.1Slukem 401.1Slukemint 411.1Slukemmain(argc, argv) 421.1Slukem int argc; 431.1Slukem char **argv; 441.1Slukem{ 451.1Slukem char **list, **p, *bindname, *name, *type; 461.1Slukem int lflag = 0, errflg = 0, bflag = 0, c; 471.1Slukem void *context; 481.1Slukem 491.1Slukem while ((c = getopt(argc, argv, "lb")) != -1) { 501.1Slukem switch (c) { 511.1Slukem case 'l': 521.1Slukem lflag = 1; 531.1Slukem break; 541.1Slukem case 'b': 551.1Slukem bflag = 1; 561.1Slukem break; 571.1Slukem default: 581.1Slukem errflg++; 591.1Slukem break; 601.1Slukem } 611.1Slukem } 621.1Slukem if (argc - optind != 2 || errflg) { 631.3Sjmmv fprintf(stderr, "usage: %s [-bl] name type\n", getprogname()); 641.1Slukem fprintf(stderr, "\t-l selects long format\n"); 651.1Slukem fprintf(stderr, "\t-b also does hes_to_bind conversion\n"); 661.1Slukem exit(2); 671.1Slukem } 681.1Slukem name = argv[optind]; 691.1Slukem type = argv[optind + 1]; 701.1Slukem 711.1Slukem if (hesiod_init(&context) < 0) { 721.1Slukem if (errno == ENOEXEC) 731.1Slukem warnx( 741.1Slukem "hesiod_init: Invalid Hesiod configuration file."); 751.1Slukem else 761.1Slukem warn("hesiod_init"); 771.1Slukem } 781.1Slukem /* Display bind name if requested. */ 791.1Slukem if (bflag) { 801.1Slukem if (lflag) 811.1Slukem printf("hes_to_bind(%s, %s) expands to\n", name, type); 821.1Slukem bindname = hesiod_to_bind(context, name, type); 831.1Slukem if (!bindname) { 841.1Slukem if (lflag) 851.1Slukem printf("nothing\n"); 861.1Slukem if (errno == ENOENT) 871.1Slukem warnx("hesiod_to_bind: Unknown rhs-extension."); 881.1Slukem else 891.1Slukem warn("hesiod_to_bind"); 901.1Slukem exit(1); 911.1Slukem } 921.1Slukem printf("%s\n", bindname); 931.1Slukem free(bindname); 941.1Slukem if (lflag) 951.1Slukem printf("which "); 961.1Slukem } 971.1Slukem if (lflag) 981.1Slukem printf("resolves to\n"); 991.1Slukem 1001.1Slukem /* Do the hesiod resolve and check for errors. */ 1011.1Slukem list = hesiod_resolve(context, name, type); 1021.1Slukem if (!list) { 1031.1Slukem if (lflag) 1041.1Slukem printf("nothing\n"); 1051.1Slukem if (errno == ENOENT) 1061.1Slukem warnx("hesiod_resolve: Hesiod name not found."); 1071.1Slukem else 1081.1Slukem warn("hesiod_resolve"); 1091.1Slukem exit(1); 1101.1Slukem } 1111.1Slukem /* Display the results. */ 1121.1Slukem for (p = list; *p; p++) 1131.1Slukem printf("%s\n", *p); 1141.1Slukem 1151.1Slukem hesiod_free_list(context, list); 1161.1Slukem hesiod_end(context); 1171.1Slukem exit(0); 1181.1Slukem} 119