Lines Matching refs:statp
126 int res_ninit(res_state statp) { in res_ninit() argument
127 return res_vinit(statp, 0); in res_ninit()
131 int res_vinit(res_state statp, int preinit) { in res_vinit() argument
139 if ((statp->options & RES_INIT) != 0U) res_ndestroy(statp); in res_vinit()
142 statp->netid = NETID_UNSET; in res_vinit()
143 statp->options = RES_DEFAULT; in res_vinit()
144 statp->id = arc4random_uniform(65536); in res_vinit()
145 statp->_mark = MARK_UNSET; in res_vinit()
153 statp->nscount = 0; in res_vinit()
154 statp->ndots = 1; in res_vinit()
155 statp->_vcsock = -1; in res_vinit()
156 statp->_flags = 0; in res_vinit()
157 statp->_u._ext.nscount = 0; in res_vinit()
158 statp->_u._ext.ext = (res_state_ext*) malloc(sizeof(*statp->_u._ext.ext)); in res_vinit()
159 statp->use_local_nameserver = false; in res_vinit()
160 if (statp->_u._ext.ext != NULL) { in res_vinit()
161 memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext)); in res_vinit()
162 statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr; in res_vinit()
163 strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa"); in res_vinit()
164 strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int"); in res_vinit()
166 statp->nsort = 0; in res_vinit()
167 res_setservers(statp, u, nserv); in res_vinit()
169 if (statp->defdname[0] == 0 && gethostname(buf, sizeof(statp->defdname) - 1) == 0 && in res_vinit()
171 strcpy(statp->defdname, cp + 1); in res_vinit()
175 pp = statp->dnsrch; in res_vinit()
176 *pp++ = statp->defdname; in res_vinit()
180 for (cp = statp->defdname; *cp; cp++) dots += (*cp == '.'); in res_vinit()
182 cp = statp->defdname; in res_vinit()
183 while (pp < statp->dnsrch + MAXDFLSRCH) { in res_vinit()
191 for (pp = statp->dnsrch; *pp; pp++) LOG(DEBUG) << "\t" << *pp; in res_vinit()
194 if ((cp = getenv("RES_OPTIONS")) != NULL) res_setoptions(statp, cp, "env"); in res_vinit()
196 statp->nscount = nserv; in res_vinit()
197 statp->options |= RES_INIT; in res_vinit()
202 static void res_setoptions(res_state statp, const char* options, const char* source) { in res_setoptions() argument
205 res_state_ext* ext = statp->_u._ext.ext; in res_setoptions()
216 statp->ndots = i; in res_setoptions()
218 statp->ndots = RES_MAXNDOTS; in res_setoptions()
219 LOG(DEBUG) << "\tndots=" << statp->ndots; in res_setoptions()
222 if (!(statp->options & RES_DEBUG)) { in res_setoptions()
224 statp->options |= RES_DEBUG; in res_setoptions()
230 statp->options |= RES_NOTLDQUERY; in res_setoptions()
232 statp->options |= RES_USE_INET6; in res_setoptions()
234 statp->options |= RES_ROTATE; in res_setoptions()
236 statp->options |= RES_NOCHECKNAME; in res_setoptions()
239 statp->options |= RES_USE_EDNS0; in res_setoptions()
242 statp->options |= RES_USE_DNAME; in res_setoptions()
259 statp->options |= RES_NO_NIBBLE2; in res_setoptions()
261 statp->options &= ~RES_NO_NIBBLE2; in res_setoptions()
279 void res_nclose(res_state statp) { in res_nclose() argument
282 if (statp->_vcsock >= 0) { in res_nclose()
283 (void) close(statp->_vcsock); in res_nclose()
284 statp->_vcsock = -1; in res_nclose()
285 statp->_flags &= ~RES_F_VC; in res_nclose()
287 for (ns = 0; ns < statp->_u._ext.nscount; ns++) { in res_nclose()
288 if (statp->_u._ext.nssocks[ns] != -1) { in res_nclose()
289 (void) close(statp->_u._ext.nssocks[ns]); in res_nclose()
290 statp->_u._ext.nssocks[ns] = -1; in res_nclose()
295 void res_ndestroy(res_state statp) { in res_ndestroy() argument
296 res_nclose(statp); in res_ndestroy()
297 if (statp->_u._ext.ext != NULL) free(statp->_u._ext.ext); in res_ndestroy()
298 statp->options &= ~RES_INIT; in res_ndestroy()
299 statp->_u._ext.ext = NULL; in res_ndestroy()
302 void res_setservers(res_state statp, const sockaddr_union* set, int cnt) { in res_setservers() argument
307 res_nclose(statp); in res_setservers()
310 statp->_u._ext.nscount = 0; in res_setservers()
317 if (statp->_u._ext.ext) in res_setservers()
318 memcpy(&statp->_u._ext.ext->nsaddrs[nserv], &set->sin, size); in res_setservers()
319 if (size <= sizeof(statp->nsaddr_list[nserv])) in res_setservers()
320 memcpy(&statp->nsaddr_list[nserv], &set->sin, size); in res_setservers()
322 statp->nsaddr_list[nserv].sin_family = 0; in res_setservers()
329 if (statp->_u._ext.ext) in res_setservers()
330 memcpy(&statp->_u._ext.ext->nsaddrs[nserv], &set->sin6, size); in res_setservers()
331 if (size <= sizeof(statp->nsaddr_list[nserv])) in res_setservers()
332 memcpy(&statp->nsaddr_list[nserv], &set->sin6, size); in res_setservers()
334 statp->nsaddr_list[nserv].sin_family = 0; in res_setservers()
344 statp->nscount = nserv; in res_setservers()
347 int res_getservers(res_state statp, sockaddr_union* set, int cnt) { in res_getservers() argument
352 for (i = 0; i < statp->nscount && i < cnt; i++) { in res_getservers()
353 if (statp->_u._ext.ext) in res_getservers()
354 family = statp->_u._ext.ext->nsaddrs[i].sin.sin_family; in res_getservers()
356 family = statp->nsaddr_list[i].sin_family; in res_getservers()
361 if (statp->_u._ext.ext) in res_getservers()
362 memcpy(&set->sin, &statp->_u._ext.ext->nsaddrs[i], size); in res_getservers()
364 memcpy(&set->sin, &statp->nsaddr_list[i], size); in res_getservers()
370 if (statp->_u._ext.ext) in res_getservers()
371 memcpy(&set->sin6, &statp->_u._ext.ext->nsaddrs[i], size); in res_getservers()
373 memcpy(&set->sin6, &statp->nsaddr_list[i], size); in res_getservers()
383 return (statp->nscount); in res_getservers()
386 void res_setnetcontext(res_state statp, const struct android_net_context* netcontext) { in res_setnetcontext() argument
387 if (statp != NULL) { in res_setnetcontext()
388 statp->netid = netcontext->dns_netid; in res_setnetcontext()
389 statp->_mark = netcontext->dns_mark; in res_setnetcontext()
391 statp->options |= RES_USE_EDNS0 | RES_USE_DNSSEC; in res_setnetcontext()
394 statp->use_local_nameserver = true; in res_setnetcontext()