OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [newlib-1.18.0/] [newlib/] [libc/] [sys/] [linux/] [net/] [res_init.c] - Blame information for rev 829

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
2
 * Copyright (c) 1985, 1989, 1993
3
 *    The Regents of the University of California.  All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 * 4. Neither the name of the University nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29
 
30
/*
31
 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
32
 *
33
 * Permission to use, copy, modify, and distribute this software for any
34
 * purpose with or without fee is hereby granted, provided that the above
35
 * copyright notice and this permission notice appear in all copies, and that
36
 * the name of Digital Equipment Corporation not be used in advertising or
37
 * publicity pertaining to distribution of the document or software without
38
 * specific, written prior permission.
39
 *
40
 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
41
 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
42
 * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
43
 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
44
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
45
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
46
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
 * SOFTWARE.
48
 */
49
 
50
/*
51
 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
52
 *
53
 * Permission to use, copy, modify, and distribute this software for any
54
 * purpose with or without fee is hereby granted, provided that the above
55
 * copyright notice and this permission notice appear in all copies.
56
 *
57
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
58
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
59
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
60
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
61
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
62
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
63
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
64
 * SOFTWARE.
65
 */
66
 
67
#if defined(LIBC_SCCS) && !defined(lint)
68
static const char sccsid[] = "@(#)res_init.c    8.1 (Berkeley) 6/7/93";
69
static const char rcsid[] = "$BINDId: res_init.c,v 8.16 2000/05/09 07:10:12 vixie Exp $";
70
#endif /* LIBC_SCCS and not lint */
71
 
72
#include <sys/types.h>
73
#include <sys/param.h>
74
#include <sys/socket.h>
75
#include <sys/time.h>
76
 
77
#include <netinet/in.h>
78
#include <arpa/inet.h>
79
#include <arpa/nameser.h>
80
 
81
#include <ctype.h>
82
#include <stdio.h>
83
#include <stdio_ext.h>
84
#include <stdlib.h>
85
#include <string.h>
86
#include <unistd.h>
87
 
88
#include <not-cancel.h>
89
#include "local.h"
90
#include <resolv.h>
91
 
92
/* Options.  Should all be left alone. */
93
#define RESOLVSORT
94
#define RFC1535
95
/* #undef DEBUG */
96
 
97
static void res_setoptions (res_state, const char *, const char *)
98
     internal_function;
99
 
100
#ifdef RESOLVSORT
101
static const char sort_mask_chars[] = "/&";
102
#define ISSORTMASK(ch) (strchr(sort_mask_chars, ch) != NULL)
103
static u_int32_t net_mask (struct in_addr) __THROW;
104
#endif
105
 
106
#if !defined(isascii)   /* XXX - could be a function */
107
# define isascii(c) (!(c & 0200))
108
#endif
109
 
110
#ifdef _LIBC
111
unsigned long long int __res_initstamp attribute_hidden;
112
#endif
113
 
114
/*
115
 * Resolver state default settings.
116
 */
117
 
118
/*
119
 * Set up default settings.  If the configuration file exist, the values
120
 * there will have precedence.  Otherwise, the server address is set to
121
 * INADDR_ANY and the default domain name comes from the gethostname().
122
 *
123
 * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
124
 * rather than INADDR_ANY ("0.0.0.0") as the default name server address
125
 * since it was noted that INADDR_ANY actually meant ``the first interface
126
 * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
127
 * it had to be "up" in order for you to reach your own name server.  It
128
 * was later decided that since the recommended practice is to always
129
 * install local static routes through 127.0.0.1 for all your network
130
 * interfaces, that we could solve this problem without a code change.
131
 *
132
 * The configuration file should always be used, since it is the only way
133
 * to specify a default domain.  If you are running a server on your local
134
 * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
135
 * in the configuration file.
136
 *
137
 * Return 0 if completes successfully, -1 on error
138
 */
139
int
140
res_ninit(res_state statp) {
141
        extern int __res_vinit(res_state, int);
142
 
143
        return (__res_vinit(statp, 0));
144
}
145
#ifdef _LIBC
146
libc_hidden_def (__res_ninit)
147
#endif
148
 
