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