#ifndef LIST_H
#define LIST_H 1
+#ifdef _LIBC
+#include <assert.h>
+#define INSIST(cond) assert(cond)
+#else
#include <isc/assertions.h>
-
+#endif
#define LIST(type) struct { type *head, *tail; }
#define INIT_LIST(list) \
do { (list).head = NULL; (list).tail = NULL; } while (0)
* Ascii internet address interpretation routine.
* The value returned is in network order.
*/
-u_long
+in_addr_t
inet_addr(const char *cp) {
struct in_addr val;
return (1);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_addr
+__weak_reference(__inet_addr, inet_addr);
+#undef inet_aton
+__weak_reference(__inet_aton, inet_aton);
+#endif
/*! \file */
#include <arpa/nameser.h>
#include <arpa/inet.h>
+#ifdef _LIBC
+#include <assert.h>
+#define INSIST(x) assert(x)
+#else
#include <isc/assertions.h>
+#endif
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
* internet address; handles class a/b/c network
* number formats.
*/
-u_long
+in_addr_t
inet_lnaof(in)
struct in_addr in;
{
- register u_long i = ntohl(in.s_addr);
+ in_addr_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
return ((i)&IN_CLASSA_HOST);
return ((i)&IN_CLASSC_HOST);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_lnaof
+__weak_reference(__inet_lnaof, inet_lnaof);
+#endif
/*! \file */
*/
struct in_addr
inet_makeaddr(net, host)
- u_long net, host;
+ in_addr_t net, host;
{
struct in_addr a;
return (a);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_makeaddr
+__weak_reference(__inet_makeaddr, inet_makeaddr);
+#endif
/*! \file */
return (NULL);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_net_ntop
+__weak_reference(__inet_net_ntop, inet_net_ntop);
+#endif
/*! \file */
#include <arpa/nameser.h>
#include <arpa/inet.h>
+#ifdef _LIBC
+#include <assert.h>
+#define INSIST(cond) assert(cond)
+#else
#include <isc/assertions.h>
+#endif
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
}
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_net_pton
+__weak_reference(__inet_net_pton, inet_net_pton);
+#endif
/*! \file */
*/
char *
inet_neta(src, dst, size)
- u_long src;
+ in_addr_t src;
char *dst;
size_t size;
{
return (NULL);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_neta
+__weak_reference(__inet_neta, inet_neta);
+#endif
/*! \file */
* Return the network number from an internet
* address; handles class a/b/c network #'s.
*/
-u_long
+in_addr_t
inet_netof(in)
struct in_addr in;
{
- register u_long i = ntohl(in.s_addr);
-
+ in_addr_t i = ntohl(in.s_addr);
+
if (IN_CLASSA(i))
return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
else if (IN_CLASSB(i))
return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_netof
+__weak_reference(__inet_netof, inet_netof);
+#endif
/*! \file */
* The library routines call this routine to interpret
* network numbers.
*/
-u_long
+in_addr_t
inet_network(cp)
- register const char *cp;
+ const char *cp;
{
- register u_long val, base, n, i;
- register char c;
- u_long parts[4], *pp = parts;
- int digit;
-
+ in_addr_t val, base, n;
+ char c;
+ in_addr_t parts[4], *pp = parts;
+ int i, digit;
again:
val = 0; base = 10; digit = 0;
if (*cp == '0')
return (val);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_network
+__weak_reference(__inet_network, inet_network);
+#endif
/*! \file */
return (ret);
}
+#ifdef _LIBC
+char *
+inet_ntoa_r(struct in_addr in, char *buf, socklen_t size)
+{
+
+ inet_ntop(AF_INET, &in, buf, size);
+ return (buf);
+}
+
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+*/
+#undef inet_ntoa
+__weak_reference(__inet_ntoa, inet_ntoa);
+__weak_reference(__inet_ntoa_r, inet_ntoa_r);
+#endif
/*! \file */
#include <sys/socket.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
+#include "arpa/inet.h"
#include <arpa/nameser.h>
#include <errno.h>
return (dst);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_ntop
+__weak_reference(__inet_ntop, inet_ntop);
+#endif
/*! \file */
return (1);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_pton
+__weak_reference(__inet_pton, inet_pton);
+#endif
/*! \file */
#include <ctype.h>
#include <resolv.h>
-#include <resolv_mt.h>
+#include "resolv_mt.h"
#include "port_after.h"
return (start);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <arpa/inet.h>.
+ */
+#undef inet_nsap_addr
+__weak_reference(__inet_nsap_addr, inet_nsap_addr);
+#undef inet_nsap_ntoa
+__weak_reference(__inet_nsap_ntoa, inet_nsap_ntoa);
+#endif
/*! \file */
int
getnetgrent(NGR_R_CONST char **host, NGR_R_CONST char **user,
- NGR_R_CONST char **domain)
+ NGR_R_CONST char **domain)
{
struct net_data *net_data = init();
const char *ch, *cu, *cd;
#endif
#include "port_before.h"
+#ifndef _LIBC
#include "fd_setsize.h"
+#endif
#include <sys/types.h>
#include <sys/uio.h>
#include <errno.h>
-#include <isc/eventlib.h>
+#include "isc/eventlib.h"
+#ifndef _LIBC
#include <isc/assertions.h>
+#endif
#include "eventlib_p.h"
#include "port_after.h"
+#ifndef _LIBC
static int copyvec(evStream *str, const struct iovec *iov, int iocnt);
static void consume(evStream *str, size_t bytes);
static void done(evContext opaqueCtx, evStream *str);
static void writable(evContext opaqueCtx, void *uap, int fd, int evmask);
static void readable(evContext opaqueCtx, void *uap, int fd, int evmask);
+#endif
struct iovec
evConsIovec(void *buf, size_t cnt) {
return (ret);
}
+#ifndef _LIBC
int
evWrite(evContext opaqueCtx, int fd, const struct iovec *iov, int iocnt,
evStreamFunc func, void *uap, evStreamID *id)
if (str->ioDone <= 0 || str->ioDone == str->ioTotal)
done(opaqueCtx, str);
}
+#endif /* !_LIBC */
/*! \file */
/* Import. */
#include "port_before.h"
+#ifndef _LIBC
#include "fd_setsize.h"
+#endif
#include <errno.h>
+#ifndef _LIBC
#include <isc/assertions.h>
-#include <isc/eventlib.h>
+#endif
+#include "isc/eventlib.h"
#include "eventlib_p.h"
#include "port_after.h"
#define BILLION 1000000000
/* Forward. */
-
+#ifdef _LIBC
+static int __evOptMonoTime;
+#else
static int due_sooner(void *, void *);
static void set_index(void *, int);
static void free_timer(void *, void *);
struct timespec max_idle;
evTimer * timer;
} idle_timer;
-
+#endif
/* Public. */
struct timespec
return (evTimeSpec(now));
}
+#ifndef _LIBC
struct timespec
evLastEventTime(evContext opaqueCtx) {
evContext_p *ctx = opaqueCtx.opaque;
return (ctx->lastEventTime);
}
+#endif
struct timespec
evTimeSpec(struct timeval tv) {
ts.tv_nsec = tv.tv_usec * 1000;
return (ts);
}
-
+#if !defined(USE_KQUEUE) || !defined(_LIBC)
struct timeval
evTimeVal(struct timespec ts) {
struct timeval tv;
tv.tv_usec = ts.tv_nsec / 1000;
return (tv);
}
+#endif
+#ifndef _LIBC
int
evSetTimer(evContext opaqueCtx,
evTimerFunc func,
this->timer->inter = evSubTime(this->max_idle, idle);
}
}
+#endif /* !_LIBC */
/*! \file */
#include <stdlib.h>
#include <string.h>
+#ifndef _LIBC
#include <isc/heap.h>
#include <isc/list.h>
#include <isc/memcluster.h>
+#endif
#define EV_MASK_ALL (EV_READ | EV_WRITE | EV_EXCEPT)
#define EV_ERR(e) return (errno = (e), -1)
struct evConn * next;
} evConn;
+#ifndef _LIBC
typedef struct evAccept {
int fd;
union {
struct { const void *placeholder; } null;
} u;
} evEvent_p;
+#endif /* !_LIBC */
#ifdef USE_POLL
typedef struct {
#endif /* USE_POLL */
+#ifndef _LIBC
typedef struct {
/* Global. */
const evEvent_p *cur;
/* ev_waits.c */
#define evFreeWait __evFreeWait
evWait *evFreeWait(evContext_p *ctx, evWait *old);
+#endif /* !_LIBC */
/* Global options */
+#ifndef _LIBC
extern int __evOptMonoTime;
+#endif /* !_LIBC */
#endif /*_EVENTLIB_P_H*/
#include <arpa/nameser.h>
#include <arpa/inet.h>
+#ifdef _LIBC
+#include <assert.h>
+#define INSIST(cond) assert(cond)
+#else
#include <isc/assertions.h>
#include <isc/dst.h>
+#endif
#include <errno.h>
#include <resolv.h>
#include <string.h>
goto formerr;
/* Key flags, Protocol, Algorithm. */
+#ifndef _LIBC
key_id = dst_s_dns_key_id(rdata, edata-rdata);
+#else
+ key_id = 0;
+#endif
keyflags = ns_get16(rdata); rdata += NS_INT16SZ;
protocol = *rdata++;
algorithm = *rdata++;
return (strncasecmp(cp, b, lb) == 0);
}
-/*%
+#ifndef _LIBC
+/*
+ * int
+ * ns_subdomain(a, b)
* is "a" a subdomain of "b"?
*/
int
ns_subdomain(const char *a, const char *b) {
return (ns_samename(a, b) != 1 && ns_samedomain(a, b));
}
+#endif
/*%
* make a canonical copy of domain name "src"
#include "port_before.h"
+#ifdef _LIBC
+#include "namespace.h"
+#endif
+
#include <sys/types.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <resolv.h>
#include <string.h>
#include <unistd.h>
+#ifndef _LIBC
#include <irs.h>
+#else
+#include "un-namespace.h"
+#endif
#include "port_after.h"
DE_CONST("\n", t);
v->iov_base = t;
v->iov_len = 1;
+#ifndef _LIBC
writev(STDERR_FILENO, iov, (v - iov) + 1);
+#else
+ _writev(STDERR_FILENO, iov, (v - iov) + 1);
+#endif
}
/*%
#include <port_before.h>
#ifdef DO_PTHREADS
#include <pthread.h>
+#ifdef _LIBC
+#include <pthread_np.h>
+#endif
#endif
#include <errno.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
-#include <resolv_mt.h>
+#include "resolv_mt.h"
+#ifndef _LIBC
#include <irs.h>
+#endif
#include <port_after.h>
#ifdef DO_PTHREADS
}
#endif
+#ifndef _LIBC
/*
* To support binaries that used the private MT-safe interface in
* Solaris 8, we still need to provide the __res_enable_mt()
__res_enable_mt(void) {
return (-1);
}
+#endif
int
__res_disable_mt(void) {
#ifdef DO_PTHREADS
mtctxres_t *mt;
+#ifdef _LIBC
+ if (pthread_main_np() != 0)
+ return (&sharedctx);
+#endif
+
+
/*
* This if clause should only be executed if we are linking
* statically. When linked dynamically _mtctxres_init() should
#endif /*__ultrix__*/
#endif /*BIND_4_COMPAT*/
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <resolv.h>.
+ */
+#undef dn_comp
+__weak_reference(__dn_comp, dn_comp);
+#undef dn_expand
+__weak_reference(__dn_expand, dn_expand);
+#endif
/*! \file */
#include <unistd.h>
#include "port_after.h"
+#ifndef _LIBC
+#undef _res
+#endif
+
const char *_res_opcodes[] = {
"QUERY",
#undef _res
#ifndef __BIND_NOSTATIC
+#ifndef _LIBC
struct __res_state _res
# if defined(__BIND_RES_TEXT)
= { RES_TIMEOUT, } /*%< Motorola, et al. */
# endif
;
+#endif /* !_LIBC */
#if defined(DO_PTHREADS) || defined(__linux)
#define _res (*__res_state())
if (!_res.retrans)
_res.retrans = RES_TIMEOUT;
if (!_res.retry)
+#ifndef _LIBC
_res.retry = 4;
+#else
+ _res.retry = RES_DFLRETRY;
+#endif
if (!(_res.options & RES_INIT))
_res.options = RES_DEFAULT;
return (res_nquery(&_res, name, class, type, answer, anslen));
}
+#ifndef _LIBC
void
res_send_setqhook(res_send_qhook hook) {
_res.qhook = hook;
res_send_setrhook(res_send_rhook hook) {
_res.rhook = hook;
}
+#endif
int
res_isourserver(const struct sockaddr_in *inp) {
return (res_nsend(&_res, buf, buflen, ans, anssiz));
}
+#ifndef _LIBC
int
res_sendsigned(const u_char *buf, int buflen, ns_tsig_key *key,
u_char *ans, int anssiz)
return (res_nsendsigned(&_res, buf, buflen, key, ans, anssiz));
}
+#endif
void
res_close(void) {
answer, anslen));
}
+#ifdef _LIBC
+int
+res_opt(int n0, u_char *buf, int buflen, int anslen)
+{
+ return (res_nopt(&_res, n0, buf, buflen, anslen));
+}
+#endif
+
const char *
hostalias(const char *name) {
static char abuf[MAXDNAME];
}
#endif /*ultrix*/
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <resolv.h>.
+ */
+#undef res_init
+__weak_reference(__res_init, res_init);
+#undef p_query
+__weak_reference(__p_query, p_query);
+#undef res_mkquery
+__weak_reference(__res_mkquery, res_mkquery);
+#undef res_query
+__weak_reference(__res_query, res_query);
+#undef res_send
+__weak_reference(__res_send, res_send);
+#undef res_close
+__weak_reference(__res_close, _res_close);
+#undef res_search
+__weak_reference(__res_search, res_search);
+#undef res_querydomain
+__weak_reference(__res_querydomain, res_querydomain);
+#endif
+
#endif
-
/*! \file */
#include <math.h>
#include <netdb.h>
#include <resolv.h>
-#include <resolv_mt.h>
+#include "resolv_mt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
return (result);
}
+#ifdef _LIBC
+/*
+ * Weak aliases for applications that use certain private entry points,
+ * and fail to include <resolv.h>.
+ */
+#undef fp_resstat
+__weak_reference(__fp_resstat, fp_resstat);
+#undef p_fqnname
+__weak_reference(__p_fqnname, p_fqnname);
+#undef sym_ston
+__weak_reference(__sym_ston, sym_ston);
+#undef sym_ntos
+__weak_reference(__sym_ntos, sym_ntos);
+#undef sym_ntop
+__weak_reference(__sym_ntop, sym_ntop);
+#undef dn_count_labels
+__weak_reference(__dn_count_labels, dn_count_labels);
+#undef p_secstodate
+__weak_reference(__p_secstodate, p_secstodate);
+#endif
/*! \file */
#include <stdlib.h>
#include <string.h>
-#include <isc/list.h>
+#include "isc/list.h"
#include "port_after.h"
* keep going. for the NS and A queries this means we just give up.
*/
+#ifndef _LIBC
int
res_findzonecut(res_state statp, const char *dname, ns_class class, int opts,
char *zname, size_t zsize, struct in_addr *addrs, int naddrs)
free(u);
return (result);
}
-
+#endif
int
res_findzonecut2(res_state statp, const char *dname, ns_class class, int opts,
char *zname, size_t zsize, union res_sockaddr_union *addrs,
#include "port_before.h"
+#ifdef _LIBC
+#include "namespace.h"
+#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
+#ifdef _LIBC
+#include "un-namespace.h"
+#endif
#include "port_after.h"
{
const char *cp = options;
int i;
+#ifndef _LIBC
struct __res_state_ext *ext = statp->_u._ext.ext;
+#endif
#ifdef DEBUG
if (statp->options & RES_DEBUG)
statp->options |= RES_USE_EDNS0;
}
#endif
+#ifndef _LIBC
else if (!strncmp(cp, "dname", sizeof("dname") - 1)) {
statp->options |= RES_USE_DNAME;
}
~RES_NO_NIBBLE2;
}
}
+#endif
else {
/* XXX - print a warning here? */
}
+#ifndef _LIBC
skip:
+#endif
/* skip to next run of spaces */
while (*cp && *cp != ' ' && *cp != '\t')
cp++;
res_nclose(res_state statp) {
int ns;
- if (statp->_vcsock >= 0) {
+ if (statp->_vcsock >= 0) {
+#ifndef _LIBC
(void) close(statp->_vcsock);
+#else
+ _close(statp->_vcsock);
+#endif
statp->_vcsock = -1;
statp->_flags &= ~(RES_F_VC | RES_F_CONN);
}
for (ns = 0; ns < statp->_u._ext.nscount; ns++) {
if (statp->_u._ext.nssocks[ns] != -1) {
+#ifndef _LIBC
(void) close(statp->_u._ext.nssocks[ns]);
+#else
+ _close(statp->_u._ext.nssocks[ns]);
+#endif
statp->_u._ext.nssocks[ns] = -1;
}
}
statp->_u._ext.ext = NULL;
}
+#ifndef _LIBC
const char *
res_get_nibblesuffix(res_state statp) {
if (statp->_u._ext.ext)
return (statp->_u._ext.ext->nsuffix2);
return ("ip6.int");
}
+#endif
void
res_setservers(res_state statp, const union res_sockaddr_union *set, int cnt) {
}
return (statp->nscount);
}
-
/*! \file */
#include <unistd.h>
#include <ctype.h>
+#ifdef _LIBC
+#include "isc/list.h"
+#endif
#include "port_after.h"
/* Options. Leave them on. */
#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2);
/* Forward. */
-
+#ifdef _LIBC
+static
+#endif
int res_protocolnumber(const char *);
+#ifdef _LIBC
+static
+#endif
int res_servicenumber(const char *);
/*%
u_int16_t rtype, rclass;
u_int32_t n1, rttl;
u_char *dnptrs[20], **dpp, **lastdnptr;
- int siglen, keylen, certlen;
+#ifndef _LIBC
+ int siglen;
+#endif
+ int keylen, certlen;
/*
* Initialize header fields.
return (-1);
break;
case ns_t_sig:
+#ifdef _LIBC
+ return (-1);
+#else
{
int sig_type, success, dateerror;
u_int32_t exptime, timesigned;
cp += siglen;
break;
}
+#endif
case ns_t_key:
/* flags */
n = gethexnum_str(&startp, endp);
endservent();
}
+#ifndef _LIBC
void
res_destroyservicelist() {
struct valuelist *slp, *slp_next;
}
servicelist = (struct valuelist *)0;
}
+#endif
void
res_buildprotolist(void) {
endprotoent();
}
+#ifndef _LIBC
void
res_destroyprotolist(void) {
struct valuelist *plp, *plp_next;
}
protolist = (struct valuelist *)0;
}
+#endif
static int
findservice(const char *s, struct valuelist **list) {
/*%
* Convert service name or (ascii) number to int.
*/
+#ifdef _LIBC
+static
+#endif
int
res_servicenumber(const char *p) {
if (servicelist == (struct valuelist *)0)
/*%
* Convert protocol name or (ascii) number to int.
*/
+#ifdef _LIBC
+static
+#endif
int
res_protocolnumber(const char *p) {
if (protolist == (struct valuelist *)0)
return (findservice(p, &protolist));
}
+#ifndef _LIBC
static struct servent *
cgetservbyport(u_int16_t port, const char *proto) { /*%< Host byte order. */
struct valuelist **list = &servicelist;
}
return (ss->s_name);
}
+#endif /* !_LIBC */
*/
#include "port_before.h"
+#ifndef USE_KQUEUE
#include "fd_setsize.h"
+#endif
+#ifdef _LIBC
+#include "namespace.h"
+#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
#include <string.h>
#include <unistd.h>
-#include <isc/eventlib.h>
+#include "isc/eventlib.h"
#include "port_after.h"
+#ifdef USE_KQUEUE
+#include <sys/event.h>
+#else
#ifdef USE_POLL
#ifdef HAVE_STROPTS_H
#endif
#include <poll.h>
#endif /* USE_POLL */
+#endif
+
+#ifdef _LIBC
+#include "un-namespace.h"
+#endif
/* Options. Leave them on. */
#define DEBUG
#define EXT(res) ((res)->_u._ext)
-#ifndef USE_POLL
+#if !defined(USE_POLL) && !defined(USE_KQUEUE)
static const int highestFD = FD_SETSIZE - 1;
#else
static int highestFD = 0;
static struct sockaddr * get_nsaddr __P((res_state, size_t));
static int send_vc(res_state, const u_char *, int,
u_char *, int, int *, int);
-static int send_dg(res_state, const u_char *, int,
+static int send_dg(res_state,
+#ifdef USE_KQUEUE
+ int,
+#endif
+ const u_char *, int,
u_char *, int, int *, int, int,
int *, int *);
static void Aerror(const res_state, FILE *, const char *, int,
const struct sockaddr *, int);
static void Perror(const res_state, FILE *, const char *, int);
static int sock_eq(struct sockaddr *, struct sockaddr *);
-#if defined(NEED_PSELECT) && !defined(USE_POLL)
+#if defined(NEED_PSELECT) && !defined(USE_POLL) && !defined(USE_KQUEUE)
static int pselect(int, void *, void *, void *,
struct timespec *,
const sigset_t *);
const u_char *buf, int buflen, u_char *ans, int anssiz)
{
int gotsomewhere, terrno, tries, v_circuit, resplen, ns, n;
+#ifdef USE_KQUEUE
+ int kq;
+#endif
char abuf[NI_MAXHOST];
-#ifdef USE_POLL
+#ifdef USE_POLL
highestFD = sysconf(_SC_OPEN_MAX) - 1;
#endif
gotsomewhere = 0;
terrno = ETIMEDOUT;
+#ifdef USE_KQUEUE
+ if ((kq = kqueue()) < 0) {
+ Perror(statp, stderr, "kqueue", errno);
+ return (-1);
+ }
+#endif
+
/*
* If the ns_addr_list in the resolver context has changed, then
* invalidate our cached copy and the associated timing data.
if (EXT(statp).nssocks[ns] == -1)
continue;
peerlen = sizeof(peer);
+#ifndef _LIBC
if (getsockname(EXT(statp).nssocks[ns],
+#else
+ if (_getsockname(EXT(statp).nssocks[ns],
+#endif
(struct sockaddr *)&peer, &peerlen) < 0) {
needclose++;
break;
res_nclose(statp);
goto next_ns;
case res_done:
+#ifdef USE_KQUEUE
+ _close(kq);
+#endif
return (resplen);
case res_modified:
/* give the hook another try */
resplen = n;
} else {
/* Use datagrams. */
- n = send_dg(statp, buf, buflen, ans, anssiz, &terrno,
- ns, tries, &v_circuit, &gotsomewhere);
+ n = send_dg(statp,
+#ifdef USE_KQUEUE
+ kq,
+#endif
+ buf, buflen, ans, anssiz, &terrno,
+ ns, tries, &v_circuit, &gotsomewhere);
if (n < 0)
goto fail;
if (n == 0)
} while (!done);
}
+#ifdef USE_KQUEUE
+ _close(kq);
+#endif
return (resplen);
next_ns: ;
} /*foreach ns*/
} /*foreach retry*/
res_nclose(statp);
+#ifdef USE_KQUEUE
+ _close(kq);
+#endif
if (!v_circuit) {
if (!gotsomewhere)
errno = ECONNREFUSED; /*%< no nameservers found */
if (statp->_vcsock >= 0 && (statp->_flags & RES_F_VC) != 0) {
struct sockaddr_storage peer;
ISC_SOCKLEN_T size = sizeof peer;
-
+#ifndef _LIBC
if (getpeername(statp->_vcsock,
+#else
+ if (_getpeername(statp->_vcsock,
+#endif
(struct sockaddr *)&peer, &size) < 0 ||
!sock_eq((struct sockaddr *)&peer, nsap)) {
res_nclose(statp);
if (statp->_vcsock < 0 || (statp->_flags & RES_F_VC) == 0) {
if (statp->_vcsock >= 0)
res_nclose(statp);
-
+#ifndef _LIBC
statp->_vcsock = socket(nsap->sa_family, SOCK_STREAM, 0);
+#else
+ statp->_vcsock = _socket(nsap->sa_family, SOCK_STREAM, 0);
+#endif
+#if !defined(USE_POLL) && !defined(USE_KQUEUE)
if (statp->_vcsock > highestFD) {
res_nclose(statp);
errno = ENOTSOCK;
}
+#endif
if (statp->_vcsock < 0) {
switch (errno) {
case EPROTONOSUPPORT:
sizeof(on));
#endif
errno = 0;
+#ifndef _LIBC
if (connect(statp->_vcsock, nsap, nsaplen) < 0) {
+#else
+ if (_connect(statp->_vcsock, nsap, nsaplen) < 0) {
+#endif
*terrno = errno;
Aerror(statp, stderr, "connect/vc", errno, nsap,
nsaplen);
iov[0] = evConsIovec(&len, INT16SZ);
DE_CONST(buf, tmp);
iov[1] = evConsIovec(tmp, buflen);
+#ifndef _LIBC
if (writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
+#else
+ if (_writev(statp->_vcsock, iov, 2) != (INT16SZ + buflen)) {
+#endif
*terrno = errno;
Perror(statp, stderr, "write failed", errno);
res_nclose(statp);
read_len:
cp = ans;
len = INT16SZ;
+#ifndef _LIBC
while ((n = read(statp->_vcsock, (char *)cp, (int)len)) > 0) {
+#else
+ while ((n = _read(statp->_vcsock, (char *)cp, (int)len)) > 0) {
+#endif
cp += n;
if ((len -= n) == 0)
break;
return (0);
}
cp = ans;
+#ifndef _LIBC
while (len != 0 && (n = read(statp->_vcsock, (char *)cp, (int)len)) > 0){
+#else
+ while (len != 0 && (n = _read(statp->_vcsock, (char *)cp, (int)len)) > 0){
+#endif
cp += n;
len -= n;
}
while (len != 0) {
char junk[PACKETSZ];
+#ifndef _LIBC
n = read(statp->_vcsock, junk,
+#else
+ n = _read(statp->_vcsock, junk,
+#endif
(len > sizeof junk) ? sizeof junk : len);
if (n > 0)
len -= n;
}
static int
-send_dg(res_state statp, const u_char *buf, int buflen, u_char *ans,
+send_dg(res_state statp,
+#ifdef USE_KQUEUE
+ int kq,
+#endif
+ const u_char *buf, int buflen, u_char *ans,
int anssiz, int *terrno, int ns, int tries, int *v_circuit,
int *gotsomewhere)
{
struct sockaddr_storage from;
ISC_SOCKLEN_T fromlen;
int resplen, seconds, n, s;
+#ifdef USE_KQUEUE
+ struct kevent kv;
+#else
#ifdef USE_POLL
int polltimeout;
struct pollfd pollfd;
#else
fd_set dsmask;
#endif
+#endif
nsap = get_nsaddr(statp, ns);
nsaplen = get_salen(nsap);
if (EXT(statp).nssocks[ns] == -1) {
+#ifndef _LIBC
EXT(statp).nssocks[ns] = socket(nsap->sa_family, SOCK_DGRAM, 0);
+#else
+ EXT(statp).nssocks[ns] = _socket(nsap->sa_family, SOCK_DGRAM, 0);
+#endif
+#if !defined(USE_POLL) && !defined(USE_KQUEUE)
if (EXT(statp).nssocks[ns] > highestFD) {
res_nclose(statp);
errno = ENOTSOCK;
}
+#endif
if (EXT(statp).nssocks[ns] < 0) {
switch (errno) {
case EPROTONOSUPPORT:
* socket operation, and select returns if the
* error message is received. We can thus detect
* the absence of a nameserver without timing out.
- */
- if (connect(EXT(statp).nssocks[ns], nsap, nsaplen) < 0) {
+ *
+ *
+ * When the option "insecure1" is specified, we'd
+ * rather expect to see responses from an "unknown"
+ * address. In order to let the kernel accept such
+ * responses, do not connect the socket here.
+ * XXX: or do we need an explicit option to disable
+ * connecting?
+ */
+ if (!(statp->options & RES_INSECURE1) &&
+#ifndef _LIBC
+ connect(EXT(statp).nssocks[ns], nsap, nsaplen) < 0) {
+#else
+ _connect(EXT(statp).nssocks[ns], nsap, nsaplen) < 0) {
+#endif
Aerror(statp, stderr, "connect(dg)", errno, nsap,
nsaplen);
res_nclose(statp);
}
s = EXT(statp).nssocks[ns];
#ifndef CANNOT_CONNECT_DGRAM
- if (send(s, (const char*)buf, buflen, 0) != buflen) {
+ if (statp->options & RES_INSECURE1) {
+#ifndef _LIBC
+ if (sendto(s,
+#else
+ if (_sendto(s,
+#endif
+ (const char*)buf, buflen, 0, nsap, nsaplen) != buflen) {
+ Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
+ res_nclose(statp);
+ return (0);
+ }
+ } else if (send(s, (const char*)buf, buflen, 0) != buflen) {
Perror(statp, stderr, "send", errno);
res_nclose(statp);
return (0);
}
#else /* !CANNOT_CONNECT_DGRAM */
+#ifndef _LIBC
if (sendto(s, (const char*)buf, buflen, 0, nsap, nsaplen) != buflen)
+#else
+ if (_sendto(s, (const char*)buf, buflen, 0, nsap, nsaplen) != buflen)
+#endif
{
Aerror(statp, stderr, "sendto", errno, nsap, nsaplen);
res_nclose(statp);
now = evNowTime();
nonow:
#ifndef USE_POLL
- FD_ZERO(&dsmask);
- FD_SET(s, &dsmask);
if (evCmpTime(finish, now) > 0)
timeout = evSubTime(finish, now);
else
timeout = evConsTime(0, 0);
+#ifdef USE_KQUEUE
+ EV_SET(&kv, s, EVFILT_READ, EV_ADD | EV_ONESHOT, 0, 0, 0);
+ n = _kevent(kq, &kv, 1, &kv, 1, &timeout);
+#else
+ FD_ZERO(&dsmask);
+ FD_SET(s, &dsmask);
n = pselect(s + 1, &dsmask, NULL, NULL, &timeout, NULL);
+#endif
#else
timeout = evSubTime(finish, now);
if (timeout.tv_sec < 0)
if (n < 0) {
if (errno == EINTR)
goto wait;
+#ifdef USE_KQUEUE
+ Perror(statp, stderr, "kevent", errno);
+#else
#ifndef USE_POLL
Perror(statp, stderr, "select", errno);
#else
Perror(statp, stderr, "poll", errno);
#endif /* USE_POLL */
+#endif
res_nclose(statp);
return (0);
}
+#ifdef USE_KQUEUE
+ if (kv.ident != s)
+ goto wait;
+#endif
errno = 0;
fromlen = sizeof(from);
+#ifndef _LIBC
resplen = recvfrom(s, (char*)ans, anssiz,0,
+#else
+ resplen = _recvfrom(s, (char*)ans, anssiz,0,
+#endif
(struct sockaddr *)&from, &fromlen);
if (resplen <= 0) {
Perror(statp, stderr, "recvfrom", errno);
}
}
-#if defined(NEED_PSELECT) && !defined(USE_POLL)
+#if defined(NEED_PSELECT) && !defined(USE_POLL) && !defined(USE_KQUEUE)
/* XXX needs to move to the porting library. */
static int
pselect(int nfds, void *rfds, void *wfds, void *efds,
#include <stdlib.h>
#include <string.h>
-#include <isc/list.h>
+#include "isc/list.h"
#include <resolv.h>
#include "port_after.h"
/* Send the update and remember the result. */
if (key != NULL)
+#ifdef _LIBC
+ {
+ DPRINTF(("TSIG is not supported\n"));
+ RES_SET_H_ERRNO(statp, NO_RECOVERY);
+ goto done;
+ }
+#else
n = res_nsendsigned(statp, packet, n, key,
answer, sizeof answer);
+#endif
else
n = res_nsend(statp, packet, n, answer, sizeof answer);
if (n < 0) {