]> git.ipfire.org Git - thirdparty/glibc.git/blob - resolv/res_libc.c
2002-10-16 Jakub Jelinek <jakub@redhat.com>
[thirdparty/glibc.git] / resolv / res_libc.c
1 /*
2 * Copyright (c) 1995-1999 by Internet Software Consortium.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
9 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
10 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
11 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
13 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
14 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
15 * SOFTWARE.
16 */
17
18 #include <sys/types.h>
19 #include <netinet/in.h>
20 #include <arpa/nameser.h>
21 #include <resolv.h>
22
23 #undef _res
24
25 #include <tls.h>
26
27 #if USE_TLS && HAVE___THREAD
28 /* With __thread support, this per-thread variable is used in all cases. */
29 __thread struct __res_state _res;
30 extern __thread struct __res_state __libc_res __attribute__ ((alias ("_res")))
31 attribute_hidden;
32 # define _res __libc_res
33 #else
34 /* The resolver state for use by single-threaded programs. */
35 struct __res_state _res;
36 #endif
37
38 /* This function is used to access the resolver state in
39 single-threaded programs. */
40 struct __res_state *
41 weak_const_function
42 __res_state (void)
43 {
44 return &_res;
45 }
46 \f
47
48 /* The following bit is copied from res_data.c (where it is #ifdef'ed
49 out) since res_init() should go into libc.so but the rest of that
50 file should not. */
51
52 int
53 res_init(void) {
54 extern int __res_vinit(res_state, int);
55
56 /*
57 * These three fields used to be statically initialized. This made
58 * it hard to use this code in a shared library. It is necessary,
59 * now that we're doing dynamic initialization here, that we preserve
60 * the old semantics: if an application modifies one of these three
61 * fields of _res before res_init() is called, res_init() will not
62 * alter them. Of course, if an application is setting them to
63 * _zero_ before calling res_init(), hoping to override what used
64 * to be the static default, we can't detect it and unexpected results
65 * will follow. Zero for any of these fields would make no sense,
66 * so one can safely assume that the applications were already getting
67 * unexpected results.
68 *
69 * _res.options is tricky since some apps were known to diddle the bits
70 * before res_init() was first called. We can't replicate that semantic
71 * with dynamic initialization (they may have turned bits off that are
72 * set in RES_DEFAULT). Our solution is to declare such applications
73 * "broken". They could fool us by setting RES_INIT but none do (yet).
74 */
75 if (!_res.retrans)
76 _res.retrans = RES_TIMEOUT;
77 if (!_res.retry)
78 _res.retry = 4;
79 if (!(_res.options & RES_INIT))
80 _res.options = RES_DEFAULT;
81
82 /*
83 * This one used to initialize implicitly to zero, so unless the app
84 * has set it to something in particular, we can randomize it now.
85 */
86 if (!_res.id)
87 _res.id = res_randomid();
88
89 return (__res_vinit(&_res, 1));
90 }
91 \f
92
93 #include <shlib-compat.h>
94
95 #if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_2)
96 # undef res_init
97 strong_alias (__res_init, __res_init_weak);
98 weak_extern (__res_init_weak);
99 compat_symbol (libc, __res_init_weak, res_init, GLIBC_2_0);
100 #endif