Add bind9_getaddresses(), a consistent version of the get_address function
from dig/host/nslookup, nsupdate, and rndc. This should make it easier to have the various programs support multiple addresses for a hostname.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.27 2001/11/06 20:04:59 bwelling Exp $
|
||||
# $Id: Makefile.in,v 1.28 2001/11/14 22:08:26 bwelling Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
@@ -23,20 +23,23 @@ top_srcdir = @top_srcdir@
|
||||
|
||||
@BIND9_MAKE_INCLUDES@
|
||||
|
||||
CINCLUDES = -I${srcdir}/include ${DNS_INCLUDES} ${ISC_INCLUDES}
|
||||
CINCLUDES = -I${srcdir}/include ${DNS_INCLUDES} ${BIND9_INCLUDES} \
|
||||
${ISC_INCLUDES}
|
||||
|
||||
CDEFINES = -DVERSION=\"${VERSION}\"
|
||||
CWARNINGS =
|
||||
|
||||
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
|
||||
BIND9LIBS = ../../lib/bind9/libbind9.@A@
|
||||
ISCLIBS = ../../lib/isc/libisc.@A@
|
||||
|
||||
DNSDEPLIBS = ../../lib/dns/libdns.@A@
|
||||
BIND9DEPLIBS = ../../lib/bind9/libbind9.@A@
|
||||
ISCDEPLIBS = ../../lib/isc/libisc.@A@
|
||||
|
||||
DEPLIBS = ${DNSDEPLIBS} ${ISCDEPLIBS}
|
||||
DEPLIBS = ${DNSDEPLIBS} ${BIND9DEPLIBS} ${ISCDEPLIBS}
|
||||
|
||||
LIBS = ${DNSLIBS} ${ISCLIBS} @LIBS@
|
||||
LIBS = ${DNSLIBS} ${BIND9LIBS} ${ISCLIBS} @LIBS@
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dighost.c,v 1.235 2001/11/14 06:31:38 marka Exp $ */
|
||||
/* $Id: dighost.c,v 1.236 2001/11/14 22:08:28 bwelling Exp $ */
|
||||
|
||||
/*
|
||||
* Notice to programmers: Do not use this code as an example of how to
|
||||
@@ -52,7 +52,6 @@
|
||||
#include <isc/entropy.h>
|
||||
#include <isc/lang.h>
|
||||
#include <isc/netaddr.h>
|
||||
#include <isc/netdb.h>
|
||||
#include <isc/print.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/string.h>
|
||||
@@ -61,22 +60,10 @@
|
||||
#include <isc/types.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <bind9/getaddresses.h>
|
||||
|
||||
#include <dig/dig.h>
|
||||
|
||||
#ifdef HAVE_ADDRINFO
|
||||
#ifdef HAVE_GETADDRINFO
|
||||
#ifdef HAVE_GAISTRERROR
|
||||
#define USE_GETADDRINFO
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef USE_GETADDRINFO
|
||||
#ifndef ISC_PLATFORM_NONSTDHERRNO
|
||||
extern int h_errno;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ISC_LIST(dig_lookup_t) lookup_list;
|
||||
dig_serverlist_t server_list;
|
||||
ISC_LIST(dig_searchlist_t) search_list;
|
||||
@@ -2418,61 +2405,16 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
||||
*/
|
||||
void
|
||||
get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr) {
|
||||
struct in_addr in4;
|
||||
struct in6_addr in6;
|
||||
#ifdef USE_GETADDRINFO
|
||||
struct addrinfo *res = NULL, hints;
|
||||
int result;
|
||||
#else
|
||||
struct hostent *he;
|
||||
#endif
|
||||
int count;
|
||||
isc_result_t result;
|
||||
|
||||
debug("get_address()");
|
||||
|
||||
if (inet_pton(AF_INET6, host, &in6) == 1) {
|
||||
if (!have_ipv6)
|
||||
fatal("protocol family INET6 not supported '%s'", host);
|
||||
isc_sockaddr_fromin6(sockaddr, &in6, port);
|
||||
} else if (inet_pton(AF_INET, host, &in4) == 1) {
|
||||
if (have_ipv4)
|
||||
isc_sockaddr_fromin(sockaddr, &in4, port);
|
||||
else
|
||||
isc_sockaddr_v6fromin(sockaddr, &in4, port);
|
||||
} else {
|
||||
#ifdef USE_GETADDRINFO
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
if (!have_ipv6)
|
||||
hints.ai_family = PF_INET;
|
||||
else if (!have_ipv4)
|
||||
hints.ai_family = PF_INET6;
|
||||
else
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
debug ("before getaddrinfo()");
|
||||
isc_app_block();
|
||||
result = getaddrinfo(host, NULL, &hints, &res);
|
||||
isc_app_unblock();
|
||||
if (result != 0) {
|
||||
fatal("couldn't find server '%s': %s",
|
||||
host, gai_strerror(result));
|
||||
}
|
||||
memcpy(&sockaddr->type.sa, res->ai_addr, res->ai_addrlen);
|
||||
sockaddr->length = res->ai_addrlen;
|
||||
isc_sockaddr_setport(sockaddr, port);
|
||||
freeaddrinfo(res);
|
||||
#else
|
||||
debug ("before gethostbyname()");
|
||||
isc_app_block();
|
||||
he = gethostbyname(host);
|
||||
isc_app_unblock();
|
||||
if (he == NULL)
|
||||
fatal("couldn't find server '%s' (h_errno=%d)",
|
||||
host, h_errno);
|
||||
INSIST(he->h_addrtype == AF_INET);
|
||||
isc_sockaddr_fromin(sockaddr,
|
||||
(struct in_addr *)(he->h_addr_list[0]),
|
||||
port);
|
||||
#endif
|
||||
}
|
||||
isc_app_block();
|
||||
result = bind9_getaddresses(host, port, sockaddr, 1, &count);
|
||||
isc_app_unblock();
|
||||
if (result != ISC_R_SUCCESS)
|
||||
fatal("couldn't get address for '%s': %s",
|
||||
host, isc_result_totext(result));
|
||||
INSIST(count == 1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dnssec-signzone.c,v 1.150 2001/10/26 21:08:03 bwelling Exp $ */
|
||||
/* $Id: dnssec-signzone.c,v 1.151 2001/11/14 22:08:29 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@@ -1505,7 +1505,7 @@ main(int argc, char *argv[]) {
|
||||
int tempfilelen;
|
||||
dns_rdataclass_t rdclass;
|
||||
isc_task_t **tasks = NULL;
|
||||
masterstyle = &dns_master_style_explicitttl;
|
||||
masterstyle = &dns_master_style_simple;
|
||||
|
||||
check_result(isc_app_start(), "isc_app_start");
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.17 2001/11/06 20:05:02 bwelling Exp $
|
||||
# $Id: Makefile.in,v 1.18 2001/11/14 22:08:30 bwelling Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
@@ -23,22 +23,25 @@ top_srcdir = @top_srcdir@
|
||||
|
||||
@BIND9_MAKE_INCLUDES@
|
||||
|
||||
CINCLUDES = ${LWRES_INCLUDES} ${DNS_INCLUDES} ${ISC_INCLUDES}
|
||||
CINCLUDES = ${LWRES_INCLUDES} ${DNS_INCLUDES} ${BIND9_INCLUDES} \
|
||||
${ISC_INCLUDES}
|
||||
|
||||
CDEFINES =
|
||||
CWARNINGS =
|
||||
|
||||
LWRESLIBS = ../../lib/lwres/liblwres.@A@
|
||||
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
|
||||
BIND9LIBS = ../../lib/bind9/libbind9.@A@
|
||||
ISCLIBS = ../../lib/isc/libisc.@A@
|
||||
|
||||
LWRESDEPLIBS = ../../lib/lwres/liblwres.@A@
|
||||
DNSDEPLIBS = ../../lib/dns/libdns.@A@
|
||||
BIND9DEPLIBS = ../../lib/bind9/libbind9.@A@
|
||||
ISCDEPLIBS = ../../lib/isc/libisc.@A@
|
||||
|
||||
DEPLIBS = ${DNSDEPLIBS} ${ISCDEPLIBS}
|
||||
DEPLIBS = ${DNSDEPLIBS} ${BIND9DEPLIBS} ${ISCDEPLIBS}
|
||||
|
||||
LIBS = ${LWRESLIBS} ${DNSLIBS} ${ISCLIBS} @LIBS@
|
||||
LIBS = ${LWRESLIBS} ${DNSLIBS} ${BIND9LIBS} ${ISCLIBS} @LIBS@
|
||||
|
||||
SUBDIRS =
|
||||
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: nsupdate.c,v 1.112 2001/11/07 04:44:09 marka Exp $ */
|
||||
/* $Id: nsupdate.c,v 1.113 2001/11/14 22:08:32 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <netdb.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@@ -66,6 +65,8 @@
|
||||
#include <lwres/lwres.h>
|
||||
#include <lwres/net.h>
|
||||
|
||||
#include <bind9/getaddresses.h>
|
||||
|
||||
#ifdef HAVE_ADDRINFO
|
||||
#ifdef HAVE_GETADDRINFO
|
||||
#ifdef HAVE_GAISTRERROR
|
||||
@@ -567,60 +568,16 @@ setup_system(void) {
|
||||
|
||||
static void
|
||||
get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr) {
|
||||
struct in_addr in4;
|
||||
struct in6_addr in6;
|
||||
#ifdef USE_GETADDRINFO
|
||||
struct addrinfo *res = NULL, hints;
|
||||
int result;
|
||||
#else
|
||||
struct hostent *he;
|
||||
#endif
|
||||
int count;
|
||||
isc_result_t result;
|
||||
|
||||
ddebug("get_address()");
|
||||
|
||||
/*
|
||||
* Assume we have v4 if we don't have v6, since setup_libs
|
||||
* fatal()'s out if we don't have either.
|
||||
*/
|
||||
if (have_ipv6 && inet_pton(AF_INET6, host, &in6) == 1)
|
||||
isc_sockaddr_fromin6(sockaddr, &in6, port);
|
||||
else if (inet_pton(AF_INET, host, &in4) == 1)
|
||||
isc_sockaddr_fromin(sockaddr, &in4, port);
|
||||
else {
|
||||
#ifdef USE_GETADDRINFO
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
if (!have_ipv6)
|
||||
hints.ai_family = PF_INET;
|
||||
else if (!have_ipv4)
|
||||
hints.ai_family = PF_INET6;
|
||||
else
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
debug ("before getaddrinfo()");
|
||||
isc_app_block();
|
||||
result = getaddrinfo(host, NULL, &hints, &res);
|
||||
isc_app_unblock();
|
||||
if (result != 0) {
|
||||
fatal("couldn't find server '%s': %s",
|
||||
host, gai_strerror(result));
|
||||
}
|
||||
memcpy(&sockaddr->type.sa,res->ai_addr, res->ai_addrlen);
|
||||
sockaddr->length = res->ai_addrlen;
|
||||
isc_sockaddr_setport(sockaddr, port);
|
||||
freeaddrinfo(res);
|
||||
#else
|
||||
debug ("before gethostbyname()");
|
||||
isc_app_block();
|
||||
he = gethostbyname(host);
|
||||
isc_app_unblock();
|
||||
if (he == NULL)
|
||||
fatal("couldn't find server '%s' (h_errno=%d)",
|
||||
host, h_errno);
|
||||
INSIST(he->h_addrtype == AF_INET);
|
||||
isc_sockaddr_fromin(sockaddr,
|
||||
(struct in_addr *)(he->h_addr_list[0]),
|
||||
port);
|
||||
#endif
|
||||
}
|
||||
isc_app_block();
|
||||
result = bind9_getaddresses(host, port, sockaddr, 1, &count);
|
||||
isc_app_unblock();
|
||||
if (result != ISC_R_SUCCESS)
|
||||
fatal("couldn't get address for '%s': %s",
|
||||
host, isc_result_totext(result));
|
||||
INSIST(count == 1);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.35 2001/11/06 20:05:04 bwelling Exp $
|
||||
# $Id: Makefile.in,v 1.36 2001/11/14 22:08:33 bwelling Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
@@ -24,7 +24,7 @@ top_srcdir = @top_srcdir@
|
||||
@BIND9_MAKE_INCLUDES@
|
||||
|
||||
CINCLUDES = -I${srcdir}/include ${ISC_INCLUDES} ${ISCCC_INCLUDES} \
|
||||
${ISCCFG_INCLUDES} ${DNS_INCLUDES}
|
||||
${ISCCFG_INCLUDES} ${DNS_INCLUDES} ${BIND9_INCLUDES}
|
||||
|
||||
CDEFINES =
|
||||
CWARNINGS =
|
||||
@@ -33,14 +33,16 @@ ISCCFGLIBS = ../../lib/isccfg/libisccfg.@A@
|
||||
ISCCCLIBS = ../../lib/isccc/libisccc.@A@
|
||||
ISCLIBS = ../../lib/isc/libisc.@A@
|
||||
DNSLIBS = ../../lib/dns/libdns.@A@ @DNS_CRYPTO_LIBS@
|
||||
BIND9LIBS = ../../lib/bind9/libbind9.@A@
|
||||
|
||||
ISCCFGDEPLIBS = ../../lib/isccfg/libisccfg.@A@
|
||||
ISCCCDEPLIBS = ../../lib/isccc/libisccc.@A@
|
||||
ISCDEPLIBS = ../../lib/isc/libisc.@A@
|
||||
DNSDEPLIBS = ../../lib/dns/libdns.@A@
|
||||
BIND9DEPLIBS = ../../lib/bind9/libbind9.@A@
|
||||
|
||||
RNDCLIBS = ${ISCCFGLIBS} ${ISCCCLIBS} ${ISCLIBS} @LIBS@
|
||||
RNDCDEPLIBS = ${ISCCFGDEPLIBS} ${ISCCCDEPLIBS} ${ISCDEPLIBS}
|
||||
RNDCLIBS = ${ISCCFGLIBS} ${ISCCCLIBS} ${BIND9LIBS} ${ISCLIBS} @LIBS@
|
||||
RNDCDEPLIBS = ${ISCCFGDEPLIBS} ${ISCCCDEPLIBS} ${BIND9DEPLIBS} ${ISCDEPLIBS}
|
||||
|
||||
CONFLIBS = ${DNSLIBS} ${ISCLIBS} @LIBS@
|
||||
CONFDEPLIBS = ${DNSDEPLIBS} ${ISCDEPLIBS}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: rndc.c,v 1.81 2001/11/14 06:42:46 marka Exp $ */
|
||||
/* $Id: rndc.c,v 1.82 2001/11/14 22:08:34 bwelling Exp $ */
|
||||
|
||||
/*
|
||||
* Principal Author: DCL
|
||||
@@ -31,7 +31,6 @@
|
||||
#include <isc/file.h>
|
||||
#include <isc/log.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/netdb.h>
|
||||
#include <isc/socket.h>
|
||||
#include <isc/stdtime.h>
|
||||
#include <isc/string.h>
|
||||
@@ -50,22 +49,10 @@
|
||||
#include <isccc/types.h>
|
||||
#include <isccc/util.h>
|
||||
|
||||
#include <bind9/getaddresses.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#ifdef HAVE_ADDRINFO
|
||||
#ifdef HAVE_GETADDRINFO
|
||||
#ifdef HAVE_GAISTRERROR
|
||||
#define USE_GETADDRINFO
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef USE_GETADDRINFO
|
||||
#ifndef ISC_PLATFORM_NONSTDHERRNO
|
||||
extern int h_errno;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
char *progname;
|
||||
isc_boolean_t verbose;
|
||||
|
||||
@@ -124,59 +111,16 @@ Version: %s\n",
|
||||
|
||||
static void
|
||||
get_address(const char *host, in_port_t port, isc_sockaddr_t *sockaddr) {
|
||||
struct in_addr in4;
|
||||
struct in6_addr in6;
|
||||
isc_boolean_t have_ipv6;
|
||||
#ifdef USE_GETADDRINFO
|
||||
struct addrinfo *res = NULL, hints;
|
||||
int result;
|
||||
#else
|
||||
struct hostent *he;
|
||||
#endif
|
||||
int count;
|
||||
isc_result_t result;
|
||||
|
||||
have_ipv6 = ISC_TF(isc_net_probeipv6() == ISC_R_SUCCESS);
|
||||
|
||||
/*
|
||||
* Assume we have v4 if we don't have v6, since setup_libs
|
||||
* fatal()'s out if we don't have either.
|
||||
*/
|
||||
if (have_ipv6 && inet_pton(AF_INET6, host, &in6) == 1)
|
||||
isc_sockaddr_fromin6(sockaddr, &in6, port);
|
||||
else if (inet_pton(AF_INET, host, &in4) == 1)
|
||||
isc_sockaddr_fromin(sockaddr, &in4, port);
|
||||
else {
|
||||
#ifdef USE_GETADDRINFO
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
if (!have_ipv6)
|
||||
hints.ai_family = PF_INET;
|
||||
else if (isc_net_probeipv4() != ISC_R_SUCCESS)
|
||||
hints.ai_family = PF_INET6;
|
||||
else
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
isc_app_block();
|
||||
result = getaddrinfo(host, NULL, &hints, &res);
|
||||
isc_app_unblock();
|
||||
if (result != 0)
|
||||
fatal("Couldn't find server '%s': %s",
|
||||
host, gai_strerror(result));
|
||||
memcpy(&sockaddr->type.sa, res->ai_addr, res->ai_addrlen);
|
||||
sockaddr->length = res->ai_addrlen;
|
||||
isc_sockaddr_setport(sockaddr, port);
|
||||
freeaddrinfo(res);
|
||||
#else
|
||||
isc_app_block();
|
||||
he = gethostbyname(host);
|
||||
isc_app_unblock();
|
||||
if (he == NULL)
|
||||
fatal("Couldn't find server '%s' (h_errno=%d)",
|
||||
host, h_errno);
|
||||
INSIST(he->h_addrtype == AF_INET);
|
||||
isc_sockaddr_fromin(sockaddr,
|
||||
(struct in_addr *)(he->h_addr_list[0]),
|
||||
port);
|
||||
#endif
|
||||
}
|
||||
isc_app_block();
|
||||
result = bind9_getaddresses(host, port, sockaddr, 1, &count);
|
||||
isc_app_unblock();
|
||||
if (result != ISC_R_SUCCESS)
|
||||
fatal("couldn't get address for '%s': %s",
|
||||
host, isc_result_totext(result));
|
||||
INSIST(count == 1);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.1 2001/09/20 15:17:06 marka Exp $
|
||||
# $Id: Makefile.in,v 1.2 2001/11/14 22:08:35 bwelling Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
@@ -36,10 +36,10 @@ LIBS = @LIBS@
|
||||
SUBDIRS = include
|
||||
|
||||
# Alphabetically
|
||||
OBJS = check.@O@ version.@O@
|
||||
OBJS = check.@O@ getaddresses.@O@ version.@O@
|
||||
|
||||
# Alphabetically
|
||||
SRCS = check.c version.c
|
||||
SRCS = check.c getaddresses.c version.c
|
||||
|
||||
TARGETS = timestamp
|
||||
|
||||
|
||||
162
lib/bind9/getaddresses.c
Normal file
162
lib/bind9/getaddresses.c
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: getaddresses.c,v 1.1 2001/11/14 22:08:37 bwelling Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <isc/net.h>
|
||||
#include <isc/netaddr.h>
|
||||
#include <isc/netdb.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/sockaddr.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#include <bind9/getaddresses.h>
|
||||
|
||||
#ifdef HAVE_ADDRINFO
|
||||
#ifdef HAVE_GETADDRINFO
|
||||
#ifdef HAVE_GAISTRERROR
|
||||
#define USE_GETADDRINFO
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef USE_GETADDRINFO
|
||||
#ifndef ISC_PLATFORM_NONSTDHERRNO
|
||||
extern int h_errno;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
isc_result_t
|
||||
bind9_getaddresses(const char *hostname, in_port_t port,
|
||||
isc_sockaddr_t *addrs, int addrsize, int *addrcount)
|
||||
{
|
||||
struct in_addr in4;
|
||||
struct in6_addr in6;
|
||||
isc_boolean_t have_ipv4, have_ipv6;
|
||||
int i;
|
||||
|
||||
#ifdef USE_GETADDRINFO
|
||||
struct addrinfo *ai = NULL, *tmpai, hints;
|
||||
int result;
|
||||
#else
|
||||
struct hostent *he;
|
||||
#endif
|
||||
|
||||
REQUIRE(hostname != NULL);
|
||||
REQUIRE(addrs != NULL);
|
||||
REQUIRE(addrcount != NULL);
|
||||
REQUIRE(addrsize > 0);
|
||||
|
||||
have_ipv4 = (isc_net_probeipv4() == ISC_R_SUCCESS);
|
||||
have_ipv6 = (isc_net_probeipv6() == ISC_R_SUCCESS);
|
||||
|
||||
if (inet_pton(AF_INET6, hostname, &in6) == 1) {
|
||||
if (!have_ipv6)
|
||||
return (ISC_R_FAMILYNOSUPPORT);
|
||||
isc_sockaddr_fromin6(&addrs[0], &in6, port);
|
||||
*addrcount = 1;
|
||||
return (ISC_R_SUCCESS);
|
||||
} else if (inet_pton(AF_INET, hostname, &in4) == 1) {
|
||||
if (have_ipv4)
|
||||
isc_sockaddr_fromin(&addrs[0], &in4, port);
|
||||
else
|
||||
isc_sockaddr_v6fromin(&addrs[0], &in4, port);
|
||||
*addrcount = 1;
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
#ifdef USE_GETADDRINFO
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
if (!have_ipv6)
|
||||
hints.ai_family = PF_INET;
|
||||
else if (!have_ipv4)
|
||||
hints.ai_family = PF_INET6;
|
||||
else
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
result = getaddrinfo(hostname, NULL, &hints, &ai);
|
||||
switch (result) {
|
||||
case 0:
|
||||
break;
|
||||
case EAI_NONAME:
|
||||
case EAI_NODATA:
|
||||
return (ISC_R_NOTFOUND);
|
||||
default:
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
for (tmpai = ai, i = 0;
|
||||
tmpai != NULL && i < addrsize;
|
||||
tmpai = tmpai->ai_next)
|
||||
{
|
||||
if (tmpai->ai_family != AF_INET &&
|
||||
tmpai->ai_family != AF_INET6)
|
||||
continue;
|
||||
if (tmpai->ai_family == AF_INET) {
|
||||
struct sockaddr_in *sin;
|
||||
sin = (struct sockaddr_in *)tmpai->ai_addr;
|
||||
isc_sockaddr_fromin(&addrs[i], &sin->sin_addr, port);
|
||||
} else {
|
||||
struct sockaddr_in6 *sin6;
|
||||
sin6 = (struct sockaddr_in6 *)tmpai->ai_addr;
|
||||
isc_sockaddr_fromin6(&addrs[i], &sin6->sin6_addr,
|
||||
port);
|
||||
}
|
||||
i++;
|
||||
|
||||
}
|
||||
freeaddrinfo(ai);
|
||||
*addrcount = i;
|
||||
#else
|
||||
he = gethostbyname(hostname);
|
||||
if (he == NULL) {
|
||||
switch (h_errno) {
|
||||
case HOST_NOT_FOUND:
|
||||
case NO_ADDRESS:
|
||||
case NO_DATA:
|
||||
return (ISC_R_NOTFOUND);
|
||||
default:
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
}
|
||||
if (he->h_addrtype != AF_INET && h_addrtype != AF_INET6) {
|
||||
freehostent(he);
|
||||
return (ISC_R_NOTFOUND);
|
||||
}
|
||||
for (i = 0; i < addrsize; i++) {
|
||||
if (he->h_addrtype == AF_INET) {
|
||||
struct in_addr_t *inp;
|
||||
inp = (struct in_addr *)(he->h_addr_list[i]);
|
||||
if (inp == NULL)
|
||||
break;
|
||||
isc_sockaddr_fromin(&addrs[i], inp, port);
|
||||
} else {
|
||||
struct in6_addr_t *in6p;
|
||||
in6p = (struct in6_addr *)(he->h_addr_list[i]);
|
||||
if (in6p == NULL)
|
||||
break;
|
||||
isc_sockaddr_fromin6(&addrs[i], in6p, port);
|
||||
}
|
||||
}
|
||||
freehostent(he);
|
||||
*addrcount = i;
|
||||
#endif
|
||||
if (*addrcount == 0)
|
||||
return (ISC_R_NOTFOUND);
|
||||
else
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
# $Id: Makefile.in,v 1.4 2001/10/16 23:20:50 gson Exp $
|
||||
# $Id: Makefile.in,v 1.5 2001/11/14 22:08:37 bwelling Exp $
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
@@ -26,7 +26,7 @@ top_srcdir = @top_srcdir@
|
||||
# machine generated. The latter are handled specially in the
|
||||
# install target below.
|
||||
#
|
||||
HEADERS = check.h version.h
|
||||
HEADERS = check.h getaddresses.h version.h
|
||||
|
||||
SUBDIRS =
|
||||
TARGETS =
|
||||
|
||||
59
lib/bind9/include/bind9/getaddresses.h
Normal file
59
lib/bind9/include/bind9/getaddresses.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2001 Internet Software Consortium.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
|
||||
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
||||
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
||||
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: getaddresses.h,v 1.1 2001/11/14 22:08:38 bwelling Exp $ */
|
||||
|
||||
#ifndef BIND9_GETADDRESSES_H
|
||||
#define BIND9_GETADDRESSES_H 1
|
||||
|
||||
#include <isc/lang.h>
|
||||
#include <isc/types.h>
|
||||
|
||||
#include <isccfg/cfg.h>
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
isc_result_t
|
||||
bind9_getaddresses(const char *hostname, in_port_t port,
|
||||
isc_sockaddr_t *addrs, int addrsize, int *addrcount);
|
||||
/*
|
||||
* Use the system resolver to get the addresses associated with a hostname.
|
||||
* If successful, the number of addresses found is returned in 'addrcount'.
|
||||
* If a hostname lookup is performed and addresses of an unknown family is
|
||||
* seen, it is ignored. If more than 'addrsize' addresses are seen, the
|
||||
* first 'addrsize' are returned and the remainder silently truncated.
|
||||
*
|
||||
* This routine may block. If called by a program using the isc_app
|
||||
* framework, it should be surounded by isc_app_block()/isc_app_unblock().
|
||||
*
|
||||
* Requires:
|
||||
* 'hostname' is not NULL.
|
||||
* 'addrs' is not NULL.
|
||||
* 'addrsize' > 0
|
||||
* 'addrcount' is not NULL.
|
||||
*
|
||||
*
|
||||
* Returns:
|
||||
* ISC_R_SUCCESS
|
||||
* ISC_R_NOTFOUND
|
||||
* ISC_R_NOFAMILYSUPPORT - 'hostname' is an IPv6 address, and IPv6 is
|
||||
* not supported.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
#endif /* BIND9_GETADDRESSES_H */
|
||||
@@ -1524,7 +1524,12 @@
|
||||
./lib/bind/resolv/res_send.c X 2001
|
||||
./lib/bind/resolv/res_sendsigned.c X 2001
|
||||
./lib/bind/resolv/res_update.c X 2001
|
||||
./lib/bind9/check.c C 2001
|
||||
./lib/bind9/getaddresses.c C 2001
|
||||
./lib/bind9/include/bind9/check.h C 2001
|
||||
./lib/bind9/include/bind9/getaddresses.h C 2001
|
||||
./lib/bind9/include/bind9/version.h C 2001
|
||||
./lib/bind9/version.c C 2001
|
||||
./lib/dns/.cvsignore X 1999,2000,2001
|
||||
./lib/dns/Makefile.in MAKE 1998,1999,2000,2001
|
||||
./lib/dns/a6.c C 1999,2000,2001
|
||||
|
||||
Reference in New Issue
Block a user