res_send.c (170244) | res_send.c (186090) |
---|---|
1/* 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 --- 52 unchanged lines hidden (view full) --- 61 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 62 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 63 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 64 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 65 */ 66 67#if defined(LIBC_SCCS) && !defined(lint) 68static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; | 1/* 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 --- 52 unchanged lines hidden (view full) --- 61 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 62 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 63 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 64 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 65 */ 66 67#if defined(LIBC_SCCS) && !defined(lint) 68static const char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; |
69static const char rcsid[] = "$Id: res_send.c,v 1.9.18.8 2006/10/16 23:00:58 marka Exp $"; | 69static const char rcsid[] = "$Id: res_send.c,v 1.9.18.10 2008/01/27 02:06:26 marka Exp $"; |
70#endif /* LIBC_SCCS and not lint */ 71#include <sys/cdefs.h> | 70#endif /* LIBC_SCCS and not lint */ 71#include <sys/cdefs.h> |
72__FBSDID("$FreeBSD: head/lib/libc/resolv/res_send.c 170244 2007-06-03 17:20:27Z ume $"); | 72__FBSDID("$FreeBSD: head/lib/libc/resolv/res_send.c 186090 2008-12-14 19:39:53Z ume $"); |
73 74/*! \file 75 * \brief 76 * Send query to name server and wait for reply. 77 */ 78 79#include "port_before.h" 80#ifndef USE_KQUEUE --- 216 unchanged lines hidden (view full) --- 297 } 298 return (1); 299} 300 301int 302res_nsend(res_state statp, 303 const u_char *buf, int buflen, u_char *ans, int anssiz) 304{ | 73 74/*! \file 75 * \brief 76 * Send query to name server and wait for reply. 77 */ 78 79#include "port_before.h" 80#ifndef USE_KQUEUE --- 216 unchanged lines hidden (view full) --- 297 } 298 return (1); 299} 300 301int 302res_nsend(res_state statp, 303 const u_char *buf, int buflen, u_char *ans, int anssiz) 304{ |
305 int gotsomewhere, terrno, try, v_circuit, resplen, ns, n; | 305 int gotsomewhere, terrno, tries, v_circuit, resplen, ns, n; |
306#ifdef USE_KQUEUE 307 int kq; 308#endif 309 char abuf[NI_MAXHOST]; 310 311 /* No name servers or res_init() failure */ 312 if (statp->nscount == 0 || EXT(statp).ext == NULL) { 313 errno = ESRCH; --- 101 unchanged lines hidden (view full) --- 415 statp->nsaddr_list[lastns] = ina; 416 EXT(statp).nssocks[lastns] = fd; 417 EXT(statp).nstimes[lastns] = nstime; 418 } 419 420 /* 421 * Send request, RETRY times, or until successful. 422 */ | 306#ifdef USE_KQUEUE 307 int kq; 308#endif 309 char abuf[NI_MAXHOST]; 310 311 /* No name servers or res_init() failure */ 312 if (statp->nscount == 0 || EXT(statp).ext == NULL) { 313 errno = ESRCH; --- 101 unchanged lines hidden (view full) --- 415 statp->nsaddr_list[lastns] = ina; 416 EXT(statp).nssocks[lastns] = fd; 417 EXT(statp).nstimes[lastns] = nstime; 418 } 419 420 /* 421 * Send request, RETRY times, or until successful. 422 */ |
423 for (try = 0; try < statp->retry; try++) { | 423 for (tries = 0; tries < statp->retry; tries++) { |
424 for (ns = 0; ns < statp->nscount; ns++) { 425 struct sockaddr *nsap; 426 int nsaplen; 427 nsap = get_nsaddr(statp, ns); 428 nsaplen = get_salen(nsap); 429 statp->_flags &= ~RES_F_LASTMASK; 430 statp->_flags |= (ns << RES_F_LASTSHIFT); 431 same_ns: --- 34 unchanged lines hidden (view full) --- 466 getnameinfo(nsap, nsaplen, abuf, sizeof(abuf), 467 NULL, 0, niflags) == 0), 468 (stdout, ";; Querying server (# %d) address = %s\n", 469 ns + 1, abuf)); 470 471 472 if (v_circuit) { 473 /* Use VC; at most one attempt per server. */ | 424 for (ns = 0; ns < statp->nscount; ns++) { 425 struct sockaddr *nsap; 426 int nsaplen; 427 nsap = get_nsaddr(statp, ns); 428 nsaplen = get_salen(nsap); 429 statp->_flags &= ~RES_F_LASTMASK; 430 statp->_flags |= (ns << RES_F_LASTSHIFT); 431 same_ns: --- 34 unchanged lines hidden (view full) --- 466 getnameinfo(nsap, nsaplen, abuf, sizeof(abuf), 467 NULL, 0, niflags) == 0), 468 (stdout, ";; Querying server (# %d) address = %s\n", 469 ns + 1, abuf)); 470 471 472 if (v_circuit) { 473 /* Use VC; at most one attempt per server. */ |
474 try = statp->retry; | 474 tries = statp->retry; |
475 n = send_vc(statp, buf, buflen, ans, anssiz, &terrno, 476 ns); 477 if (n < 0) 478 goto fail; 479 if (n == 0) 480 goto next_ns; 481 resplen = n; 482 } else { 483 /* Use datagrams. */ 484 n = send_dg(statp, 485#ifdef USE_KQUEUE 486 kq, 487#endif 488 buf, buflen, ans, anssiz, &terrno, | 475 n = send_vc(statp, buf, buflen, ans, anssiz, &terrno, 476 ns); 477 if (n < 0) 478 goto fail; 479 if (n == 0) 480 goto next_ns; 481 resplen = n; 482 } else { 483 /* Use datagrams. */ 484 n = send_dg(statp, 485#ifdef USE_KQUEUE 486 kq, 487#endif 488 buf, buflen, ans, anssiz, &terrno, |
489 ns, try, &v_circuit, &gotsomewhere); | 489 ns, tries, &v_circuit, &gotsomewhere); |
490 if (n < 0) 491 goto fail; 492 if (n == 0) 493 goto next_ns; 494 if (v_circuit) 495 goto same_ns; 496 resplen = n; 497 } --- 129 unchanged lines hidden (view full) --- 627 HEADER *anhp = (HEADER *) ans; 628 struct sockaddr *nsap; 629 int nsaplen; 630 int truncating, connreset, resplen, n; 631 struct iovec iov[2]; 632 u_short len; 633 u_char *cp; 634 void *tmp; | 490 if (n < 0) 491 goto fail; 492 if (n == 0) 493 goto next_ns; 494 if (v_circuit) 495 goto same_ns; 496 resplen = n; 497 } --- 129 unchanged lines hidden (view full) --- 627 HEADER *anhp = (HEADER *) ans; 628 struct sockaddr *nsap; 629 int nsaplen; 630 int truncating, connreset, resplen, n; 631 struct iovec iov[2]; 632 u_short len; 633 u_char *cp; 634 void *tmp; |
635#ifdef SO_NOSIGPIPE 636 int on = 1; 637#endif |
|
635 636 nsap = get_nsaddr(statp, ns); 637 nsaplen = get_salen(nsap); 638 639 connreset = 0; 640 same_ns: 641 truncating = 0; 642 --- 31 unchanged lines hidden (view full) --- 674 Perror(statp, stderr, "socket(vc)", errno); 675 return (0); 676 default: 677 *terrno = errno; 678 Perror(statp, stderr, "socket(vc)", errno); 679 return (-1); 680 } 681 } | 638 639 nsap = get_nsaddr(statp, ns); 640 nsaplen = get_salen(nsap); 641 642 connreset = 0; 643 same_ns: 644 truncating = 0; 645 --- 31 unchanged lines hidden (view full) --- 677 Perror(statp, stderr, "socket(vc)", errno); 678 return (0); 679 default: 680 *terrno = errno; 681 Perror(statp, stderr, "socket(vc)", errno); 682 return (-1); 683 } 684 } |
685#ifdef SO_NOSIGPIPE 686 /* 687 * Disable generation of SIGPIPE when writing to a closed 688 * socket. Write should return -1 and set errno to EPIPE 689 * instead. 690 * 691 * Push on even if setsockopt(SO_NOSIGPIPE) fails. 692 */ 693 (void)_setsockopt(statp->_vcsock, SOL_SOCKET, SO_NOSIGPIPE, &on, 694 sizeof(on)); 695#endif |
|
682 errno = 0; 683 if (_connect(statp->_vcsock, nsap, nsaplen) < 0) { 684 *terrno = errno; 685 Aerror(statp, stderr, "connect/vc", errno, nsap, 686 nsaplen); 687 res_nclose(statp); 688 return (0); 689 } --- 116 unchanged lines hidden (view full) --- 806} 807 808static int 809send_dg(res_state statp, 810#ifdef USE_KQUEUE 811 int kq, 812#endif 813 const u_char *buf, int buflen, u_char *ans, | 696 errno = 0; 697 if (_connect(statp->_vcsock, nsap, nsaplen) < 0) { 698 *terrno = errno; 699 Aerror(statp, stderr, "connect/vc", errno, nsap, 700 nsaplen); 701 res_nclose(statp); 702 return (0); 703 } --- 116 unchanged lines hidden (view full) --- 820} 821 822static int 823send_dg(res_state statp, 824#ifdef USE_KQUEUE 825 int kq, 826#endif 827 const u_char *buf, int buflen, u_char *ans, |
814 int anssiz, int *terrno, int ns, int try, int *v_circuit, | 828 int anssiz, int *terrno, int ns, int tries, int *v_circuit, |
815 int *gotsomewhere) 816{ 817 const HEADER *hp = (const HEADER *) buf; 818 HEADER *anhp = (HEADER *) ans; 819 const struct sockaddr *nsap; 820 int nsaplen; 821 struct timespec now, timeout, finish; 822 struct sockaddr_storage from; --- 87 unchanged lines hidden (view full) --- 910 res_nclose(statp); 911 return (0); 912 } 913#endif /* !CANNOT_CONNECT_DGRAM */ 914 915 /* 916 * Wait for reply. 917 */ | 829 int *gotsomewhere) 830{ 831 const HEADER *hp = (const HEADER *) buf; 832 HEADER *anhp = (HEADER *) ans; 833 const struct sockaddr *nsap; 834 int nsaplen; 835 struct timespec now, timeout, finish; 836 struct sockaddr_storage from; --- 87 unchanged lines hidden (view full) --- 924 res_nclose(statp); 925 return (0); 926 } 927#endif /* !CANNOT_CONNECT_DGRAM */ 928 929 /* 930 * Wait for reply. 931 */ |
918 seconds = (statp->retrans << try); | 932 seconds = (statp->retrans << tries); |
919 if (ns > 0) 920 seconds /= statp->nscount; 921 if (seconds <= 0) 922 seconds = 1; 923 now = evNowTime(); 924 timeout = evConsTime(seconds, 0); 925 finish = evAddTime(now, timeout); 926 goto nonow; --- 241 unchanged lines hidden --- | 933 if (ns > 0) 934 seconds /= statp->nscount; 935 if (seconds <= 0) 936 seconds = 1; 937 now = evNowTime(); 938 timeout = evConsTime(seconds, 0); 939 finish = evAddTime(now, timeout); 940 goto nonow; --- 241 unchanged lines hidden --- |