1 // -*-c++-*- 2 /* $Id$ */ 3 4 /* 5 * 6 * Copyright (C) 1998-2003 David Mazieres (dm@uun.org) 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License as 10 * published by the Free Software Foundation; either version 2, or (at 11 * your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 21 * USA 22 * 23 */ 24 25 26 #ifndef _DNS_H_ 27 #define _DNS_H_ 1 28 29 #include "async.h" 30 31 extern "C" { 32 #define class rr_class 33 #if HAVE_ARPA_NAMESER_COMPAT_H 34 #include <arpa/nameser_compat.h> 35 #include <arpa/nameser.h> 36 #else /* !HAVE_ARPA_NAMESER_COMPAT_H */ 37 #include <arpa/nameser.h> 38 #endif /* !HAVE_ARPA_NAMESER_COMPAT_H */ 39 #undef class 40 #include <resolv.h> 41 42 /* Declarations missing on some OS's */ 43 #ifdef NEED_RES_INIT_DECL 44 void res_init (); 45 #endif /* NEED_RES_INIT_DECL */ 46 #ifdef NEED_RES_MKQUERY_DECL 47 int res_mkquery (int, const char *, int, int, 48 const u_char *, int, const u_char *, 49 u_char *, int); 50 #endif /* NEED_RES_MKQUERY_DECL */ 51 } 52 53 struct addrhint { 54 char *h_name; 55 int h_addrtype; 56 int h_length; 57 char h_address[16]; 58 }; 59 60 // struct hostent; 61 62 struct mxrec { 63 u_int16_t pref; 64 char *name; 65 }; 66 struct mxlist { 67 char *m_name; /* Name of host for which MX list taken */ 68 struct addrhint **m_hints; 69 u_short m_nmx; /* Number of mx records */ 70 struct mxrec m_mxes[1]; /* MX records */ 71 }; 72 73 struct srvrec { 74 u_int16_t prio; 75 u_int16_t weight; 76 u_int16_t port; 77 char *name; 78 }; 79 struct srvlist { 80 char *s_name; 81 struct addrhint **s_hints; 82 u_short s_nsrv; 83 struct srvrec s_srvs[1]; 84 }; 85 86 struct txtlist { 87 char *t_name; 88 u_short t_ntxt; 89 char *t_txts[1]; 90 }; 91 92 /* Extender error types for ar_errno */ 93 #define ARERR_NXREC 0x101 /* No records of appropriate type */ 94 #define ARERR_TIMEOUT 0x102 /* Query timed out */ 95 #define ARERR_PTRSPOOF 0x103 /* PTR response was a lie! */ 96 #define ARERR_BADRESP 0x104 /* Nameserver replied with malformed packet */ 97 #define ARERR_CANTSEND 0x105 /* Can't send to name server */ 98 #define ARERR_REQINVAL 0x106 /* Request was for malformed domain name */ 99 #define ARERR_CNAMELOOP 0x107 /* CNAME records form loop */ 100 101 typedef struct dnsreq dnsreq_t; 102 void dnsreq_cancel (dnsreq_t *rqp); 103 104 typedef callback<void, ptr<hostent>, int>::ref cbhent; 105 dnsreq_t *dns_hostbyname (str, cbhent, 106 bool search = false, bool addrok = true); 107 dnsreq_t *dns_hostbyaddr (const in_addr, cbhent); 108 109 typedef callback<void, ptr<mxlist>, int>::ref cbmxlist; 110 dnsreq_t *dns_mxbyname (str, cbmxlist, bool search = false); 111 112 typedef callback<void, ptr<srvlist>, int>::ref cbsrvlist; 113 dnsreq_t *dns_srvbyname (str name, cbsrvlist, bool search = false); 114 115 typedef callback<void, ptr<txtlist>, int>::ref cbtxtlist; 116 dnsreq_t *dns_txtbyname (str name, cbtxtlist cb, bool search = false); 117 118 inline dnsreq_t * 119 dns_srvbyname (const char *name, const char *proto, const char *srv, 120 cbsrvlist cb, bool search = false) 121 { 122 return dns_srvbyname (strbuf ("_%s._%s.%s", srv, proto, name), cb, search); 123 } 124 125 const char *dns_strerror (int); 126 int dns_tmperr (int); 127 128 void printaddrs (const char *, ptr<hostent>, int = 0); 129 void printmxlist (const char *, ptr<mxlist>, int = 0); 130 void printsrvlist (const char *msg, ptr<srvlist> s, int = 0); 131 void printtxtlist (const char *msg, ptr<txtlist> s, int = 0); 132 133 void dns_reload (); 134 135 #endif /* !_DNS_H_ */ 136 137