1RESOLVER(3) 386BSD Programmer's Manual RESOLVER(3) 2 3NNAAMMEE 4 rreess__qquueerryy, rreess__sseeaarrcchh, rreess__mmkkqquueerryy, rreess__sseenndd, rreess__iinniitt, ddnn__ccoommpp, 5 ddnn__eexxppaanndd - resolver routines 6 7SSYYNNOOPPSSIISS 8 ##iinncclluuddee <<ssyyss//ttyyppeess..hh>> 9 ##iinncclluuddee <<nneettiinneett//iinn..hh>> 10 ##iinncclluuddee <<aarrppaa//nnaammeesseerr..hh>> 11 ##iinncclluuddee <<rreessoollvv..hh>> 12 13 rreess__qquueerryy(_c_h_a_r *_d_n_a_m_e, _i_n_t _c_l_a_s_s, _i_n_t _t_y_p_e, _u__c_h_a_r *_a_n_s_w_e_r, _i_n_t _a_n_s_l_e_n) 14 15 rreess__sseeaarrcchh(_c_h_a_r *_d_n_a_m_e, _i_n_t _c_l_a_s_s, _i_n_t _t_y_p_e, _u__c_h_a_r *_a_n_s_w_e_r, _i_n_t _a_n_s_l_e_n) 16 17 rreess__mmkkqquueerryy(_i_n_t _o_p, _c_h_a_r *_d_n_a_m_e, _i_n_t _c_l_a_s_s, _i_n_t _t_y_p_e, _c_h_a_r *_d_a_t_a, 18 _i_n_t _d_a_t_a_l_e_n, _s_t_r_u_c_t _r_r_e_c *_n_e_w_r_r, _c_h_a_r *_b_u_f, _i_n_t _b_u_f_l_e_n) 19 20 rreess__sseenndd(_c_h_a_r *_m_s_g, _i_n_t _m_s_g_l_e_n, _c_h_a_r *_a_n_s_w_e_r, _i_n_t _a_n_s_l_e_n) 21 22 rreess__iinniitt() 23 24 ddnn__ccoommpp(_c_h_a_r *_e_x_p__d_n, _c_h_a_r *_c_o_m_p__d_n, _i_n_t _l_e_n_g_t_h, _c_h_a_r **_d_n_p_t_r_s, 25 _c_h_a_r **_l_a_s_t_d_n_p_t_r) 26 27 ddnn__eexxppaanndd(_u__c_h_a_r *_m_s_g, _u__c_h_a_r *_e_o_m_o_r_i_g, _u__c_h_a_r *_c_o_m_p__d_n, _u__c_h_a_r *_e_x_p__d_n, 28 _i_n_t _l_e_n_g_t_h) 29 30DDEESSCCRRIIPPTTIIOONN 31 These routines are used for making, sending and interpreting query and 32 reply messages with Internet domain name servers. 33 34 Global configuration and state information that is used by the resolver 35 routines is kept in the structure __r_e_s. Most of the values have 36 reasonable defaults and can be ignored. Options stored in __r_e_s._o_p_t_i_o_n_s 37 are defined in _r_e_s_o_l_v._h and are as follows. Options are stored as a 38 simple bit mask containing the bitwise ``or'' of the options enabled. 39 40 RES_INIT True if the initial name server address and default domain 41 name are initialized (i.e., rreess__iinniitt() has been called). 42 43 RES_DEBUG Print debugging messages. 44 45 RES_AAONLY Accept authoritative answers only. With this option, 46 rreess__sseenndd() should continue until it finds an authoritative 47 answer or finds an error. Currently this is not 48 implemented. 49 50 RES_USEVC Use TCP connections for queries instead of UDP datagrams. 51 52 RES_STAYOPEN Used with RES_USEVC to keep the TCP connection open between 53 queries. This is useful only in programs that regularly do 54 many queries. UDP should be the normal mode used. 55 56 RES_IGNTC Unused currently (ignore truncation errors, i.e., don't 57 retry with TCP). 58 59 RES_RECURSE Set the recursion-desired bit in queries. This is the 60 default. (rreess__sseenndd() does not do iterative queries and 61 expects the name server to handle recursion.) 62 63 RES_DEFNAMES If set, rreess__sseeaarrcchh() will append the default domain name to 64 single-component names (those that do not contain a dot). 65 66 This option is enabled by default. 67 68 RES_DNSRCH If this option is set, rreess__sseeaarrcchh() will search for host 69 names in the current domain and in parent domains; see 70 hostname(7). This is used by the standard host lookup 71 routine gethostbyname(3). This option is enabled by 72 default. 73 74 The rreess__iinniitt() routine reads the configuration file (if any; see 75 resolver(5)) to get the default domain name, search list and the 76 Internet address of the local name server(s). If no server is 77 configured, the host running the resolver is tried. The current domain 78 name is defined by the hostname if not specified in the configuration 79 file; it can be overridden by the environment variable LOCALDOMAIN. 80 Initialization normally occurs on the first call to one of the following 81 routines. 82 83 The rreess__qquueerryy() function provides an interface to the server query 84 mechanism. It constructs a query, sends it to the local server, awaits a 85 response, and makes preliminary checks on the reply. The query requests 86 information of the specified _t_y_p_e and _c_l_a_s_s for the specified fully- 87 qualified domain name _d_n_a_m_e. The reply message is left in the _a_n_s_w_e_r 88 buffer with length _a_n_s_l_e_n supplied by the caller. 89 90 The rreess__sseeaarrcchh() routine makes a query and awaits a response like 91 rreess__qquueerryy(), but in addition, it implements the default and search rules 92 controlled by the RES_DEFNAMES and RES_DNSRCH options. It returns the 93 first successful reply. 94 95 The remaining routines are lower-level routines used by rreess__qquueerryy(). The 96 rreess__mmkkqquueerryy() function constructs a standard query message and places it 97 in _b_u_f. It returns the size of the query, or -1 if the query is larger 98 than _b_u_f_l_e_n. The query type _o_p is usually QUERY, but can be any of the 99 query types defined in <_a_r_p_a/_n_a_m_e_s_e_r._h>. The domain name for the query is 100 given by _d_n_a_m_e. _N_e_w_r_r is currently unused but is intended for making 101 update messages. 102 103 The rreess__sseenndd() routine sends a pre-formatted query and returns an answer. 104 It will call rreess__iinniitt() if RES_INIT is not set, send the query to the 105 local name server, and handle timeouts and retries. The length of the 106 reply message is returned, or -1 if there were errors. 107 108 The ddnn__ccoommpp() function compresses the domain name _e_x_p__d_n and stores it in 109 _c_o_m_p__d_n. The size of the compressed name is returned or -1 if there were 110 errors. The size of the array pointed to by _c_o_m_p__d_n is given by _l_e_n_g_t_h. 111 The compression uses an array of pointers _d_n_p_t_r_s to previously-compressed 112 names in the current message. The first pointer points to to the 113 beginning of the message and the list ends with NULL. The limit to the 114 array is specified by _l_a_s_t_d_n_p_t_r. A side effect of ddnn__ccoommpp() is to update 115 the list of pointers for labels inserted into the message as the name is 116 compressed. If _d_n_p_t_r is NULL, names are not compressed. If _l_a_s_t_d_n_p_t_r is 117 NULL, the list of labels is not updated. 118 119 The ddnn__eexxppaanndd() entry expands the compressed domain name _c_o_m_p__d_n to a 120 full domain name The compressed name is contained in a query or reply 121 message; _m_s_g is a pointer to the beginning of the message. The 122 uncompressed name is placed in the buffer indicated by _e_x_p__d_n which is of 123 size _l_e_n_g_t_h. The size of compressed name is returned or -1 if there was 124 an error. 125 126FFIILLEESS 127 /etc/resolv.conf The configuration file see resolver(5). 128 129SSEEEE AALLSSOO 130 gethostbyname(3), named(8), resolver(5), hostname(7), 131 132 133 _R_F_C_1_0_3_2, _R_F_C_1_0_3_3, _R_F_C_1_0_3_4, _R_F_C_1_0_3_5, _R_F_C_9_7_4 134 135 _N_a_m_e _S_e_r_v_e_r _O_p_e_r_a_t_i_o_n_s _G_u_i_d_e _f_o_r _B_I_N_D. 136 137HHIISSTTOORRYY 138 The rreess__qquueerryy function appeared in 4.3BSD. 139 1404.3 Berkeley Distribution July 29, 1991 3 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199