149
/* This function has to be reachable by res_data.c but not publically. */
150
int
151
__res_vinit(res_state statp, int preinit) {
152
        register FILE *fp;
153
        register char *cp, **pp;
154
        register int n;
155
        char buf[BUFSIZ];
156
        int nserv = 0;    /* number of nameserver records read from file */
157
#ifdef _LIBC
158
        int nservall = 0; /* number of NS records read, nserv IPv4 only */
159
#endif
160
        int haveenv = 0;
161
        int havesearch = 0;
162
#ifdef RESOLVSORT
163
        int nsort = 0;
164
        char *net;
165
#endif
166
#ifndef RFC1535
167
        int dots;
168
#endif
169
#ifdef _LIBC
170
        statp->_u._ext.initstamp = __res_initstamp;
171
#endif
172
 
173
        if (!preinit) {
174
                statp->retrans = RES_TIMEOUT;
175
                statp->retry = RES_DFLRETRY;
176
                statp->options = RES_DEFAULT;
177
                statp->id = res_randomid();
178
        }
179
 
180
#ifdef USELOOPBACK
181
        statp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
182
#else
183
        statp->nsaddr.sin_addr.s_addr = INADDR_ANY;
184
#endif
185
        statp->nsaddr.sin_family = AF_INET;
186
        statp->nsaddr.sin_port = htons(NAMESERVER_PORT);
187
        statp->nscount = 1;
188
        statp->ndots = 1;
189
        statp->pfcode = 0;
190
        statp->_vcsock = -1;
191
        statp->_flags = 0;
192
        statp->qhook = NULL;
193
        statp->rhook = NULL;
194
        statp->_u._ext.nsinit = 0;
195
        statp->_u._ext.nscount = 0;
196
#ifdef _LIBC
197
        statp->_u._ext.nscount6 = 0;
198
        for (n = 0; n < MAXNS; n++) {
199
                statp->_u._ext.nsaddrs[n] = NULL;
200
                statp->_u._ext.nsmap[n] = MAXNS;
201
        }
202
#endif
203
 
204
        /* Allow user to override the local domain definition */
205
        if ((cp = getenv("LOCALDOMAIN")) != NULL) {
206
                (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
207
                statp->defdname[sizeof(statp->defdname) - 1] = '\0';
208
                haveenv++;
209
 
210
                /*
211
                 * Set search list to be blank-separated strings
212
                 * from rest of env value.  Permits users of LOCALDOMAIN
213
                 * to still have a search list, and anyone to set the
214
                 * one that they want to use as an individual (even more
215
                 * important now that the rfc1535 stuff restricts searches)
216
                 */
217
                cp = statp->defdname;
218
                pp = statp->dnsrch;
219
                *pp++ = cp;
220
                for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
221
                        if (*cp == '\n')        /* silly backwards compat */
222
                                break;
223
                        else if (*cp == ' ' || *cp == '\t') {
224
                                *cp = 0;
225
                                n = 1;
226
                        } else if (n) {
227
                                *pp++ = cp;
228
                                n = 0;
229
                                havesearch = 1;
230
                        }
231
                }
232
                /* null terminate last domain if there are excess */
233
                while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
234
                        cp++;
235
                *cp = '\0';
236
                *pp++ = 0;
237
        }
238
 
239
#define MATCH(line, name) \
240
        (!strncmp(line, name, sizeof(name) - 1) && \
241
        (line[sizeof(name) - 1] == ' ' || \
242
         line[sizeof(name) - 1] == '\t'))
243
 
244
        if ((fp = fopen(_PATH_RESCONF, "rc")) != NULL) {
245
                /* No threads use this stream.  */
246
                __fsetlocking (fp, FSETLOCKING_BYCALLER);
247
            /* read the config file */
248
            while (fgets(buf, sizeof(buf), fp) != NULL) {
249
                /* skip comments */
250
                if (*buf == ';' || *buf == '#')
251
                        continue;
252
                /* read default domain name */
253
                if (MATCH(buf, "domain")) {
254
                    if (haveenv)        /* skip if have from environ */
255
                            continue;
256
                    cp = buf + sizeof("domain") - 1;
257
                    while (*cp == ' ' || *cp == '\t')
258
                            cp++;
259
                    if ((*cp == '\0') || (*cp == '\n'))
260
                            continue;
261
                    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
262
                    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
263
                    if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL)
264
                            *cp = '\0';
265
                    havesearch = 0;
266
                    continue;
267
                }
268
                /* set search list */
269
                if (MATCH(buf, "search")) {
270
                    if (haveenv)        /* skip if have from environ */
271
                            continue;
272
                    cp = buf + sizeof("search") - 1;
273
                    while (*cp == ' ' || *cp == '\t')
274
                            cp++;
275
                    if ((*cp == '\0') || (*cp == '\n'))
276
                            continue;
277
                    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
278
                    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
279
                    if ((cp = strchr(statp->defdname, '\n')) != NULL)
280
                            *cp = '\0';
281
                    /*
282
                     * Set search list to be blank-separated strings
283
                     * on rest of line.
284
                     */
285
                    cp = statp->defdname;
286
                    pp = statp->dnsrch;
287
                    *pp++ = cp;
288
                    for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
289
                            if (*cp == ' ' || *cp == '\t') {
290
                                    *cp = 0;
291
                                    n = 1;
292
                            } else if (n) {
293
                                    *pp++ = cp;
294
                                    n = 0;
295
                            }
296
                    }
297
                    /* null terminate last domain if there are excess */
298
                    while (*cp != '\0' && *cp != ' ' && *cp != '\t')
299
                            cp++;
300
                    *cp = '\0';
301
                    *pp++ = 0;
302
                    havesearch = 1;
303
                    continue;
304
                }
305
                /* read nameservers to query */
306
#ifdef _LIBC
307
                if (MATCH(buf, "nameserver") && nservall < MAXNS) {
308
#else
309
                if (MATCH(buf, "nameserver") && nserv < MAXNS) {
310
#endif
311
                    struct in_addr a;
312
 
313
                    cp = buf + sizeof("nameserver") - 1;
314
                    while (*cp == ' ' || *cp == '\t')
315
                        cp++;
316
                    if ((*cp != '\0') && (*cp != '\n')
317
                        && inet_aton(cp, &a)) {
318
                        statp->nsaddr_list[nserv].sin_addr = a;
319
                        statp->nsaddr_list[nserv].sin_family = AF_INET;
320
                        statp->nsaddr_list[nserv].sin_port =
321
                                htons(NAMESERVER_PORT);
322
                        nserv++;
323
#ifdef _LIBC
324
                        nservall++;
325
                    } else {
326
                        struct in6_addr a6;
327
                        char *el;
328
 
329
                        if ((el = strchr(cp, '\n')) != NULL)
330
                            *el = '\0';
331
                        if ((*cp != '\0') &&
332
                            (inet_pton(AF_INET6, cp, &a6) > 0)) {
333
                            struct sockaddr_in6 *sa6;
334
 
335
                            sa6 = malloc(sizeof(*sa6));
336
                            if (sa6 != NULL) {
337
                                sa6->sin6_addr = a6;
338
                                sa6->sin6_family = AF_INET6;
339
                                sa6->sin6_port = htons(NAMESERVER_PORT);
340
                                statp->_u._ext.nsaddrs[nservall] = sa6;
341
                                statp->_u._ext.nssocks[nservall] = -1;
342
                                statp->_u._ext.nsmap[nservall] = MAXNS + 1;
343
                                nservall++;
344
                            }
345
                        }
346
#endif
347
                    }
348
                    continue;
349
                }
350
#ifdef RESOLVSORT
351
                if (MATCH(buf, "sortlist")) {
352
                    struct in_addr a;
353
 
354
                    cp = buf + sizeof("sortlist") - 1;
355
                    while (nsort < MAXRESOLVSORT) {
356
                        while (*cp == ' ' || *cp == '\t')
357
                            cp++;
358
                        if (*cp == '\0' || *cp == '\n' || *cp == ';')
359
                            break;
360
                        net = cp;
361
                        while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
362
                               isascii(*cp) && !isspace(*cp))
363
                                cp++;
364
                        n = *cp;
365
                        *cp = 0;
366
                        if (inet_aton(net, &a)) {
367
                            statp->sort_list[nsort].addr = a;
368
                            if (ISSORTMASK(n)) {
369
                                *cp++ = n;
370
                                net = cp;
371
                                while (*cp && *cp != ';' &&
372
                                        isascii(*cp) && !isspace(*cp))
373
                                    cp++;
374
                                n = *cp;
375
                                *cp = 0;
376
                                if (inet_aton(net, &a)) {
377
                                    statp->sort_list[nsort].mask = a.s_addr;
378
                                } else {
379
                                    statp->sort_list[nsort].mask =
380
                                        net_mask(statp->sort_list[nsort].addr);
381
                                }
382
                            } else {
383
                                statp->sort_list[nsort].mask =
384
                                    net_mask(statp->sort_list[nsort].addr);
385
                            }
386
                            nsort++;
387
                        }
388
                        *cp = n;
389
                    }
390
                    continue;
391
                }
392
#endif
393
                if (MATCH(buf, "options")) {
394
                    res_setoptions(statp, buf + sizeof("options") - 1, "conf");
395
                    continue;
396
                }
397
            }
