Update.
[glibc.git] / resolv / res_libc.c
blobfc5cc691ba6d561da9b9f017a3d1d3c8e98c4e01
1 /*
2 * Copyright (c) 1995-1999 by Internet Software Consortium.
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.
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.
18 /* Define some functions that go int libc.so. */
20 #if defined(LIBC_SCCS) && !defined(lint)
21 static const char rcsid[] = "$Id$";
22 #endif /* LIBC_SCCS and not lint */
24 #include <sys/types.h>
25 #include <sys/param.h>
26 #include <sys/socket.h>
27 #include <sys/time.h>
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
31 #include <arpa/nameser.h>
33 #include <ctype.h>
34 #include <netdb.h>
35 #include <resolv.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <unistd.h>
42 /* This is the old res_init function. It has been moved from
43 res_data.c to this file since res_init should go into libc.so but
44 the rest of res_data not. */
47 int
48 res_init(void) {
49 extern int __res_vinit(res_state, int);
52 * These three fields used to be statically initialized. This made
53 * it hard to use this code in a shared library. It is necessary,
54 * now that we're doing dynamic initialization here, that we preserve
55 * the old semantics: if an application modifies one of these three
56 * fields of _res before res_init() is called, res_init() will not
57 * alter them. Of course, if an application is setting them to
58 * _zero_ before calling res_init(), hoping to override what used
59 * to be the static default, we can't detect it and unexpected results
60 * will follow. Zero for any of these fields would make no sense,
61 * so one can safely assume that the applications were already getting
62 * unexpected results.
64 * _res.options is tricky since some apps were known to diddle the bits
65 * before res_init() was first called. We can't replicate that semantic
66 * with dynamic initialization (they may have turned bits off that are
67 * set in RES_DEFAULT). Our solution is to declare such applications
68 * "broken". They could fool us by setting RES_INIT but none do (yet).
70 if (!_res.retrans)
71 _res.retrans = RES_TIMEOUT;
72 if (!_res.retry)
73 _res.retry = 4;
74 if (!(_res.options & RES_INIT))
75 _res.options = RES_DEFAULT;
78 * This one used to initialize implicitly to zero, so unless the app
79 * has set it to something in particular, we can randomize it now.
81 if (!_res.id)
82 _res.id = res_randomid();
84 return (__res_vinit(&_res, 1));
87 /* We need a resolver context - in unthreaded apps, this weak function
88 provides it. */
90 #undef _res
92 struct __res_state _res = { _sock : -1 };
95 struct __res_state *
96 weak_const_function
97 __res_state(void)
99 return &_res;