projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
set socket pgrp to avoid races; block SIGURG till done;
[unix-history]
/
usr
/
src
/
lib
/
libc
/
net
/
res_send.c
diff --git
a/usr/src/lib/libc/net/res_send.c
b/usr/src/lib/libc/net/res_send.c
index
9e37090
..
3bdf9de
100644
(file)
--- a/
usr/src/lib/libc/net/res_send.c
+++ b/
usr/src/lib/libc/net/res_send.c
@@
-5,22
+5,22
@@
* specifies the terms and conditions for redistribution.
*/
* specifies the terms and conditions for redistribution.
*/
-#if
ndef lint
-static char sccsid[] = "@(#)res_send.c 6.
3
(Berkeley) %G%";
-#endif not lint
+#if
defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)res_send.c 6.
8
(Berkeley) %G%";
+#endif
LIBC_SCCS and
not lint
/*
* Send query to name server and wait for reply.
*/
/*
* Send query to name server and wait for reply.
*/
-#include <sys/
types
.h>
+#include <sys/
param
.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <errno.h>
#include <arpa/nameser.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <errno.h>
#include <arpa/nameser.h>
-#include <
arpa/
resolv.h>
+#include <resolv.h>
extern int errno;
extern int errno;
@@
-35,6
+35,7
@@
res_send(buf, buflen, answer, anslen)
register int n;
int retry, v_circuit, resplen, ns;
static int s = -1;
register int n;
int retry, v_circuit, resplen, ns;
static int s = -1;
+ int gotsomewhere = 0;
u_short id, len;
char *cp;
int dsmask;
u_short id, len;
char *cp;
int dsmask;
@@
-70,6
+71,13
@@
res_send(buf, buflen, answer, anslen)
*/
if (s < 0) {
s = socket(AF_INET, SOCK_STREAM, 0);
*/
if (s < 0) {
s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s < 0) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf("socket failed %d\n",errno);
+#endif DEBUG
+ continue;
+ }
if (connect(s, &(_res.nsaddr_list[ns]),
sizeof(struct sockaddr)) < 0) {
#ifdef DEBUG
if (connect(s, &(_res.nsaddr_list[ns]),
sizeof(struct sockaddr)) < 0) {
#ifdef DEBUG
@@
-134,6
+142,7
@@
res_send(buf, buflen, answer, anslen)
*/
if (s < 0)
s = socket(AF_INET, SOCK_DGRAM, 0);
*/
if (s < 0)
s = socket(AF_INET, SOCK_DGRAM, 0);
+#if BSD >= 43
if (connect(s, &_res.nsaddr_list[ns],
sizeof(struct sockaddr)) < 0 ||
send(s, buf, buflen, 0) != buflen) {
if (connect(s, &_res.nsaddr_list[ns],
sizeof(struct sockaddr)) < 0 ||
send(s, buf, buflen, 0) != buflen) {
@@
-142,7
+151,18
@@
res_send(buf, buflen, answer, anslen)
printf("connect/send errno = %d\n",
errno);
#endif DEBUG
printf("connect/send errno = %d\n",
errno);
#endif DEBUG
+ continue;
+ }
+#else BSD
+ if (sendto(s, buf, buflen, 0, &_res.nsaddr_list[ns],
+ sizeof(struct sockaddr)) != buflen) {
+#ifdef DEBUG
+ if (_res.options & RES_DEBUG)
+ printf("sendto errno = %d\n", errno);
+#endif DEBUG
+ continue;
}
}
+#endif BSD
/*
* Wait for reply
*/
/*
* Wait for reply
*/
@@
-167,6
+187,7
@@
wait:
if (_res.options & RES_DEBUG)
printf("timeout\n");
#endif DEBUG
if (_res.options & RES_DEBUG)
printf("timeout\n");
#endif DEBUG
+ gotsomewhere = 1;
continue;
}
if ((resplen = recv(s, answer, anslen, 0)) <= 0) {
continue;
}
if ((resplen = recv(s, answer, anslen, 0)) <= 0) {
@@
-176,6
+197,7
@@
wait:
#endif DEBUG
continue;
}
#endif DEBUG
continue;
}
+ gotsomewhere = 1;
if (id != anhp->id) {
/*
* response from old query, ignore it
if (id != anhp->id) {
/*
* response from old query, ignore it
@@
-224,6
+246,10
@@
wait:
}
}
(void) close(s);
}
}
(void) close(s);
- errno = ETIMEDOUT;
+ s = -1;
+ if (v_circuit == 0 && gotsomewhere == 0)
+ errno = ECONNREFUSED;
+ else
+ errno = ETIMEDOUT;
return (-1);
}
return (-1);
}