]> git.ipfire.org Git - thirdparty/glibc.git/blame - resolv/res_libc.c
Update.
[thirdparty/glibc.git] / resolv / res_libc.c
CommitLineData
b43b13ac
UD
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
b43b13ac 18#include <sys/types.h>
b43b13ac 19#include <netinet/in.h>
b43b13ac 20#include <arpa/nameser.h>
b43b13ac 21#include <resolv.h>
b43b13ac 22
b43b13ac 23
e685e07d
UD
24/* The following bit is copied from res_data.c (where it is #ifdef'ed
25 out) since res_init() should go into libc.so but the rest of that
26 file should not. */
b43b13ac
UD
27
28int
29res_init(void) {
30 extern int __res_vinit(res_state, int);
31
32 /*
33 * These three fields used to be statically initialized. This made
34 * it hard to use this code in a shared library. It is necessary,
35 * now that we're doing dynamic initialization here, that we preserve
36 * the old semantics: if an application modifies one of these three
37 * fields of _res before res_init() is called, res_init() will not
38 * alter them. Of course, if an application is setting them to
39 * _zero_ before calling res_init(), hoping to override what used
40 * to be the static default, we can't detect it and unexpected results
41 * will follow. Zero for any of these fields would make no sense,
42 * so one can safely assume that the applications were already getting
43 * unexpected results.
44 *
45 * _res.options is tricky since some apps were known to diddle the bits
46 * before res_init() was first called. We can't replicate that semantic
47 * with dynamic initialization (they may have turned bits off that are
48 * set in RES_DEFAULT). Our solution is to declare such applications
49 * "broken". They could fool us by setting RES_INIT but none do (yet).
50 */
51 if (!_res.retrans)
52 _res.retrans = RES_TIMEOUT;
53 if (!_res.retry)
54 _res.retry = 4;
55 if (!(_res.options & RES_INIT))
56 _res.options = RES_DEFAULT;
2ed2dc18
UD
57 else if (_res.nscount > 0) {
58 __res_nclose (&_res); /* Close any VC sockets. */
59
60 for (int ns = 0; ns < MAXNS; ns++) {
61 free (_res._u._ext.nsaddrs[ns]);
62 _res._u._ext.nsaddrs[ns] = NULL;
63 }
64 }
b43b13ac
UD
65
66 /*
67 * This one used to initialize implicitly to zero, so unless the app
68 * has set it to something in particular, we can randomize it now.
69 */
70 if (!_res.id)
71 _res.id = res_randomid();
72
73 return (__res_vinit(&_res, 1));
74}
e685e07d 75\f
4aeb650e
RM
76/* This needs to be after the use of _res in res_init, above. */
77#undef _res
78
1f503475
UD
79/* The resolver state for use by single-threaded programs.
80 This differs from plain `struct __res_state _res;' in that it doesn't
81 create a common definition, but a plain symbol that resides in .bss,
82 which can have an alias. */
83struct __res_state _res __attribute__((section (".bss")));
4aeb650e 84
0e9d6240
UD
85#include <tls.h>
86
87#if USE___THREAD
88#undef __resp
89__thread struct __res_state *__resp = &_res;
90extern __thread struct __res_state *__libc_resp
91 __attribute__ ((alias ("__resp"))) attribute_hidden;
92#endif
93
4aeb650e
RM
94/* We declare this with compat_symbol so that it's not
95 visible at link time. Programs must use the accessor functions. */
0e9d6240
UD
96#if defined HAVE_ELF && defined SHARED && defined DO_VERSIONING
97# include <shlib-compat.h>
4aeb650e 98compat_symbol (libc, _res, _res, GLIBC_2_0);
4aeb650e 99#endif
b43b13ac 100
e685e07d 101#include <shlib-compat.h>
66ac0abe 102
e685e07d
UD
103#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_2)
104# undef res_init
1cb990bc 105extern int __res_init_weak (void);
0e3af135 106weak_extern (__res_init_weak);
1cb990bc 107strong_alias (__res_init, __res_init_weak);
0e3af135 108compat_symbol (libc, __res_init_weak, res_init, GLIBC_2_0);
e685e07d 109#endif