~andreserl/ubuntu/lucid/bind9/bind9-apport-533601

« back to all changes in this revision

Viewing changes to lib/bind/resolv/res_send.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones, LaMont Jones, Internet Software Consortium, Inc, localization folks
  • Date: 2008-08-02 14:20:20 UTC
  • mfrom: (1.2.1 upstream) (6.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080802142020-l1hon9jy8lbbjxmg
[LaMont Jones]

* default to using resolvconf if it is installed
* fix sonames and dependencies.  Closes: #149259, #492418
* Do not build-depend libcap2-dev on non-linux.  Closes: #493392
* drop unused query-loc manpage.  Closes: #492564
* lwresd: Deliver /etc/bind directory.  Closes: #490027
* fix query-source comment in default install

[Internet Software Consortium, Inc]

* 9.5.0-P2.  Closes: #492949

[localization folks]

* l10n: Spanish debconf translation.  Closes: #492425 (Ignacio Mondino)
* l10n: Swedish debconf templates.  Closes: #491369 (Martin Ågren)
* l10n: Japanese debconf translations.  Closes: #492048 (Hideki Yamane
  (Debian-JP))
* l10n: Finnish translation.  Closes: #490630 (Esko Arajärvi)
* l10n: Italian debconf translations.  Closes: #492587 (Alessandro Vietta)

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
 
71
71
#if defined(LIBC_SCCS) && !defined(lint)
72
72
static const char sccsid[] = "@(#)res_send.c    8.1 (Berkeley) 6/4/93";
73
 
static const char rcsid[] = "$Id: res_send.c,v 1.5.2.2.4.7 2005/08/15 02:04:41 marka Exp $";
 
73
static const char rcsid[] = "$Id: res_send.c,v 1.18.10.1 2008/01/27 02:06:46 marka Exp $";
74
74
#endif /* LIBC_SCCS and not lint */
75
75
 
76
 
/*
 
76
/*! \file
 
77
 * \brief
77
78
 * Send query to name server and wait for reply.
78
79
 */
79
80
 
130
131
static int              send_vc(res_state, const u_char *, int,
131
132
                                u_char *, int, int *, int);
132
133
static int              send_dg(res_state, const u_char *, int,
133
 
                                u_char *, int, int *, int,
 
134
                                u_char *, int, int *, int, int,
134
135
                                int *, int *);
135
136
static void             Aerror(const res_state, FILE *, const char *, int,
136
137
                               const struct sockaddr *, int);
147
148
 
148
149
/* Public. */
149
150
 
150
 
/* int
151
 
 * res_isourserver(ina)
 
151
/*%
152
152
 *      looks up "ina" in _res.ns_addr_list[]
 
153
 *
153
154
 * returns:
154
 
 *      0  : not found
155
 
 *      >0 : found
 
155
 *\li   0  : not found
 
156
 *\li   >0 : found
 
157
 *
156
158
 * author:
157
 
 *      paul vixie, 29may94
 
159
 *\li   paul vixie, 29may94
158
160
 */
159
161
int
160
162
res_ourserver_p(const res_state statp, const struct sockaddr *sa) {
197
199
        return (0);
198
200
}
199
201
 
200
 
/* int
201
 
 * res_nameinquery(name, type, class, buf, eom)
 
202
/*%
202
203
 *      look for (name,type,class) in the query section of packet (buf,eom)
 
204
 *
203
205
 * requires:
204
 
 *      buf + HFIXEDSZ <= eom
 
206
 *\li   buf + HFIXEDSZ <= eom
 
207
 *
205
208
 * returns:
206
 
 *      -1 : format error
207
 
 *      0  : not found
208
 
 *      >0 : found
 
209
 *\li   -1 : format error
 
210
 *\li   0  : not found
 
211
 *\li   >0 : found
 
212
 *
209
213
 * author:
210
 
 *      paul vixie, 29may94
 
214
 *\li   paul vixie, 29may94
211
215
 */
212
216
int
213
217
res_nameinquery(const char *name, int type, int class,
235
239
        return (0);
236
240
}
237
241
 
238
 
/* int
239
 
 * res_queriesmatch(buf1, eom1, buf2, eom2)
 
242
/*%
240
243
 *      is there a 1:1 mapping of (name,type,class)
241
244
 *      in (buf1,eom1) and (buf2,eom2)?
 
245
 *
242
246
 * returns:
243
 
 *      -1 : format error
244
 
 *      0  : not a 1:1 mapping
245
 
 *      >0 : is a 1:1 mapping
 
247
 *\li   -1 : format error
 
248
 *\li   0  : not a 1:1 mapping
 
249
 *\li   >0 : is a 1:1 mapping
 
250
 *
246
251
 * author:
247
 
 *      paul vixie, 29may94
 
252
 *\li   paul vixie, 29may94
248
253
 */
