2 * Copyright (C) 2008 The Android Open Source Project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * This version of this file is derived from Android 2.3 "Gingerbread",
31 * which contains uncredited changes by Android/Google developers. It has
32 * been modified in 2011 for use in the Android build of Mozilla Firefox by
33 * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>,
34 * and Steve Workman <sjhworkman@gmail.com>).
35 * These changes are offered under the same license as the original NetBSD
36 * file, whose copyright and license are unchanged above.
40 * This version of this file is derived from Android 2.3 "Gingerbread",
41 * which contains uncredited changes by Android/Google developers. It has
42 * been modified in 2011 for use in the Android build of Mozilla Firefox by
43 * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>,
44 * and Steve Workman <sjhworkman@gmail.com>).
45 * These changes are offered under the same license as the original NetBSD
46 * file, whose copyright and license are unchanged above.
49 #define ANDROID_CHANGES 1
50 #define MOZILLA_NECKO_EXCLUDE_CODE 1
52 #include <sys/cdefs.h>
53 #include <sys/types.h>
54 #include <arpa/inet.h>
55 #include "arpa_nameser.h"
57 #include "resolv_private.h"
58 #include "resolv_cache.h"
62 #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
63 #include <sys/_system_properties.h>
65 static pthread_key_t _res_key
;
66 static pthread_once_t _res_once
;
70 struct __res_state _nres
[1];
72 struct prop_info
* _pi
;
73 struct res_static _rstatic
[1];
77 _res_thread_alloc(void)
79 _res_thread
* rt
= malloc(sizeof(*rt
));
83 /* Special system property which tracks any changes to 'net.*'. */
85 rt
->_pi
= (struct prop_info
*) __system_property_find("net.change");
87 rt
->_serial
= rt
->_pi
->serial
;
89 if ( res_ninit( rt
->_nres
) < 0 ) {
93 memset(rt
->_rstatic
, 0, sizeof rt
->_rstatic
);
100 _res_static_done( res_static rs
)
102 /* fortunately, there is nothing to do here, since the
103 * points in h_addr_ptrs and host_aliases should all
106 if (rs
->hostf
) { /* should not happen in theory, but just be safe */
110 free(rs
->servent
.s_aliases
);
114 _res_thread_free( void* _rt
)
116 _res_thread
* rt
= _rt
;
118 _res_static_done(rt
->_rstatic
);
119 res_ndestroy(rt
->_nres
);
124 _res_init_key( void )
126 pthread_key_create( &_res_key
, _res_thread_free
);
130 _res_thread_get(void)
133 pthread_once( &_res_once
, _res_init_key
);
134 rt
= pthread_getspecific( _res_key
);
136 if ((rt
= _res_thread_alloc()) == NULL
) {
141 pthread_setspecific( _res_key
, rt
);
143 /* Check the serial value for any chanes to net.* properties. */
144 if (rt
->_pi
== NULL
) {
145 rt
->_pi
= (struct prop_info
*) __system_property_find("net.change");
147 if (rt
->_pi
== NULL
|| rt
->_serial
== rt
->_pi
->serial
) {
150 rt
->_serial
= rt
->_pi
->serial
;
151 /* Reload from system properties. */
152 if ( res_ninit( rt
->_nres
) < 0 ) {
155 pthread_setspecific( _res_key
, rt
);
157 #ifdef USE_RESOLV_CACHE
158 _resolv_cache_reset(rt
->_serial
);
163 struct __res_state _nres
;
167 __get_res_cache(void)
169 _res_thread
* rt
= _res_thread_get();
175 rt
->_cache
= _resolv_cache_create();
184 _res_thread
* rt
= _res_thread_get();
185 static int panic
= NETDB_INTERNAL
;
187 return rt
? &rt
->_h_errno
: &panic
;
191 __res_get_state(void)
193 _res_thread
* rt
= _res_thread_get();
195 return rt
? rt
->_nres
: NULL
;
199 __res_put_state(res_state res
)
206 __res_get_static(void)
208 _res_thread
* rt
= _res_thread_get();
210 return rt
? rt
->_rstatic
: NULL
;