398
            if (nserv > 1)
399
                statp->nscount = nserv;
400
#ifdef _LIBC
401
            if (nservall - nserv > 0)
402
                statp->_u._ext.nscount6 = nservall - nserv;
403
#endif
404
#ifdef RESOLVSORT
405
            statp->nsort = nsort;
406
#endif
407
            (void) fclose(fp);
408
        }
409
        if (statp->defdname[0] == 0 &&
410
            __gethostname(buf, sizeof(statp->defdname) - 1) == 0 &&
411
            (cp = strchr(buf, '.')) != NULL)
412
                strcpy(statp->defdname, cp + 1);
413
 
414
        /* find components of local domain that might be searched */
415
        if (havesearch == 0) {
416
                pp = statp->dnsrch;
417
                *pp++ = statp->defdname;
418
                *pp = NULL;
419
 
420
#ifndef RFC1535
421
                dots = 0;
422
                for (cp = statp->defdname; *cp; cp++)
423
                        dots += (*cp == '.');
424
 
425
                cp = statp->defdname;
426
                while (pp < statp->dnsrch + MAXDFLSRCH) {
427
                        if (dots < LOCALDOMAINPARTS)
428
                                break;
429
                        cp = memchr(cp, '.') + 1;    /* we know there is one */
430
                        *pp++ = cp;
431
                        dots--;
432
                }
433
                *pp = NULL;
434
#ifdef DEBUG
435
                if (statp->options & RES_DEBUG) {
436
                        printf(";; res_init()... default dnsrch list:\n");
437
                        for (pp = statp->dnsrch; *pp; pp++)
438
                                printf(";;\t%s\n", *pp);
439
                        printf(";;\t..END..\n");
440
                }
441
#endif
442
#endif /* !RFC1535 */
443
        }
