res_data.c revision 1dc9e472e19acfe6dc7f41e429236e7eef7ceda1
11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* $NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $ */ 21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") 51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (c) 1995-1999 by Internet Software Consortium. 61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Permission to use, copy, modify, and distribute this software for any 81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * purpose with or without fee is hereby granted, provided that the above 91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * copyright notice and this permission notice appear in all copies. 101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <sys/cdefs.h> 211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if defined(LIBC_SCCS) && !defined(lint) 221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef notdef 231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectstatic const char rcsid[] = "Id: res_data.c,v 1.1.206.2 2004/03/16 12:34:18 marka Exp"; 241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project__RCSID("$NetBSD: res_data.c,v 1.8 2004/06/09 18:07:03 christos Exp $"); 261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* LIBC_SCCS and not lint */ 281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <sys/types.h> 321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <sys/param.h> 331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <sys/socket.h> 341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <sys/time.h> 351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <netinet/in.h> 371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <arpa/inet.h> 381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include "arpa_nameser.h" 391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <ctype.h> 411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <netdb.h> 421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include "resolv_private.h" 431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <stdio.h> 441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <stdlib.h> 451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <string.h> 461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <unistd.h> 471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectconst char * const _res_opcodes[] = { 501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "QUERY", 511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "IQUERY", 521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "CQUERYM", 531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "CQUERYU", /* experimental */ 541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "NOTIFY", /* experimental */ 551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "UPDATE", 561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "6", 571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "7", 581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "8", 591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "9", 601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "10", 611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "11", 621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "12", 631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "13", 641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "ZONEINIT", 651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "ZONEREF", 661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}; 671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef BIND_UPDATE 691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectconst char * const _res_sectioncodes[] = { 701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "ZONE", 711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "PREREQUISITES", 721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "UPDATE", 731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project "ADDITIONAL", 741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}; 751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef __BIND_NOSTATIC 781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectextern struct __res_state _nres; 791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* Proto. */ 811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint res_ourserver_p(const res_state, const struct sockaddr *); 831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef ANDROID_CHANGES 851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint res_need_init() { 861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return ((_nres.options & RES_INIT) == 0U) || res_get_dns_changed(); 871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else 891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define res_need_init() ((_nres.options & RES_INIT) == 0U) 901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_init(void) { 941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int rv; 951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project extern int __res_vinit(res_state, int); 961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef COMPAT__RES 971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project /* 981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Compatibility with program that were accessing _res directly 991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * to set options. We keep another struct res that is the same 1001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * size as the original res structure, and then copy fields to 1011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * it so that we achieve the same initialization 1021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 1031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project extern void *__res_get_old_state(void); 1041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project extern void __res_put_old_state(void *); 1051dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project res_state ores = __res_get_old_state(); 1061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (ores->options != 0) 1081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _nres.options = ores->options; 1091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (ores->retrans != 0) 1101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _nres.retrans = ores->retrans; 1111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (ores->retry != 0) 1121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _nres.retry = ores->retry; 1131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 1141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project /* 1161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * These three fields used to be statically initialized. This made 1171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * it hard to use this code in a shared library. It is necessary, 1181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * now that we're doing dynamic initialization here, that we preserve 1191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * the old semantics: if an application modifies one of these three 1201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * fields of _res before res_init() is called, res_init() will not 1211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * alter them. Of course, if an application is setting them to 1221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * _zero_ before calling res_init(), hoping to override what used 1231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * to be the static default, we can't detect it and unexpected results 1241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * will follow. Zero for any of these fields would make no sense, 1251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * so one can safely assume that the applications were already getting 1261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * unexpected results. 1271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 1281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * _nres.options is tricky since some apps were known to diddle the bits 1291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * before res_init() was first called. We can't replicate that semantic 1301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * with dynamic initialization (they may have turned bits off that are 1311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * set in RES_DEFAULT). Our solution is to declare such applications 1321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * "broken". They could fool us by setting RES_INIT but none do (yet). 1331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 1341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (!_nres.retrans) 1351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _nres.retrans = RES_TIMEOUT; 1361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (!_nres.retry) 1371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _nres.retry = 4; 1381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (!(_nres.options & RES_INIT)) 1391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _nres.options = RES_DEFAULT; 1401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project /* 1421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * This one used to initialize implicitly to zero, so unless the app 1431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * has set it to something in particular, we can randomize it now. 1441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 1451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (!_nres.id) 1461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _nres.id = res_randomid(); 1471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project rv = __res_vinit(&_nres, 1); 1491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef COMPAT__RES 1501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project __res_put_old_state(&_nres); 1511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 1521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return rv; 1531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 1541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectvoid 1561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectp_query(const u_char *msg) { 1571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project fp_query(msg, stdout); 1581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 1591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectvoid 1611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectfp_query(const u_char *msg, FILE *file) { 1621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project fp_nquery(msg, PACKETSZ, file); 1631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 1641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectvoid 1661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectfp_nquery(const u_char *msg, int len, FILE *file) { 1671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (res_need_init() && res_init() == -1) 1681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return; 1691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project res_pquery(&_nres, msg, len, file); 1711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 1721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 1741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_mkquery(int op, /* opcode of query */ 1751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project const char *dname, /* domain name */ 1761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int class, int type, /* class and type of query */ 1771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project const u_char *data, /* resource record data */ 1781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int datalen, /* length of data */ 1791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project const u_char *newrr_in, /* new rr for modify or append */ 1801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project u_char *buf, /* buffer to put query */ 1811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int buflen) /* size of buffer */ 1821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{ 1831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (res_need_init() && res_init() == -1) { 1841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 1851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (-1); 1861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project } 1871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (res_nmkquery(&_nres, op, dname, class, type, 1881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project data, datalen, 1891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project newrr_in, buf, buflen)); 1901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 1911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 1921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef _LIBRESOLV 1931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 1941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) { 1951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (res_need_init() && res_init() == -1) { 1961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 1971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (-1); 1981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project } 1991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (res_nmkupdate(&_nres, rrecp_in, buf, buflen)); 2011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 2051dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_query(const char *name, /* domain name */ 2061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int class, int type, /* class and type of query */ 2071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project u_char *answer, /* buffer to put answer */ 2081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int anslen) /* size of answer buffer */ 2091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{ 2101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (res_need_init() && res_init() == -1) { 2111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 2121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (-1); 2131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project } 2141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (res_nquery(&_nres, name, class, type, answer, anslen)); 2151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectvoid 2181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_send_setqhook(res_send_qhook hook) { 2191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _nres.qhook = hook; 2201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectvoid 2231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_send_setrhook(res_send_rhook hook) { 2241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _nres.rhook = hook; 2251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 2281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_isourserver(const struct sockaddr_in *inp) { 2291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (res_ourserver_p(&_nres, (const struct sockaddr *)(const void *)inp)); 2301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 2331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_send(const u_char *buf, int buflen, u_char *ans, int anssiz) { 2341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (res_need_init() && res_init() == -1) { 2351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project /* errno should have been set by res_init() in this case. */ 2361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (-1); 2371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project } 2381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (res_nsend(&_nres, buf, buflen, ans, anssiz)); 2401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2421dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef _LIBRESOLV 2431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 2441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key, 2451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project u_char *ans, int anssiz) 2461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{ 2471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (res_need_init() && res_init() == -1) { 2481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project /* errno should have been set by res_init() in this case. */ 2491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (-1); 2501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project } 2511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (res_nsendsigned(&_nres, buf, buflen, key, ans, anssiz)); 2531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectvoid 2571dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_close(void) { 2581dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project res_nclose(&_nres); 2591dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2601dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef _LIBRESOLV 2621dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 2631dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_update(ns_updrec *rrecp_in) { 2641dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (res_need_init() && res_init() == -1) { 2651dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 2661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (-1); 2671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project } 2681dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (res_nupdate(&_nres, rrecp_in, NULL)); 2701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2711dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 2721dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 2741dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_search(const char *name, /* domain name */ 2751dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int class, int type, /* class and type of query */ 2761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project u_char *answer, /* buffer to put answer */ 2771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int anslen) /* size of answer */ 2781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{ 2791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (res_need_init() && res_init() == -1) { 2801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 2811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (-1); 2821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project } 2831dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (res_nsearch(&_nres, name, class, type, answer, anslen)); 2851dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 2881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_querydomain(const char *name, 2891dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project const char *domain, 2901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int class, int type, /* class and type of query */ 2911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project u_char *answer, /* buffer to put answer */ 2921dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int anslen) /* size of answer */ 2931dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{ 2941dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (res_need_init() && res_init() == -1) { 2951dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project RES_SET_H_ERRNO(&_nres, NETDB_INTERNAL); 2961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (-1); 2971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project } 2981dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2991dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (res_nquerydomain(&_nres, name, domain, 3001dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project class, type, 3011dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project answer, anslen)); 3021dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 3031dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 3041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 3051dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectres_opt(int a, u_char *b, int c, int d) 3061dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project{ 3071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return res_nopt(&_nres, a, b, c, d); 3081dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 3091dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 3101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectconst char * 3111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projecthostalias(const char *name) { 3121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return NULL; 3131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 3141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 3151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifdef ultrix 3161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint 3171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectlocal_hostname_length(const char *hostname) { 3181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project int len_host, len_domain; 3191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 3201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (!*_nres.defdname) 3211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project res_init(); 3221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project len_host = strlen(hostname); 3231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project len_domain = strlen(_nres.defdname); 3241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (len_host > len_domain && 3251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project !strcasecmp(hostname + len_host - len_domain, _nres.defdname) && 3261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project hostname[len_host - len_domain - 1] == '.') 3271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (len_host - len_domain - 1); 3281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project return (0); 3291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 3301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /*ultrix*/ 3311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 3321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif 333