| 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 | |
| 29 | struct query_node { |
| 30 | struct query_node *next, *back; |
| 31 | struct perqueryflags_remember pqfr; |
| 32 | char *id; |
| 33 | adns_query qu; |
| 34 | }; |
| 35 | |
| 36 | static adns_state ads; |
| 37 | static struct { struct query_node *head, *tail; } outstanding; |
| 38 | |
| 39 | static unsigned long idcounter; |
| 40 | |
| 41 | static void domain_do(const char *domain) { |
| 42 | struct query_node *qun; |
| 43 | char idbuf[20]; |
| 44 | |
| 45 | if (!ads) { |
| 46 | if (signal(SIGPIPE,SIG_IGN) == SIG_ERR) sysfail("ignore SIGPIPE"); |
| 47 | r= adns_init(&ads, |
| 48 | adns_if_noautosys|adns_if_nosigpipe | |
| 49 | (ov_env ? 0 : adns_ifnoenv) | |
| 50 | ov_verbose, |
| 51 | 0); |
| 52 | if (r) sysfail("adns_init",r); |
| 53 | } |
| 54 | |
| 55 | qun= malloc(sizeof(*qun)); |
| 56 | qun->pqfr= ov_pqfr; |
| 57 | if (ov_id) { |
| 58 | qun->id= xstrsave(ov_id); |
| 59 | } else { |
| 60 | sprintf(idbuf,"%lu",idcounter++); |
| 61 | idcounter &= 0x0fffffffflu; |
| 62 | qun->id= xstrsave(idbuf); |
| 63 | } |
| 64 | |
| 65 | r= adns_submit(ads, domain, type, |
| 66 | (ov_search ? adns_qf_search : 0) | |
| 67 | (ov_tcp ? adns_qf_usevc : 0) | |
| 68 | (ov_pqfr.show_owner ? adns_qf_owner : 0) | |
| 69 | (ov_qc_query ? adns_qf_quoteok_query : 0) | |
| 70 | (ov_qc_anshost ? adns_qf_quoteok_anshost : 0) | |
| 71 | (ov_qc_cname ? 0 : adns_qf_quoteok_cname) | |
| 72 | ov_cname, |
| 73 | qun, |
| 74 | &qun->qu); |
| 75 | if (r) sysfail("adns_submit",r); |
| 76 | |
| 77 | DLIST_LINK_TAIL(outstanding,qun); |
| 78 | } |