444
 
445
        if ((cp = getenv("RES_OPTIONS")) != NULL)
446
                res_setoptions(statp, cp, "env");
447
        statp->options |= RES_INIT;
448
        return (0);
449
}
450
 
451
static void
452
internal_function
453
res_setoptions(res_state statp, const char *options, const char *source) {
454
        const char *cp = options;
455
        int i;
456
 
457
#ifdef DEBUG
458
        if (statp->options & RES_DEBUG)
459
                printf(";; res_setoptions(\"%s\", \"%s\")...\n",
460
                       options, source);
461
#endif
462
        while (*cp) {
463
                /* skip leading and inner runs of spaces */
464
                while (*cp == ' ' || *cp == '\t')
465
                        cp++;
466
                /* search for and process individual options */
467
                if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
468
                        i = atoi(cp + sizeof("ndots:") - 1);
469
                        if (i <= RES_MAXNDOTS)
470
                                statp->ndots = i;
471
                        else
472
                                statp->ndots = RES_MAXNDOTS;
473
#ifdef DEBUG
474
                        if (statp->options & RES_DEBUG)
475
                                printf(";;\tndots=%d\n", statp->ndots);
476
#endif
477
                } else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) {
478
                        i = atoi(cp + sizeof("timeout:") - 1);
479
                        if (i <= RES_MAXRETRANS)
480
                                statp->retrans = i;
481
                        else
482
                                statp->retrans = RES_MAXRETRANS;
483
                } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
484
                        i = atoi(cp + sizeof("attempts:") - 1);
485
                        if (i <= RES_MAXRETRY)
486
                                statp->retry = i;
487
                        else
488
                                statp->retry = RES_MAXRETRY;
489
                } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
490
#ifdef DEBUG
491
                        if (!(statp->options & RES_DEBUG)) {
492
                                printf(";; res_setoptions(\"%s\", \"%s\")..\n",
493
                                       options, source);
494
                                statp->options |= RES_DEBUG;
495
                        }
