| 1 | /* |
| 2 | * adnshost.c |
| 3 | * - useful general-purpose resolver client program |
| 4 | */ |
| 5 | /* |
| 6 | * This file is |
| 7 | * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> |
| 8 | * |
| 9 | * It is part of adns, which is |
| 10 | * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> |
| 11 | * Copyright (C) 1999 Tony Finch <dot@dotat.at> |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2, or (at your option) |
| 16 | * any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software Foundation, |
| 25 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 26 | */ |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <string.h> |
| 30 | #include <errno.h> |
| 31 | |
| 32 | #include "config.h" |
| 33 | |
| 34 | static void sysfail(const char *what, int errnoval) NONRETURNING; |
| 35 | static void sysfail(const char *what, int errnoval) { |
| 36 | fprintf(stderr,"adnshost failed: %s: %s\n",what,strerror(errnoval)); |
| 37 | exit(10); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | static void printusage(void) { |
| 42 | if (fputs |
| 43 | ("usage: adnshost [global-opts] [query-opts] query-domain\n" |
| 44 | " [[query-opts] query-domain ...]\n" |
| 45 | " adnshost [global-opts] [query-opts] -f|--pipe\n" |
| 46 | "\n" |
| 47 | "global binary options:\n" |
| 48 | " +e --no-env Do not look at environment variables at all.\n" |
| 49 | " -f --pipe Read queries on stdin instead of using args.\n" |
| 50 | " -a --asynch Allow answers to be reordered.\n" |
| 51 | " -0 --null stdin items are delimited by nulls.\n" |
| 52 | "global verbosity level:\n" |
| 53 | " -Vq --quiet Do not print anything to stderr.\n" |
| 54 | " -Vn --no-quiet Report unexpected kinds of problem only. (default)\n" |
| 55 | " -Vd --debug Debugging mode.\n" |
| 56 | "other global options:\n" |
| 57 | " --help, --version Print usage or version information.\n" |
| 58 | "\n" |
| 59 | "per-query binary options:\n" |
| 60 | " -s --search Use the search list.\n" |
| 61 | " -Qq --qc-query Let query domains contain quote-requiring chars.\n" |
| 62 | " -Qa --qc-anshost Let hostnames in answers contain ...\n" |
| 63 | " +Qc --no-qc-cname Prevent CNAME target domains from containing ...\n" |
| 64 | " -u --tcp Force use of a virtual circuit.\n" |
| 65 | " +Do --no-owner Do not display owner name in output.\n" |
| 66 | " +Dt --no-type Do not display RR type in output.\n" |
| 67 | " +Dc --no-show-cname Do not display CNAME target in output.\n" |
| 68 | "per-query TTL mode (NB TTL is minimum across whole query reply):\n" |
| 69 | " -Tt --ttl-ttl Show the TTL as a TTL.\n" |
| 70 | " -Ta --ttl-abs Show the TTL as a time_t when the data might expire.\n" |
| 71 | " -Tn --no-ttl Do not show the TTL (default).\n" |
| 72 | "per-query cname handling mode:\n" |
| 73 | " -Cf --cname-reject Call it an error if a CNAME is found.\n" |
| 74 | " -Cl --cname-loose Allow references to CNAMEs in other RRs.\n" |
| 75 | " -Cs --cname-ok CNAME ok for query domain, but not in RRs (default).\n" |
| 76 | "query type:\n" |
| 77 | " -t<type> } Set the query type (see below).\n" |
| 78 | " --type <type> } Default is addr. Not case-sensitive.\n" |
| 79 | "other per-query options:\n" |
| 80 | " -i<id> } Set the <id> to print in the output with --async;\n" |
| 81 | " --asynch-id <id> } default is a sequence number in decimal starting at 0.\n" |
| 82 | " --cancel-id <id> Cancel the query with id <id>.\n" |
| 83 | " - <domain> Next argument is a domain, but more options may follow.\n" |
| 84 | "\n" |
| 85 | "For binary options, --FOO and --no-FOO are opposites, as are\n" |
| 86 | "-X and +X. In each case the default is the one not listed.\n" |
| 87 | "Per query options stay set a particular way until they are reset,\n" |
| 88 | "whether they appear on the command line or on stdin.\n" |
| 89 | "All global options must preceed the first query domain.\n" |
| 90 | "\n" |
| 91 | "Output format is master file format without class or TTL by default:\n" |
| 92 | " [<owner>] [<ttl>] [<type>] <data>\n" |
| 93 | "or if the <owner> domain refers to a CNAME and --show-cname is on\n" |
| 94 | " [<owner>] [<ttl>] CNAME <cname>\n" |
| 95 | " [<cname>] [<ttl>] <type> <data>\n" |
| 96 | "When a query fails you get a line like:\n" |
| 97 | " ; failed <statustype> [<owner>] [<ttl>] [<type>] <status> \"<status string>\"\n" |
| 98 | "If you use --asynch, you don't get that. Instead, each answer (success or\n" |
| 99 | "failure) is preceded by a line:\n" |
| 100 | " <id> <statustype> <status> <nrrs> [<cname>] \"<status string>\"\n" |
| 101 | "where <nrrs> is the number of RRs that follow and <cname> will be `$' or\n" |
| 102 | "the canonical name.\n" |
| 103 | "\n" |
| 104 | "With -f, the input should be a list of arguments one per line (ie separated\n" |
| 105 | "by newlines), or separated by null characters if -0 or --null was used\n" |
| 106 | "\n" |
| 107 | "Exit status:\n" |
| 108 | " 0 all went well\n" |
| 109 | " 1-6 at least one query failed with statustype:\n" |
| 110 | " 1 localfail )\n" |
| 111 | " 2 remotefail ) temporary errors\n" |
| 112 | " 3 tempfail __)_________________\n" |
| 113 | " 4 misconfig )\n" |
| 114 | " 5 misquery ) permanent errors\n" |
| 115 | " 6 permfail )\n" |
| 116 | " 10 system trouble\n" |
| 117 | " 11 usage problems\n" |
| 118 | "\n" |
| 119 | "Query types (see adns.h):\n" |
| 120 | " ns soa ptr mx rp addr - enhanced versions\n" |
| 121 | " cname hinfo txt - types with only one version\n" |
| 122 | " a ns- soa- ptr- mx- rp- - _raw versions\n", |
| 123 | stdout) == EOF) sysfail("write usage message",errno); |
| 124 | } |
| 125 | |
| 126 | int main(int argc, const char *const *argv) { |
| 127 | printusage(); |
| 128 | if (fclose(stdout)) sysfail("finish writing output",errno); |
| 129 | exit(0); |
| 130 | } |