249
254
int
250
255
res_queriesmatch(const u_char *buf1, const u_char *eom1,
288
293
res_nsend(res_state statp,
289
294
          const u_char *buf, int buflen, u_char *ans, int anssiz)
290
295
{
291
 
        int gotsomewhere, terrno, try, v_circuit, resplen, ns, n;
 
296
        int gotsomewhere, terrno, tries, v_circuit, resplen, ns, n;
292
297
        char abuf[NI_MAXHOST];
293
298
 
294
299
#ifdef USE_POLL
295
300
        highestFD = sysconf(_SC_OPEN_MAX) - 1;
296
301
#endif
297
302
 
298
 
        if (statp->nscount == 0) {
 
303
        /* No name servers or res_init() failure */
 
304
        if (statp->nscount == 0 || EXT(statp).ext == NULL) {
299
305
                errno = ESRCH;
300
306
                return (-1);
301
307
        }
399
405
        /*
400
406
         * Send request, RETRY times, or until successful.
401
407
         */
402
 
        for (try = 0; try < statp->retry; try++) {
 
408
        for (tries = 0; tries < statp->retry; tries++) {
403
409
            for (ns = 0; ns < statp->nscount; ns++) {
404
410
                struct sockaddr *nsap;
405
411
                int nsaplen;
447
453
 
448
454
                if (v_circuit) {
449
455
                        /* Use VC; at most one attempt per server. */
450
 
                        try = statp->retry;
 
456
                        tries = statp->retry;
451
457
                        n = send_vc(statp, buf, buflen, ans, anssiz, &terrno,
452
458
                                    ns);
453
459
                        if (n < 0)
458
464
                } else {
459
465
                        /* Use datagrams. */
460
466
                        n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,
461
 
                                    ns, &v_circuit, &gotsomewhere);
 
467
                                    ns, tries, &v_circuit, &gotsomewhere);
462
468
                        if (n < 0)
463
469
                                goto fail;
464
470
                        if (n == 0)
523
529
        res_nclose(statp);
524
530
        if (!v_circuit) {
525
531
                if (!gotsomewhere)
526
 
                        errno = ECONNREFUSED;   /* no nameservers found */
 
532
                        errno = ECONNREFUSED;   /*%< no nameservers found */
527
533
                else
528
 
                        errno = ETIMEDOUT;      /* no answer obtained */
 
534
                        errno = ETIMEDOUT;      /*%< no answer obtained */
529
535
        } else
530
536
                errno = terrno;
531
537
        return (-1);
552
558
        else if (sa->sa_family == AF_INET6)
553
559
                return (sizeof(struct sockaddr_in6));
554
560
        else
555
 
                return (0);     /* unknown, die on connect */
 
561
                return (0);     /*%< unknown, die on connect */
556
562
}
557
563
 
558
 
/*
 
564
/*%
559
565
 * pick appropriate nsaddr_list for use.  see res_init() for initialization.
560
566
 */
561
567
static struct sockaddr *
595
601
        u_short len;
596
602
        u_char *cp;
597
603
        void *tmp;
 
604
#ifdef SO_NOSIGPIPE
 
605
        int on = 1;
 
606
#endif
598
607
 
599
608
        nsap = get_nsaddr(statp, ns);
600
609
        nsaplen = get_salen(nsap);
640
649
                                return (-1);
641
650
                        }
642
651
                }
 
652
#ifdef SO_NOSIGPIPE
 
653
                /*
 
654
                 * Disable generation of SIGPIPE when writing to a closed
 
655
                 * socket.  Write should return -1 and set errno to EPIPE
 
656
                 * instead. 
 
657
                 *
 
658
                 * Push on even if setsockopt(SO_NOSIGPIPE) fails.
 
659
                 */
 
660
                (void)setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on,
 
661
                                 sizeof(on));
 
662
#endif
643
663
                errno = 0;
644
664
                if (connect(statp->_vcsock, nsap, nsaplen) < 0) {
645
665
                        *terrno = errno;
766
786
}
767
787
 
768
788
static int
769
 
send_dg(res_state statp,
770
 
        const u_char *buf, int buflen, u_char *ans, int anssiz,
771
 
        int *terrno, int ns, int *v_circuit, int *gotsomewhere)
 
789
send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans,
 
790
        int anssiz, int *terrno, int ns, int tries, int *v_circuit,
 
791
        int *gotsomewhere)
772
792
{
773
793
        const HEADER *hp = (const HEADER *) buf;
774
794
        HEADER *anhp = (HEADER *) ans;
849
869
        /*
850
870
         * Wait for reply.
851
871
         */
852
 
        seconds = (statp->retrans << ns);
 
872
        seconds = (statp->retrans << tries);
853
873
        if (ns > 0)
854
874
                seconds /= statp->nscount;
855
875
        if (seconds <= 0)