3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 #pragma ident "%Z%%M% %I% %E% SMI"
41
42 /*
43 * Send query to name server and wait for reply.
44 */
45
46 #include <sys/param.h>
47 #include <sys/time.h>
48 #include <sys/socket.h>
49 #include <sys/uio.h>
50 #include <sys/stat.h>
51 #include <netinet/in.h>
52 #include <stdio.h>
53 #include <errno.h>
54 #include <arpa/nameser.h>
55 #include <resolv.h>
56
57
58 static int s = -1; /* socket used for communications */
59 static struct sockaddr no_addr;
60
61
62 #ifndef FD_SET
63 #define NFDBITS 32
64 #define FD_SETSIZE 32
65 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
66 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
67 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
68 #ifdef SYSV
69 #define FD_ZERO(p) memset((void *)(p), 0, sizeof (*(p)))
70 #else
71 #define FD_ZERO(p) bzero((char *)(p), sizeof (*(p)))
72 #endif
73 #endif
74
75 /*
76 * 1247019: Kludge to time out quickly if there is no /etc/resolv.conf
77 * and a TCP connection to the local DNS server fails.
78 */
79
80 static int _confcheck()
81 {
82 int ns;
83 struct stat rc_stat;
84 struct sockaddr_in ns_sin;
85
86
87 /* First, we check to see if /etc/resolv.conf exists.
88 * If it doesn't, then localhost is mostlikely to be
89 * the nameserver.
112 close(ns);
113 return(0);
114 }
115 }
116
117 return(0);
118 }
119
120 return (0);
121 }
122
123 int
124 res_send(buf, buflen, answer, anslen)
125 char *buf;
126 int buflen;
127 char *answer;
128 int anslen;
129 {
130 register int n;
131 int try, v_circuit, resplen, ns;
132 int gotsomewhere = 0, connected = 0;
133 int connreset = 0;
134 u_short id, len;
135 char *cp;
136 fd_set dsmask;
137 struct timeval timeout;
138 HEADER *hp = (HEADER *) buf;
139 HEADER *anhp = (HEADER *) answer;
140 struct iovec iov[2];
141 int terrno = ETIMEDOUT;
142 char junk[512];
143
144 #ifdef DEBUG
145 if (_res.options & RES_DEBUG) {
146 printf("res_send()\n");
147 p_query(buf);
148 }
149 #endif
150 if (!(_res.options & RES_INIT))
151 if (res_init() == -1) {
152 return (-1);
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2015 Gary Mills
24 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 /*
32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 * The Regents of the University of California
34 * All Rights Reserved
35 *
36 * University Acknowledgment- Portions of this document are derived from
37 * software developed by the University of California, Berkeley, and its
38 * contributors.
39 */
40
41 /*
42 * Send query to name server and wait for reply.
43 */
44
45 #include <sys/param.h>
46 #include <sys/time.h>
47 #include <sys/socket.h>
48 #include <sys/uio.h>
49 #include <sys/stat.h>
50 #include <netinet/in.h>
51 #include <stdio.h>
52 #include <string.h>
53 #include <unistd.h>
54 #include <errno.h>
55 #include <arpa/nameser.h>
56 #include <arpa/inet.h>
57 #include <resolv.h>
58 #include "crossl.h"
59
60 /*
61 * Undocumented external function in libsocket
62 */
63 extern int
64 _socket(int, int, int);
65
66 static int s = -1; /* socket used for communications */
67 #if BSD >= 43
68 static struct sockaddr no_addr;
69 #endif /* BSD */
70
71
72 #ifndef FD_SET
73 #define NFDBITS 32
74 #define FD_SETSIZE 32
75 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
76 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
77 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
78 #ifdef SYSV
79 #define FD_ZERO(p) (void) memset((void *)(p), 0, sizeof (*(p)))
80 #else
81 #define FD_ZERO(p) bzero((char *)(p), sizeof (*(p)))
82 #endif
83 #endif
84
85 /*
86 * 1247019: Kludge to time out quickly if there is no /etc/resolv.conf
87 * and a TCP connection to the local DNS server fails.
88 */
89
90 static int _confcheck()
91 {
92 int ns;
93 struct stat rc_stat;
94 struct sockaddr_in ns_sin;
95
96
97 /* First, we check to see if /etc/resolv.conf exists.
98 * If it doesn't, then localhost is mostlikely to be
99 * the nameserver.
122 close(ns);
123 return(0);
124 }
125 }
126
127 return(0);
128 }
129
130 return (0);
131 }
132
133 int
134 res_send(buf, buflen, answer, anslen)
135 char *buf;
136 int buflen;
137 char *answer;
138 int anslen;
139 {
140 register int n;
141 int try, v_circuit, resplen, ns;
142 int gotsomewhere = 0;
143 #if BSD >= 43
144 int connected = 0;
145 #endif /* BSD */
146 int connreset = 0;
147 u_short id, len;
148 char *cp;
149 fd_set dsmask;
150 struct timeval timeout;
151 HEADER *hp = (HEADER *) buf;
152 HEADER *anhp = (HEADER *) answer;
153 struct iovec iov[2];
154 int terrno = ETIMEDOUT;
155 char junk[512];
156
157 #ifdef DEBUG
158 if (_res.options & RES_DEBUG) {
159 printf("res_send()\n");
160 p_query(buf);
161 }
162 #endif
163 if (!(_res.options & RES_INIT))
164 if (res_init() == -1) {
165 return (-1);
|