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