chiark / gitweb /
Fix typo in changelog entry for 1.6.1
[adns.git] / client / fanftest.c
1 /*
2  * fanftest.c
3  * - a small test program from Tony Finch
4  */
5 /*
6  *  This file is part of adns, which is Copyright Ian Jackson
7  *  and contributors (see the file INSTALL for full details).
8  *  
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 3, or (at your option)
12  *  any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, write to the Free Software Foundation.
21  *
22  * This version was originally supplied by Tony Finch, but has been
23  * modified by Ian Jackson as it was incorporated into adns.
24  */
25
26 #include <sys/types.h>
27 #include <sys/time.h>
28
29 #include <string.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <errno.h>
33
34 #include "config.h"
35 #include "adns.h"
36
37 static const char *progname;
38
39 static void aargh(const char *msg) {
40   fprintf(stderr, "%s: %s: %s (%d)\n", progname, msg,
41           strerror(errno) ? strerror(errno) : "Unknown error", errno);
42   exit(1);
43 }
44
45 int main(int argc, char *argv[]) {
46   adns_state adns;
47   adns_query query;
48   adns_answer *answer;
49
50   progname= strrchr(*argv, '/');
51   if (progname)
52     progname++;
53   else
54     progname= *argv;
55
56   if (argc != 2) {
57     fprintf(stderr, "usage: %s <domain>\n", progname);
58     exit(1);
59   }
60
61   errno= adns_init(&adns, adns_if_debug, 0);
62   if (errno) aargh("adns_init");
63
64   errno= adns_submit(adns, argv[1], adns_r_ptr,
65                      adns_qf_quoteok_cname|adns_qf_cname_loose,
66                      NULL, &query);
67   if (errno) aargh("adns_submit");
68
69   errno= adns_wait(adns, &query, &answer, NULL);
70   if (errno) aargh("adns_init");
71
72   printf("%s\n", answer->status == adns_s_ok ? *answer->rrs.str : "dunno");
73
74   adns_finish(adns);
75
76   return 0;
77 }