496
                        printf(";;\tdebug\n");
497
#endif
498
                } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
499
                        statp->options |= RES_USE_INET6;
500
                } else if (!strncmp(cp, "ip6-bytestring",
501
                                    sizeof("ip6-bytestring") - 1)) {
502
                        statp->options |= RES_USEBSTRING;
503
                } else if (!strncmp(cp, "no-ip6-dotint",
504
                                    sizeof("no-ip6-dotint") - 1)) {
505
                        statp->options |= RES_NOIP6DOTINT;
506
                } else if (!strncmp(cp, "ip6-dotint",
507
                                    sizeof("ip6-dotint") - 1)) {
508
                        statp->options &= ~RES_NOIP6DOTINT;
509
                } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
510
                        statp->options |= RES_ROTATE;
511
                } else if (!strncmp(cp, "no-check-names",
512
                                    sizeof("no-check-names") - 1)) {
513
                        statp->options |= RES_NOCHECKNAME;
514
                } else {
515
                        /* XXX - print a warning here? */
516
                }
517
                /* skip to next run of spaces */
518
                while (*cp && *cp != ' ' && *cp != '\t')
519
                        cp++;
520
        }
521
}
522
 
523
#ifdef RESOLVSORT
524
/* XXX - should really support CIDR which means explicit masks always. */
525
static u_int32_t
526
net_mask(in)            /* XXX - should really use system's version of this */
527
        struct in_addr in;
528
{
529
        register u_int32_t i = ntohl(in.s_addr);
530
 
531
        if (IN_CLASSA(i))
532
                return (htonl(IN_CLASSA_NET));
533
        else if (IN_CLASSB(i))
534
                return (htonl(IN_CLASSB_NET));
535
        return (htonl(IN_CLASSC_NET));
536
}
537
#endif
538
 
539
u_int
540
res_randomid(void) {
541
        struct timeval now;
542
 
543
        gettimeofday(&now, NULL);
544
        return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
545
}
546
#ifdef _LIBC
547
libc_hidden_def (__res_randomid)
548
#endif
549
 
550
 
551
/*
552
 * This routine is for closing the socket if a virtual circuit is used and
553
 * the program wants to close it.  This provides support for endhostent()
554
 * which expects to close the socket.
555
 *
556
 * This routine is not expected to be user visible.
557
 */
558
void
559
res_nclose(res_state statp) {
560
        int ns;
561
 
562
        if (statp->_vcsock >= 0) {
563
                close_not_cancel_no_status(statp->_vcsock);
564
                statp->_vcsock = -1;
565
                statp->_flags &= ~(RES_F_VC | RES_F_CONN);
566
        }
567
#ifdef _LIBC
568
        for (ns = 0; ns < MAXNS; ns++)
569
#else
570
        for (ns = 0; ns < statp->_u._ext.nscount; ns++)
571
#endif
572
                if (statp->_u._ext.nsaddrs[ns]
573
                    && statp->_u._ext.nssocks[ns] != -1) {
574
                        close_not_cancel_no_status(statp->_u._ext.nssocks[ns]);
575
                        statp->_u._ext.nssocks[ns] = -1;
576
                }
577
        statp->_u._ext.nsinit = 0;
578
}
579
#ifdef _LIBC
580
libc_hidden_def (__res_nclose)
581
#endif
582
 
583
#ifdef _LIBC
584
# ifdef _LIBC_REENTRANT
585
/* This is called when a thread is exiting to free resources held in _res.  */
586
static void __attribute__ ((section ("__libc_thread_freeres_fn")))
587
res_thread_freeres (void)
588
{
589
  if (_res.nscount == 0)
590
    /* Never called res_ninit.  */
591
    return;
592
 
593
  __res_nclose (&_res);         /* Close any VC sockets.  */
594
 
595
  for (int ns = 0; ns < MAXNS; ns++)
596
    if (_res._u._ext.nsaddrs[ns] != NULL)
597
      {
598
        free (_res._u._ext.nsaddrs[ns]);
599
        _res._u._ext.nsaddrs[ns] = NULL;
600
      }
601
 
602
  /* Make sure we do a full re-initialization the next time.  */
603
  _res.options = 0;
604
}
605
text_set_element (__libc_thread_subfreeres, res_thread_freeres);
606
text_set_element (__libc_subfreeres, res_thread_freeres);
607
# endif
608
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.