b3543b6b |
1 | /* |
2 | * adh-query.c |
3 | * - useful general-purpose resolver client program |
4 | * make queries and print answers |
5 | */ |
6 | /* |
7 | * This file is |
8 | * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> |
9 | * |
10 | * It is part of adns, which is |
11 | * Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk> |
12 | * Copyright (C) 1999 Tony Finch <dot@dotat.at> |
13 | * |
14 | * This program is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU General Public License as published by |
16 | * the Free Software Foundation; either version 2, or (at your option) |
17 | * any later version. |
18 | * |
19 | * This program is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU General Public License |
25 | * along with this program; if not, write to the Free Software Foundation, |
26 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
27 | */ |
28 | |
aa1d7195 |
29 | #include "adnshost.h" |
30 | |
31 | adns_state ads; |
32 | |
b3543b6b |
33 | struct query_node { |
34 | struct query_node *next, *back; |
35 | struct perqueryflags_remember pqfr; |
36 | char *id; |
37 | adns_query qu; |
38 | }; |
39 | |
b3543b6b |
40 | static struct { struct query_node *head, *tail; } outstanding; |
41 | |
42 | static unsigned long idcounter; |
43 | |
aa1d7195 |
44 | void domain_do(const char *domain) { |
b3543b6b |
45 | struct query_node *qun; |
46 | char idbuf[20]; |
aa1d7195 |
47 | int r; |
b3543b6b |
48 | |
49 | if (!ads) { |
aa1d7195 |
50 | if (signal(SIGPIPE,SIG_IGN) == SIG_ERR) sysfail("ignore SIGPIPE",errno); |
b3543b6b |
51 | r= adns_init(&ads, |
52 | adns_if_noautosys|adns_if_nosigpipe | |
aa1d7195 |
53 | (ov_env ? 0 : adns_if_noenv) | |
b3543b6b |
54 | ov_verbose, |
55 | 0); |
56 | if (r) sysfail("adns_init",r); |
57 | } |
58 | |
59 | qun= malloc(sizeof(*qun)); |
60 | qun->pqfr= ov_pqfr; |
61 | if (ov_id) { |
62 | qun->id= xstrsave(ov_id); |
63 | } else { |
64 | sprintf(idbuf,"%lu",idcounter++); |
65 | idcounter &= 0x0fffffffflu; |
66 | qun->id= xstrsave(idbuf); |
67 | } |
68 | |
aa1d7195 |
69 | r= adns_submit(ads, domain, |
70 | ov_type == adns_r_none ? adns_r_addr : ov_type, |
b3543b6b |
71 | (ov_search ? adns_qf_search : 0) | |
72 | (ov_tcp ? adns_qf_usevc : 0) | |
73 | (ov_pqfr.show_owner ? adns_qf_owner : 0) | |
74 | (ov_qc_query ? adns_qf_quoteok_query : 0) | |
75 | (ov_qc_anshost ? adns_qf_quoteok_anshost : 0) | |
76 | (ov_qc_cname ? 0 : adns_qf_quoteok_cname) | |
77 | ov_cname, |
78 | qun, |
79 | &qun->qu); |
80 | if (r) sysfail("adns_submit",r); |
81 | |
aa1d7195 |
82 | LIST_LINK_TAIL(outstanding,qun); |
b3543b6b |
83 | } |
aa1d7195 |
84 | |
85 | void of_asynch_id(const struct optioninfo *oi, const char *arg) { abort(); } |
86 | void of_cancel_id(const struct optioninfo *oi, const char *arg) { abort(); } |