Remove compatibility code which is unused in glibc and probably bitrotten.

This commit is contained in:
Ulrich Drepper 2004-10-23 06:12:20 +00:00
parent 3fd352b01b
commit 3bc99c1158

View File

@ -78,9 +78,7 @@ static const char rcsid[] = "$BINDId: res_send.c,v 8.38 2000/03/30 20:16:51 vixi
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/uio.h> #include <sys/uio.h>
#ifdef _LIBC
#include <sys/poll.h> #include <sys/poll.h>
#endif
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/nameser.h> #include <arpa/nameser.h>
@ -103,9 +101,6 @@ static const char rcsid[] = "$BINDId: res_send.c,v 8.38 2000/03/30 20:16:51 vixi
#define MAXPACKET 65536 #define MAXPACKET 65536
#endif #endif
#ifndef _LIBC
#include <isc/eventlib.h>
#else
/* From ev_streams.c. */ /* From ev_streams.c. */
@ -170,7 +165,6 @@ evNowTime(struct timespec *res) {
TIMEVAL_TO_TIMESPEC (&now, res); TIMEVAL_TO_TIMESPEC (&now, res);
} }
#endif
/* Options. Leave them on. */ /* Options. Leave them on. */
/* #undef DEBUG */ /* #undef DEBUG */
@ -178,10 +172,6 @@ evNowTime(struct timespec *res) {
#define EXT(res) ((res)->_u._ext) #define EXT(res) ((res)->_u._ext)
#ifndef _LIBC
static const int highestFD = FD_SETSIZE - 1;
#endif
/* Forward. */ /* Forward. */
static int send_vc(res_state, const u_char *, int, static int send_vc(res_state, const u_char *, int,
@ -194,22 +184,11 @@ static void Aerror(const res_state, FILE *, const char *, int,
const struct sockaddr *); const struct sockaddr *);
static void Perror(const res_state, FILE *, const char *, int); static void Perror(const res_state, FILE *, const char *, int);
#endif #endif
#ifdef _LIBC
static int sock_eq(struct sockaddr_in6 *, struct sockaddr_in6 *); static int sock_eq(struct sockaddr_in6 *, struct sockaddr_in6 *);
#else
static int sock_eq(struct sockaddr_in *, struct sockaddr_in *);
#endif
#ifdef NEED_PSELECT
static int pselect(int, void *, void *, void *,
struct timespec *,
const sigset_t *);
#endif
/* Reachover. */ /* Reachover. */
#ifdef _LIBC
static void convaddr4to6(struct sockaddr_in6 *sa); static void convaddr4to6(struct sockaddr_in6 *sa);
#endif
void res_pquery(const res_state, const u_char *, int, FILE *); void res_pquery(const res_state, const u_char *, int, FILE *);
/* Public. */ /* Public. */
@ -224,15 +203,10 @@ void res_pquery(const res_state, const u_char *, int, FILE *);
* paul vixie, 29may94 * paul vixie, 29may94
*/ */
int int
#ifdef _LIBC
res_ourserver_p(const res_state statp, const struct sockaddr_in6 *inp) res_ourserver_p(const res_state statp, const struct sockaddr_in6 *inp)
#else
res_ourserver_p(const res_state statp, const struct sockaddr_in *inp)
#endif
{ {
int ns; int ns;
#ifdef _LIBC
if (inp->sin6_family == AF_INET) { if (inp->sin6_family == AF_INET) {
struct sockaddr_in *in4p = (struct sockaddr_in *) inp; struct sockaddr_in *in4p = (struct sockaddr_in *) inp;
in_port_t port = in4p->sin_port; in_port_t port = in4p->sin_port;
@ -260,18 +234,6 @@ res_ourserver_p(const res_state statp, const struct sockaddr_in *inp)
return (1); return (1);
} }
} }
#else
struct sockaddr_in ina = *inp;
for (ns = 0; ns < statp->nscount; ns++) {
const struct sockaddr_in *srv = &statp->nsaddr_list[ns];
if (srv->sin_family == ina.sin_family &&
srv->sin_port == ina.sin_port &&
(srv->sin_addr.s_addr == INADDR_ANY ||
srv->sin_addr.s_addr == ina.sin_addr.s_addr))
return (1);
}
#endif
return (0); return (0);
} }
@ -406,18 +368,12 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
if (EXT(statp).nscount != statp->nscount) if (EXT(statp).nscount != statp->nscount)
needclose++; needclose++;
else else
#ifdef _LIBC
for (ns = 0; ns < MAXNS; ns++) { for (ns = 0; ns < MAXNS; ns++) {
unsigned int map = EXT(statp).nsmap[ns]; unsigned int map = EXT(statp).nsmap[ns];
if (map < MAXNS if (map < MAXNS
&& !sock_eq((struct sockaddr_in6 *) && !sock_eq((struct sockaddr_in6 *)
&statp->nsaddr_list[map], &statp->nsaddr_list[map],
EXT(statp).nsaddrs[ns])) EXT(statp).nsaddrs[ns]))
#else
for (ns = 0; ns < statp->nscount; ns++) {
if (!sock_eq(&statp->nsaddr_list[ns],
&EXT(statp).nsaddrs[ns]))
#endif
{ {
needclose++; needclose++;
break; break;
@ -431,7 +387,6 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
* Maybe initialize our private copy of the ns_addr_list. * Maybe initialize our private copy of the ns_addr_list.
*/ */
if (EXT(statp).nsinit == 0) { if (EXT(statp).nsinit == 0) {
#ifdef _LIBC
unsigned char map[MAXNS]; unsigned char map[MAXNS];
memset (map, MAXNS, sizeof (map)); memset (map, MAXNS, sizeof (map));
@ -471,13 +426,6 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
n++; n++;
} }
} }
#else
for (ns = 0; ns < statp->nscount; ns++) {
EXT(statp).nsaddrs[ns] = statp->nsaddr_list[ns];
EXT(statp).nssocks[ns] = -1;
}
EXT(statp).nscount = ns;
#endif
EXT(statp).nsinit = 1; EXT(statp).nsinit = 1;
} }
@ -487,7 +435,6 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
*/ */
if ((statp->options & RES_ROTATE) != 0 && if ((statp->options & RES_ROTATE) != 0 &&
(statp->options & RES_BLAST) == 0) { (statp->options & RES_BLAST) == 0) {
#ifdef _LIBC
struct sockaddr_in6 *ina; struct sockaddr_in6 *ina;
unsigned int map; unsigned int map;
@ -511,35 +458,18 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
EXT(statp).nsaddrs[n] = ina; EXT(statp).nsaddrs[n] = ina;
EXT(statp).nsmap[n] = map; EXT(statp).nsmap[n] = map;
} }
#else
struct sockaddr_in ina;
int lastns = statp->nscount - 1;
ina = statp->nsaddr_list[0];
for (ns = 0; ns < lastns; ns++)
statp->nsaddr_list[ns] = statp->nsaddr_list[ns + 1];
statp->nsaddr_list[lastns] = ina;
#endif
} }
/* /*
* Send request, RETRY times, or until successful. * Send request, RETRY times, or until successful.
*/ */
for (try = 0; try < statp->retry; try++) { for (try = 0; try < statp->retry; try++) {
#ifdef _LIBC
for (ns = 0; ns < MAXNS; ns++) for (ns = 0; ns < MAXNS; ns++)
#else
for (ns = 0; ns < statp->nscount; ns++)
#endif
{ {
#ifdef _LIBC
struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns]; struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];
if (nsap == NULL) if (nsap == NULL)
goto next_ns; goto next_ns;
#else
struct sockaddr_in *nsap = &statp->nsaddr_list[ns];
#endif
same_ns: same_ns:
if (statp->qhook) { if (statp->qhook) {
int done = 0, loops = 0; int done = 0, loops = 0;
@ -547,16 +477,11 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
do { do {
res_sendhookact act; res_sendhookact act;
#ifdef _LIBC
struct sockaddr_in *nsap4; struct sockaddr_in *nsap4;
nsap4 = (struct sockaddr_in *) nsap; nsap4 = (struct sockaddr_in *) nsap;
act = (*statp->qhook)(&nsap4, &buf, &buflen, act = (*statp->qhook)(&nsap4, &buf, &buflen,
ans, anssiz, &resplen); ans, anssiz, &resplen);
nsap = (struct sockaddr_in6 *) nsap4; nsap = (struct sockaddr_in6 *) nsap4;
#else
act = (*statp->qhook)(&nsap, &buf, &buflen,
ans, anssiz, &resplen);
#endif
switch (act) { switch (act) {
case res_goahead: case res_goahead:
done = 1; done = 1;
@ -579,7 +504,6 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
} while (!done); } while (!done);
} }
#ifdef _LIBC
#ifdef DEBUG #ifdef DEBUG
char tmpbuf[40]; char tmpbuf[40];
#endif #endif
@ -587,11 +511,6 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
(stdout, ";; Querying server (# %d) address = %s\n", (stdout, ";; Querying server (# %d) address = %s\n",
ns + 1, inet_ntop(AF_INET6, &nsap->sin6_addr, ns + 1, inet_ntop(AF_INET6, &nsap->sin6_addr,
tmpbuf, sizeof (tmpbuf)))); tmpbuf, sizeof (tmpbuf))));
#else
Dprint(statp->options & RES_DEBUG,
(stdout, ";; Querying server (# %d) address = %s\n",
ns + 1, inet_ntoa(nsap->sin_addr)));
#endif
if (v_circuit) { if (v_circuit) {
/* Use VC; at most one attempt per server. */ /* Use VC; at most one attempt per server. */
@ -641,14 +560,9 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
do { do {
res_sendhookact act; res_sendhookact act;
#ifdef _LIBC
act = (*statp->rhook)((struct sockaddr_in *) act = (*statp->rhook)((struct sockaddr_in *)
nsap, buf, buflen, nsap, buf, buflen,
ans, anssiz, &resplen); ans, anssiz, &resplen);
#else
act = (*statp->rhook)(nsap, buf, buflen,
ans, anssiz, &resplen);
#endif
switch (act) { switch (act) {
case res_goahead: case res_goahead:
case res_done: case res_done:
@ -704,11 +618,7 @@ send_vc(res_state statp,
u_char *ans = *ansp; u_char *ans = *ansp;
int anssiz = *anssizp; int anssiz = *anssizp;
HEADER *anhp = (HEADER *) ans; HEADER *anhp = (HEADER *) ans;
#ifdef _LIBC
struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns]; struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];
#else
struct sockaddr_in *nsap = &statp->nsaddr_list[ns];
#endif
int truncating, connreset, resplen, n; int truncating, connreset, resplen, n;
struct iovec iov[2]; struct iovec iov[2];
u_short len; u_short len;
@ -720,11 +630,7 @@ send_vc(res_state statp,
/* Are we still talking to whom we want to talk to? */ /* Are we still talking to whom we want to talk to? */
if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) { if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
#ifdef _LIBC
struct sockaddr_in6 peer; struct sockaddr_in6 peer;
#else
struct sockaddr_in peer;
#endif
int size = sizeof peer; int size = sizeof peer;
if (getpeername(statp->_vcsock, if (getpeername(statp->_vcsock,
@ -739,15 +645,7 @@ send_vc(res_state statp,
if (statp->_vcsock >= 0) if (statp->_vcsock >= 0)
res_nclose(statp); res_nclose(statp);
#ifdef _LIBC
statp->_vcsock = socket(nsap->sin6_family, SOCK_STREAM, 0); statp->_vcsock = socket(nsap->sin6_family, SOCK_STREAM, 0);
#else
statp->_vcsock = socket(PF_INET, SOCK_STREAM, 0);
if (statp->_vcsock > highestFD) {
res_nclose(statp);
__set_errno (ENOTSOCK);
}
#endif
if (statp->_vcsock < 0) { if (statp->_vcsock < 0) {
*terrno = errno; *terrno = errno;
Perror(statp, stderr, "socket(vc)", errno); Perror(statp, stderr, "socket(vc)", errno);
@ -904,25 +802,15 @@ send_dg(res_state statp,
u_char *ans = *ansp; u_char *ans = *ansp;
int anssiz = *anssizp; int anssiz = *anssizp;
HEADER *anhp = (HEADER *) ans; HEADER *anhp = (HEADER *) ans;
#ifdef _LIBC
struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns]; struct sockaddr_in6 *nsap = EXT(statp).nsaddrs[ns];
#else
const struct sockaddr_in *nsap = &statp->nsaddr_list[ns];
#endif
struct timespec now, timeout, finish; struct timespec now, timeout, finish;
#ifdef _LIBC
struct pollfd pfd[1]; struct pollfd pfd[1];
int ptimeout; int ptimeout;
struct sockaddr_in6 from; struct sockaddr_in6 from;
static int socket_pf = 0; static int socket_pf = 0;
#else
fd_set dsmask;
struct sockaddr_in from;
#endif
int fromlen, resplen, seconds, n, s; int fromlen, resplen, seconds, n, s;
if (EXT(statp).nssocks[ns] == -1) { if (EXT(statp).nssocks[ns] == -1) {
#ifdef _LIBC
/* only try IPv6 if IPv6 NS and if not failed before */ /* only try IPv6 if IPv6 NS and if not failed before */
if ((EXT(statp).nscount6 > 0) && (socket_pf != PF_INET)) { if ((EXT(statp).nscount6 > 0) && (socket_pf != PF_INET)) {
EXT(statp).nssocks[ns] = EXT(statp).nssocks[ns] =
@ -932,24 +820,14 @@ send_dg(res_state statp,
} }
if (EXT(statp).nssocks[ns] < 0) if (EXT(statp).nssocks[ns] < 0)
EXT(statp).nssocks[ns] = socket(PF_INET, SOCK_DGRAM, 0); EXT(statp).nssocks[ns] = socket(PF_INET, SOCK_DGRAM, 0);
#else
EXT(statp).nssocks[ns] = socket(PF_INET, SOCK_DGRAM, 0);
if (EXT(statp).nssocks[ns] > highestFD) {
res_nclose(statp);
__set_errno (ENOTSOCK);
}
#endif
if (EXT(statp).nssocks[ns] < 0) { if (EXT(statp).nssocks[ns] < 0) {
*terrno = errno; *terrno = errno;
Perror(statp, stderr, "socket(dg)", errno); Perror(statp, stderr, "socket(dg)", errno);
return (-1); return (-1);
} }
#ifndef CANNOT_CONNECT_DGRAM
#ifdef _LIBC
/* If IPv6 socket and nsap is IPv4, make it IPv4-mapped */ /* If IPv6 socket and nsap is IPv4, make it IPv4-mapped */
if ((socket_pf == PF_INET6) && (nsap->sin6_family == AF_INET)) if ((socket_pf == PF_INET6) && (nsap->sin6_family == AF_INET))
convaddr4to6(nsap); convaddr4to6(nsap);
#endif
/* /*
* On a 4.3BSD+ machine (client and server, * On a 4.3BSD+ machine (client and server,
* actually), sending to a nameserver datagram * actually), sending to a nameserver datagram
@ -968,7 +846,6 @@ send_dg(res_state statp,
res_nclose(statp); res_nclose(statp);
return (0); return (0);
} }
#endif /* !CANNOT_CONNECT_DGRAM */
/* Make socket non-blocking. */ /* Make socket non-blocking. */
int fl = __fcntl (EXT(statp).nssocks[ns], F_GETFL); int fl = __fcntl (EXT(statp).nssocks[ns], F_GETFL);
if (fl != -1) if (fl != -1)
@ -991,7 +868,6 @@ send_dg(res_state statp,
evAddTime(&finish, &now, &timeout); evAddTime(&finish, &now, &timeout);
int need_recompute = 0; int need_recompute = 0;
resend: resend:
#ifdef _LIBC
/* Convert struct timespec in milliseconds. */ /* Convert struct timespec in milliseconds. */
ptimeout = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000; ptimeout = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000;
@ -1002,16 +878,6 @@ send_dg(res_state statp,
n = __poll (pfd, 1, ptimeout); n = __poll (pfd, 1, ptimeout);
need_recompute = 1; need_recompute = 1;
} }
#else
FD_ZERO(&dsmask);
FD_SET(s, &dsmask);
struct timeval zerotime = { 0, 0 };
n = pselect(s + 1, NULL, &dsmask, NULL, &zerotime, NULL);
if (n == 0) {
n = pselect(s + 1, NULL, &dsmask, NULL, &timeout, NULL);
need_recompute = 1;
}
#endif
if (n == 0) { if (n == 0) {
Dprint(statp->options & RES_DEBUG, (stdout, Dprint(statp->options & RES_DEBUG, (stdout,
";; timeout sending\n")); ";; timeout sending\n"));
@ -1032,7 +898,6 @@ send_dg(res_state statp,
return (0); return (0);
} }
__set_errno (0); __set_errno (0);
#ifndef CANNOT_CONNECT_DGRAM
if (send(s, (char*)buf, buflen, 0) != buflen) { if (send(s, (char*)buf, buflen, 0) != buflen) {
if (errno == EINTR || errno == EAGAIN) if (errno == EINTR || errno == EAGAIN)
goto recompute_resend; goto recompute_resend;
@ -1040,23 +905,6 @@ send_dg(res_state statp,
res_nclose(statp); res_nclose(statp);
return (0); return (0);
} }
#else /* !CANNOT_CONNECT_DGRAM */
#ifdef _LIBC
/* If IPv6 socket and nsap is IPv4, make it IPv4-mapped */
if ((socket_pf == PF_INET6) && (nsap->sin6_family == AF_INET))
convaddr4to6(nsap);
#endif
if (sendto(s, (char*)buf, buflen, 0,
(struct sockaddr *)nsap, sizeof *nsap) != buflen)
{
if (errno == EINTR || errno == EAGAIN)
goto recompute_resend;
Aerror(statp, stderr, "sendto", errno,
(struct sockaddr *) nsap);
res_nclose(statp);
return (0);
}
#endif /* !CANNOT_CONNECT_DGRAM */
wait: wait:
if (need_recompute) { if (need_recompute) {
@ -1069,15 +917,11 @@ send_dg(res_state statp,
} }
evSubTime(&timeout, &finish, &now); evSubTime(&timeout, &finish, &now);
} }
#ifdef _LIBC
/* Convert struct timespec in milliseconds. */ /* Convert struct timespec in milliseconds. */
ptimeout = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000; ptimeout = timeout.tv_sec * 1000 + timeout.tv_nsec / 1000000;
pfd[0].events = POLLIN; pfd[0].events = POLLIN;
n = __poll (pfd, 1, ptimeout); n = __poll (pfd, 1, ptimeout);
#else
n = pselect(s + 1, &dsmask, NULL, NULL, &timeout, NULL);
#endif
if (n == 0) { if (n == 0) {
Dprint(statp->options & RES_DEBUG, (stdout, Dprint(statp->options & RES_DEBUG, (stdout,
";; timeout receiving\n")); ";; timeout receiving\n"));
@ -1092,11 +936,7 @@ send_dg(res_state statp,
goto err_return; goto err_return;
} }
__set_errno (0); __set_errno (0);
#ifdef _LIBC
fromlen = sizeof(struct sockaddr_in6); fromlen = sizeof(struct sockaddr_in6);
#else
fromlen = sizeof(struct sockaddr_in);
#endif
if (anssiz < MAXPACKET if (anssiz < MAXPACKET
&& anscp && anscp
&& (ioctl (s, FIONREAD, &resplen) < 0 && (ioctl (s, FIONREAD, &resplen) < 0
@ -1239,7 +1079,6 @@ Perror(const res_state statp, FILE *file, const char *string, int error) {
#endif #endif
static int static int
#ifdef _LIBC
sock_eq(struct sockaddr_in6 *a1, struct sockaddr_in6 *a2) { sock_eq(struct sockaddr_in6 *a1, struct sockaddr_in6 *a2) {
if (a1->sin6_family == a2->sin6_family) { if (a1->sin6_family == a2->sin6_family) {
if (a1->sin6_family == AF_INET) if (a1->sin6_family == AF_INET)
@ -1262,15 +1101,7 @@ sock_eq(struct sockaddr_in6 *a1, struct sockaddr_in6 *a2) {
(a1->sin6_addr.s6_addr32[3] == (a1->sin6_addr.s6_addr32[3] ==
((struct sockaddr_in *)a2)->sin_addr.s_addr)); ((struct sockaddr_in *)a2)->sin_addr.s_addr));
} }
#else
sock_eq(struct sockaddr_in *a1, struct sockaddr_in *a2) {
return ((a1->sin_family == a2->sin_family) &&
(a1->sin_port == a2->sin_port) &&
(a1->sin_addr.s_addr == a2->sin_addr.s_addr));
}
#endif
#ifdef _LIBC
/* /*
* Converts IPv4 family, address and port to * Converts IPv4 family, address and port to
* IPv6 family, IPv4-mapped IPv6 address and port. * IPv6 family, IPv4-mapped IPv6 address and port.
@ -1289,30 +1120,3 @@ convaddr4to6(struct sockaddr_in6 *sa)
sa->sin6_addr.s6_addr32[2] = htonl(0xFFFF); sa->sin6_addr.s6_addr32[2] = htonl(0xFFFF);
sa->sin6_addr.s6_addr32[3] = addr; sa->sin6_addr.s6_addr32[3] = addr;
} }
#endif
#ifdef NEED_PSELECT
/* XXX needs to move to the porting library. */
static int
pselect(int nfds, void *rfds, void *wfds, void *efds,
struct timespec *tsp, const sigset_t *sigmask)
{
struct timeval tv, *tvp;
sigset_t sigs;
int n;
if (tsp) {
tvp = &tv;
tv = evTimeVal(*tsp);
} else
tvp = NULL;
if (sigmask)
sigprocmask(SIG_SETMASK, sigmask, &sigs);
n = select(nfds, rfds, wfds, efds, tvp);
if (sigmask)
sigprocmask(SIG_SETMASK, &sigs, NULL);
if (tsp)
TIMEVAL_TO_TIMESPEC (tv, *tsp);
return (n);
}
#endif