summaryrefslogtreecommitdiffstats
path: root/libisc
diff options
context:
space:
mode:
Diffstat (limited to 'libisc')
-rw-r--r--libisc/assertions.c93
-rw-r--r--libisc/error.c101
-rw-r--r--libisc/ifiter_getifaddrs.c191
-rw-r--r--libisc/ifiter_ioctl.c1118
-rw-r--r--libisc/ifiter_sysctl.c315
-rw-r--r--libisc/inet_aton.c195
-rw-r--r--libisc/inet_ntop.c198
-rw-r--r--libisc/inet_pton.c211
-rw-r--r--libisc/interfaceiter.c220
-rw-r--r--libisc/isc_strerror.c74
-rw-r--r--libisc/lib.c77
-rw-r--r--libisc/mem.c42
-rw-r--r--libisc/msgcat.c130
-rw-r--r--libisc/net.c311
-rw-r--r--libisc/netaddr.c363
-rw-r--r--libisc/netscope.c74
-rw-r--r--libisc/sockaddr.c480
-rw-r--r--libisc/strerror.c72
18 files changed, 0 insertions, 4265 deletions
diff --git a/libisc/assertions.c b/libisc/assertions.c
deleted file mode 100644
index 08dd5f3..0000000
--- a/libisc/assertions.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 1997-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: assertions.c,v 1.16 2001/07/16 03:52:05 mayer Exp $ */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <isc/assertions.h>
-#include <isc/msgs.h>
-
-/*
- * Forward.
- */
-
-static void
-default_callback(const char *, int, isc_assertiontype_t, const char *);
-
-/*
- * Public.
- */
-
-LIBISC_EXTERNAL_DATA isc_assertioncallback_t isc_assertion_failed =
- default_callback;
-
-void
-isc_assertion_setcallback(isc_assertioncallback_t cb) {
- if (cb == NULL)
- isc_assertion_failed = default_callback;
- else
- isc_assertion_failed = cb;
-}
-
-const char *
-isc_assertion_typetotext(isc_assertiontype_t type) {
- const char *result;
-
- /*
- * These strings have purposefully not been internationalized
- * because they are considered to essentially be keywords of
- * the ISC development environment.
- */
- switch (type) {
- case isc_assertiontype_require:
- result = "REQUIRE";
- break;
- case isc_assertiontype_ensure:
- result = "ENSURE";
- break;
- case isc_assertiontype_insist:
- result = "INSIST";
- break;
- case isc_assertiontype_invariant:
- result = "INVARIANT";
- break;
- default:
- result = NULL;
- }
- return (result);
-}
-
-/*
- * Private.
- */
-
-static void
-default_callback(const char *file, int line, isc_assertiontype_t type,
- const char *cond)
-{
- fprintf(stderr, "%s:%d: %s(%s) %s.\n",
- file, line, isc_assertion_typetotext(type), cond,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
- fflush(stderr);
- abort();
- /* NOTREACHED */
-}
diff --git a/libisc/error.c b/libisc/error.c
deleted file mode 100644
index ed0469d..0000000
--- a/libisc/error.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (C) 1998-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: error.c,v 1.16 2001/08/08 22:54:49 gson Exp $ */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <isc/error.h>
-#include <isc/msgs.h>
-
-static void
-default_unexpected_callback(const char *, int, const char *, va_list)
- ISC_FORMAT_PRINTF(3, 0);
-
-static void
-default_fatal_callback(const char *, int, const char *, va_list)
- ISC_FORMAT_PRINTF(3, 0);
-
-static isc_errorcallback_t unexpected_callback = default_unexpected_callback;
-static isc_errorcallback_t fatal_callback = default_fatal_callback;
-
-void
-isc_error_setunexpected(isc_errorcallback_t cb) {
- if (cb == NULL)
- unexpected_callback = default_unexpected_callback;
- else
- unexpected_callback = cb;
-}
-
-void
-isc_error_setfatal(isc_errorcallback_t cb) {
- if (cb == NULL)
- fatal_callback = default_fatal_callback;
- else
- fatal_callback = cb;
-}
-
-void
-isc_error_unexpected(const char *file, int line, const char *format, ...) {
- va_list args;
-
- va_start(args, format);
- (unexpected_callback)(file, line, format, args);
- va_end(args);
-}
-
-void
-isc_error_fatal(const char *file, int line, const char *format, ...) {
- va_list args;
-
- va_start(args, format);
- (fatal_callback)(file, line, format, args);
- va_end(args);
- abort();
-}
-
-void
-isc_error_runtimecheck(const char *file, int line, const char *expression) {
- isc_error_fatal(file, line, "RUNTIME_CHECK(%s) %s", expression,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
-}
-
-static void
-default_unexpected_callback(const char *file, int line, const char *format,
- va_list args)
-{
- fprintf(stderr, "%s:%d: ", file, line);
- vfprintf(stderr, format, args);
- fprintf(stderr, "\n");
- fflush(stderr);
-}
-
-static void
-default_fatal_callback(const char *file, int line, const char *format,
- va_list args)
-{
- fprintf(stderr, "%s:%d: %s: ", file, line,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FATALERROR, "fatal error"));
- vfprintf(stderr, format, args);
- fprintf(stderr, "\n");
- fflush(stderr);
-}
diff --git a/libisc/ifiter_getifaddrs.c b/libisc/ifiter_getifaddrs.c
deleted file mode 100644
index f20c1b3..0000000
--- a/libisc/ifiter_getifaddrs.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 2003 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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: ifiter_getifaddrs.c,v 1.2.68.3 2004/03/06 08:14:59 marka Exp $ */
-
-/*
- * Obtain the list of network interfaces using the getifaddrs(3) library.
- */
-
-#include <ifaddrs.h>
-
-#define IFITER_MAGIC ISC_MAGIC('I', 'F', 'I', 'G')
-#define VALID_IFITER(t) ISC_MAGIC_VALID(t, IFITER_MAGIC)
-
-struct isc_interfaceiter {
- unsigned int magic; /* Magic number. */
- isc_mem_t *mctx;
- void *buf; /* (unused) */
- unsigned int bufsize; /* (always 0) */
- struct ifaddrs *ifaddrs; /* List of ifaddrs */
- struct ifaddrs *pos; /* Ptr to current ifaddr */
- isc_interface_t current; /* Current interface data. */
- isc_result_t result; /* Last result code. */
-};
-
-isc_result_t
-isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
- isc_interfaceiter_t *iter;
- isc_result_t result;
- char strbuf[ISC_STRERRORSIZE];
-
- REQUIRE(iterp != NULL);
- REQUIRE(*iterp == NULL);
-
- iter = isc_mem_get(mctx, sizeof(*iter));
- if (iter == NULL)
- return (ISC_R_NOMEMORY);
-
- iter->mctx = mctx;
- iter->buf = NULL;
- iter->bufsize = 0;
- iter->ifaddrs = NULL;
-
- if (getifaddrs(&iter->ifaddrs) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERGETIFADDRS,
- ISC_MSG_GETIFADDRS,
- "getting interface "
- "addresses: getifaddrs: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto failure;
- }
-
- /*
- * A newly created iterator has an undefined position
- * until isc_interfaceiter_first() is called.
- */
- iter->pos = NULL;
- iter->result = ISC_R_FAILURE;
-
- iter->magic = IFITER_MAGIC;
- *iterp = iter;
- return (ISC_R_SUCCESS);
-
- failure:
- if (iter->ifaddrs != NULL) /* just in case */
- freeifaddrs(iter->ifaddrs);
- isc_mem_put(mctx, iter, sizeof(*iter));
- return (result);
-}
-
-/*
- * Get information about the current interface to iter->current.
- * If successful, return ISC_R_SUCCESS.
- * If the interface has an unsupported address family,
- * return ISC_R_IGNORE.
- */
-
-static isc_result_t
-internal_current(isc_interfaceiter_t *iter) {
- struct ifaddrs *ifa;
- int family;
- unsigned int namelen;
-
- REQUIRE(VALID_IFITER(iter));
-
- ifa = iter->pos;
-
- INSIST(ifa != NULL);
- INSIST(ifa->ifa_name != NULL);
- INSIST(ifa->ifa_addr != NULL);
-
- family = ifa->ifa_addr->sa_family;
- if (family != AF_INET && family != AF_INET6)
- return (ISC_R_IGNORE);
-
- memset(&iter->current, 0, sizeof(iter->current));
-
- namelen = strlen(ifa->ifa_name);
- if (namelen > sizeof(iter->current.name) - 1)
- namelen = sizeof(iter->current.name) - 1;
-
- memset(iter->current.name, 0, sizeof(iter->current.name));
- memcpy(iter->current.name, ifa->ifa_name, namelen);
-
- iter->current.flags = 0;
-
- if ((ifa->ifa_flags & IFF_UP) != 0)
- iter->current.flags |= INTERFACE_F_UP;
-
- if ((ifa->ifa_flags & IFF_POINTOPOINT) != 0)
- iter->current.flags |= INTERFACE_F_POINTTOPOINT;
-
- if ((ifa->ifa_flags & IFF_LOOPBACK) != 0)
- iter->current.flags |= INTERFACE_F_LOOPBACK;
-
- if ((ifa->ifa_flags & IFF_BROADCAST) != 0) {
- iter->current.flags |= INTERFACE_F_BROADCAST;
- }
-
-#ifdef IFF_MULTICAST
- if ((ifa->ifa_flags & IFF_MULTICAST) != 0) {
- iter->current.flags |= INTERFACE_F_MULTICAST;
- }
-#endif
- iter->current.af = family;
-
- get_addr(family, &iter->current.address, ifa->ifa_addr, ifa->ifa_name);
-
- if (ifa->ifa_netmask != NULL)
- get_addr(family, &iter->current.netmask, ifa->ifa_netmask,
- ifa->ifa_name);
-
- if (ifa->ifa_dstaddr != NULL &&
- (iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0)
- get_addr(family, &iter->current.dstaddress, ifa->ifa_dstaddr,
- ifa->ifa_name);
-
- if (ifa->ifa_broadaddr != NULL &&
- (iter->current.flags & INTERFACE_F_BROADCAST) != 0)
- get_addr(family, &iter->current.broadcast, ifa->ifa_broadaddr,
- ifa->ifa_name);
-
- return (ISC_R_SUCCESS);
-}
-
-/*
- * Step the iterator to the next interface. Unlike
- * isc_interfaceiter_next(), this may leave the iterator
- * positioned on an interface that will ultimately
- * be ignored. Return ISC_R_NOMORE if there are no more
- * interfaces, otherwise ISC_R_SUCCESS.
- */
-static isc_result_t
-internal_next(isc_interfaceiter_t *iter) {
- iter->pos = iter->pos->ifa_next;
-
- if (iter->pos == NULL)
- return (ISC_R_NOMORE);
-
- return (ISC_R_SUCCESS);
-}
-
-static void
-internal_destroy(isc_interfaceiter_t *iter) {
- if (iter->ifaddrs)
- freeifaddrs(iter->ifaddrs);
- iter->ifaddrs = NULL;
-}
-
-static
-void internal_first(isc_interfaceiter_t *iter) {
- iter->pos = iter->ifaddrs;
-}
diff --git a/libisc/ifiter_ioctl.c b/libisc/ifiter_ioctl.c
deleted file mode 100644
index e069560..0000000
--- a/libisc/ifiter_ioctl.c
+++ /dev/null
@@ -1,1118 +0,0 @@
-/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2003 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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: ifiter_ioctl.c,v 1.19.2.5.2.14 2004/06/22 04:40:23 marka Exp $ */
-
-/*
- * Obtain the list of network interfaces using the SIOCGLIFCONF ioctl.
- * See netintro(4).
- */
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
-#ifdef ISC_PLATFORM_HAVEIF_LADDRCONF
-#define lifc_len iflc_len
-#define lifc_buf iflc_buf
-#define lifc_req iflc_req
-#define LIFCONF if_laddrconf
-#else
-#define ISC_HAVE_LIFC_FAMILY 1
-#define ISC_HAVE_LIFC_FLAGS 1
-#define LIFCONF lifconf
-#endif
-
-#ifdef ISC_PLATFORM_HAVEIF_LADDRREQ
-#define lifr_addr iflr_addr
-#define lifr_name iflr_name
-#define lifr_dstaddr iflr_dstaddr
-#define lifr_broadaddr iflr_broadaddr
-#define lifr_flags iflr_flags
-#define lifr_index iflr_index
-#define ss_family sa_family
-#define LIFREQ if_laddrreq
-#else
-#define LIFREQ lifreq
-#endif
-#endif
-
-#define IFITER_MAGIC ISC_MAGIC('I', 'F', 'I', 'T')
-#define VALID_IFITER(t) ISC_MAGIC_VALID(t, IFITER_MAGIC)
-
-#define ISC_IF_INET6_SZ \
- sizeof("00000000000000000000000000000001 01 80 10 80 XXXXXXloXXXXXXXX\n")
-
-struct isc_interfaceiter {
- unsigned int magic; /* Magic number. */
- isc_mem_t *mctx;
- int mode;
- int socket;
- struct ifconf ifc;
- void *buf; /* Buffer for sysctl data. */
- unsigned int bufsize; /* Bytes allocated. */
- unsigned int pos; /* Current offset in
- SIOCGIFCONF data */
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- int socket6;
- struct LIFCONF lifc;
- void *buf6; /* Buffer for sysctl data. */
- unsigned int bufsize6; /* Bytes allocated. */
- unsigned int pos6; /* Current offset in
- SIOCGLIFCONF data */
- isc_result_t result6; /* Last result code. */
- isc_boolean_t first6;
-#endif
-#ifdef HAVE_TRUCLUSTER
- int clua_context; /* Cluster alias context */
- isc_boolean_t clua_done;
- struct sockaddr clua_sa;
-#endif
-#ifdef __linux
- FILE * proc;
- char entry[ISC_IF_INET6_SZ];
- isc_result_t valid;
- isc_boolean_t first;
-#endif
- isc_interface_t current; /* Current interface data. */
- isc_result_t result; /* Last result code. */
-};
-
-#ifdef HAVE_TRUCLUSTER
-#include <clua/clua.h>
-#include <sys/socket.h>
-#endif
-
-
-/*
- * Size of buffer for SIOCGLIFCONF, in bytes. We assume no sane system
- * will have more than a megabyte of interface configuration data.
- */
-#define IFCONF_BUFSIZE_INITIAL 4096
-#define IFCONF_BUFSIZE_MAX 1048576
-
-#ifdef __linux
-#ifndef IF_NAMESIZE
-# ifdef IFNAMSIZ
-# define IF_NAMESIZE IFNAMSIZ
-# else
-# define IF_NAMESIZE 16
-# endif
-#endif
-#endif
-
-static isc_result_t
-getbuf4(isc_interfaceiter_t *iter) {
- char strbuf[ISC_STRERRORSIZE];
-
- iter->bufsize = IFCONF_BUFSIZE_INITIAL;
-
- for (;;) {
- iter->buf = isc_mem_get(iter->mctx, iter->bufsize);
- if (iter->buf == NULL)
- return (ISC_R_NOMEMORY);
-
- memset(&iter->ifc.ifc_len, 0, sizeof(iter->ifc.ifc_len));
- iter->ifc.ifc_len = iter->bufsize;
- iter->ifc.ifc_buf = iter->buf;
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion". It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGIFCONF, (char *)&iter->ifc)
- == -1) {
- if (errno != EINVAL) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETIFCONFIG,
- "get interface "
- "configuration: %s"),
- strbuf);
- goto unexpected;
- }
- /*
- * EINVAL. Retry with a bigger buffer.
- */
- } else {
- /*
- * The ioctl succeeded.
- * Some OS's just return what will fit rather
- * than set EINVAL if the buffer is too small
- * to fit all the interfaces in. If
- * ifc.lifc_len is too near to the end of the
- * buffer we will grow it just in case and
- * retry.
- */
- if (iter->ifc.ifc_len + 2 * sizeof(struct ifreq)
- < iter->bufsize)
- break;
- }
- if (iter->bufsize >= IFCONF_BUFSIZE_MAX) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_BUFFERMAX,
- "get interface "
- "configuration: "
- "maximum buffer "
- "size exceeded"));
- goto unexpected;
- }
- isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
-
- iter->bufsize *= 2;
- }
- return (ISC_R_SUCCESS);
-
- unexpected:
- isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
- iter->buf = NULL;
- return (ISC_R_UNEXPECTED);
-}
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
-static isc_result_t
-getbuf6(isc_interfaceiter_t *iter) {
- char strbuf[ISC_STRERRORSIZE];
- isc_result_t result;
-
- iter->bufsize6 = IFCONF_BUFSIZE_INITIAL;
-
- for (;;) {
- iter->buf6 = isc_mem_get(iter->mctx, iter->bufsize6);
- if (iter->buf6 == NULL)
- return (ISC_R_NOMEMORY);
-
- memset(&iter->lifc, 0, sizeof(iter->lifc));
-#ifdef ISC_HAVE_LIFC_FAMILY
- iter->lifc.lifc_family = AF_INET6;
-#endif
-#ifdef ISC_HAVE_LIFC_FLAGS
- iter->lifc.lifc_flags = 0;
-#endif
- iter->lifc.lifc_len = iter->bufsize6;
- iter->lifc.lifc_buf = iter->buf6;
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion". It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket6, SIOCGLIFCONF, (char *)&iter->lifc)
- == -1) {
-#ifdef __hpux
- /*
- * IPv6 interface scanning is not available on all
- * kernels w/ IPv6 sockets.
- */
- if (errno == ENOENT) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETIFCONFIG,
- "get interface "
- "configuration: %s"),
- strbuf);
- result = ISC_R_FAILURE;
- goto cleanup;
- }
-#endif
- if (errno != EINVAL) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETIFCONFIG,
- "get interface "
- "configuration: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto cleanup;
- }
- /*
- * EINVAL. Retry with a bigger buffer.
- */
- } else {
- /*
- * The ioctl succeeded.
- * Some OS's just return what will fit rather
- * than set EINVAL if the buffer is too small
- * to fit all the interfaces in. If
- * ifc.ifc_len is too near to the end of the
- * buffer we will grow it just in case and
- * retry.
- */
- if (iter->lifc.lifc_len + 2 * sizeof(struct LIFREQ)
- < iter->bufsize6)
- break;
- }
- if (iter->bufsize6 >= IFCONF_BUFSIZE_MAX) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_BUFFERMAX,
- "get interface "
- "configuration: "
- "maximum buffer "
- "size exceeded"));
- result = ISC_R_UNEXPECTED;
- goto cleanup;
- }
- isc_mem_put(iter->mctx, iter->buf6, iter->bufsize6);
-
- iter->bufsize6 *= 2;
- }
-
- if (iter->lifc.lifc_len != 0)
- iter->mode = 6;
- return (ISC_R_SUCCESS);
-
- cleanup:
- isc_mem_put(iter->mctx, iter->buf6, iter->bufsize6);
- iter->buf6 = NULL;
- return (result);
-}
-#endif
-
-isc_result_t
-isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
- isc_interfaceiter_t *iter;
- isc_result_t result;
- char strbuf[ISC_STRERRORSIZE];
-
- REQUIRE(iterp != NULL);
- REQUIRE(*iterp == NULL);
-
- iter = isc_mem_get(mctx, sizeof(*iter));
- if (iter == NULL)
- return (ISC_R_NOMEMORY);
-
- iter->mctx = mctx;
- iter->mode = 4;
- iter->buf = NULL;
- iter->pos = (unsigned int) -1;
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- iter->buf6 = NULL;
- iter->pos6 = (unsigned int) -1;
- iter->result6 = ISC_R_NOMORE;
- iter->socket6 = -1;
- iter->first6 = ISC_FALSE;
-#endif
-
- /*
- * Get the interface configuration, allocating more memory if
- * necessary.
- */
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- result = isc_net_probeipv6();
- if (result == ISC_R_SUCCESS) {
- /*
- * Create an unbound datagram socket to do the SIOCGLIFCONF
- * ioctl on. HP/UX requires an AF_INET6 socket for
- * SIOCGLIFCONF to get IPv6 addresses.
- */
- if ((iter->socket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_MAKESCANSOCKET,
- "making interface "
- "scan socket: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto socket6_failure;
- }
- iter->result6 = getbuf6(iter);
- if (iter->result6 != ISC_R_NOTIMPLEMENTED &&
- iter->result6 != ISC_R_SUCCESS)
- goto ioctl6_failure;
- }
-#endif
- if ((iter->socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_MAKESCANSOCKET,
- "making interface "
- "scan socket: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto socket_failure;
- }
- result = getbuf4(iter);
- if (result != ISC_R_SUCCESS)
- goto ioctl_failure;
-
- /*
- * A newly created iterator has an undefined position
- * until isc_interfaceiter_first() is called.
- */
-#ifdef HAVE_TRUCLUSTER
- iter->clua_context = -1;
- iter->clua_done = ISC_TRUE;
-#endif
-#ifdef __linux
- iter->proc = fopen("/proc/net/if_inet6", "r");
- iter->valid = ISC_R_FAILURE;
- iter->first = ISC_FALSE;
-#endif
- iter->result = ISC_R_FAILURE;
-
- iter->magic = IFITER_MAGIC;
- *iterp = iter;
- return (ISC_R_SUCCESS);
-
- ioctl_failure:
- if (iter->buf != NULL)
- isc_mem_put(mctx, iter->buf, iter->bufsize);
- (void) close(iter->socket);
-
- socket_failure:
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- if (iter->buf6 != NULL)
- isc_mem_put(mctx, iter->buf6, iter->bufsize6);
- ioctl6_failure:
- if (iter->socket6 != -1)
- (void) close(iter->socket6);
- socket6_failure:
-#endif
-
- isc_mem_put(mctx, iter, sizeof(*iter));
- return (result);
-}
-
-#ifdef HAVE_TRUCLUSTER
-static void
-get_inaddr(isc_netaddr_t *dst, struct in_addr *src) {
- dst->family = AF_INET;
- memcpy(&dst->type.in, src, sizeof(struct in_addr));
-}
-
-static isc_result_t
-internal_current_clusteralias(isc_interfaceiter_t *iter) {
- struct clua_info ci;
- if (clua_getaliasinfo(&iter->clua_sa, &ci) != CLUA_SUCCESS)
- return (ISC_R_IGNORE);
- memset(&iter->current, 0, sizeof(iter->current));
- iter->current.af = iter->clua_sa.sa_family;
- memset(iter->current.name, 0, sizeof(iter->current.name));
- sprintf(iter->current.name, "clua%d", ci.aliasid);
- iter->current.flags = INTERFACE_F_UP;
- get_inaddr(&iter->current.address, &ci.addr);
- get_inaddr(&iter->current.netmask, &ci.netmask);
- return (ISC_R_SUCCESS);
-}
-#endif
-
-#ifdef __linux
-static isc_result_t
-linux_if_inet6_next(isc_interfaceiter_t *iter) {
- if (iter->proc != NULL &&
- fgets(iter->entry, sizeof(iter->entry), iter->proc) != NULL)
- iter->valid = ISC_R_SUCCESS;
- else
- iter->valid = ISC_R_NOMORE;
- return (iter->valid);
-}
-
-static void
-linux_if_inet6_first(isc_interfaceiter_t *iter) {
- if (iter->proc != NULL) {
- rewind(iter->proc);
- (void)linux_if_inet6_next(iter);
- } else
- iter->valid = ISC_R_NOMORE;
- iter->first = ISC_FALSE;
-}
-
-static isc_result_t
-linux_if_inet6_current(isc_interfaceiter_t *iter) {
- char address[33];
- char name[IF_NAMESIZE+1];
- char strbuf[ISC_STRERRORSIZE];
- struct in6_addr addr6;
- struct ifreq ifreq;
- int ifindex, prefix, scope, flags;
- int res;
- unsigned int i;
-
- if (iter->valid != ISC_R_SUCCESS)
- return (iter->valid);
- if (iter->proc == NULL) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "/proc/net/if_inet6:iter->proc == NULL");
- return (ISC_R_FAILURE);
- }
-
- /*
- * Format for /proc/net/if_inet6:
- * (see iface_proc_info() in net/ipv6/addrconf.c)
- * <addr6:32> <ifindex:2> <prefix:2> <scope:2> <flags:2> <name:8>
- */
- res = sscanf(iter->entry, "%32[a-f0-9] %x %x %x %x %16s\n",
- address, &ifindex, &prefix, &scope, &flags, name);
- if (res != 6) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "/proc/net/if_inet6:sscanf() -> %d (expected 6)",
- res);
- return (ISC_R_FAILURE);
- }
- if (strlen(address) != 32) {
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "/proc/net/if_inet6:strlen(%s) != 32", address);
- return (ISC_R_FAILURE);
- }
- for (i = 0; i < 16; i++) {
- unsigned char byte;
- static const char hex[] = "0123456789abcdef";
- byte = ((index(hex, address[i * 2]) - hex) << 4) |
- (index(hex, address[i * 2 + 1]) - hex);
- addr6.s6_addr[i] = byte;
- }
- iter->current.af = AF_INET6;
- /* iter->current.ifindex = ifindex; */
- iter->current.flags = 0;
-
- memset(&ifreq, 0, sizeof(ifreq));
- INSIST(sizeof(ifreq.ifr_name) <= sizeof(iter->current.name));
- strncpy(ifreq.ifr_name, name, sizeof(ifreq.ifr_name));
-
- if (ioctl(iter->socket, SIOCGIFFLAGS, (char *) &ifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "%s: getting interface flags: %s",
- ifreq.ifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
-
- if ((ifreq.ifr_flags & IFF_UP) != 0)
- iter->current.flags |= INTERFACE_F_UP;
-#ifdef IFF_POINTOPOINT
- if ((ifreq.ifr_flags & IFF_POINTOPOINT) != 0)
- iter->current.flags |= INTERFACE_F_POINTTOPOINT;
-#endif
- if ((ifreq.ifr_flags & IFF_LOOPBACK) != 0)
- iter->current.flags |= INTERFACE_F_LOOPBACK;
- if ((ifreq.ifr_flags & IFF_BROADCAST) != 0)
- iter->current.flags |= INTERFACE_F_BROADCAST;
-#ifdef IFF_MULTICAST
- if ((ifreq.ifr_flags & IFF_MULTICAST) != 0)
- iter->current.flags |= INTERFACE_F_MULTICAST;
-#endif
-
- /*
- * enable_multicast_if() requires scopeid for setsockopt,
- * so associate address with their corresponding ifindex.
- */
- isc_netaddr_fromin6(&iter->current.address, &addr6);
- isc_netaddr_setzone(&iter->current.address, (isc_uint32_t)ifindex);
-
- for (i = 0; i < 16; i++) {
- if (prefix > 8) {
- addr6.s6_addr[i] = 0xff;
- prefix -= 8;
- } else {
- addr6.s6_addr[i] = (0xff << (8 - prefix)) & 0xff;
- prefix = 0;
- }
- }
- isc_netaddr_fromin6(&iter->current.netmask, &addr6);
- strncpy(iter->current.name, name, sizeof(iter->current.name));
- return (ISC_R_SUCCESS);
-}
-#endif
-
-/*
- * Get information about the current interface to iter->current.
- * If successful, return ISC_R_SUCCESS.
- * If the interface has an unsupported address family, or if
- * some operation on it fails, return ISC_R_IGNORE to make
- * the higher-level iterator code ignore it.
- */
-
-static isc_result_t
-internal_current4(isc_interfaceiter_t *iter) {
- struct ifreq *ifrp;
- struct ifreq ifreq;
- int family;
- char strbuf[ISC_STRERRORSIZE];
-#if !defined(ISC_PLATFORM_HAVEIF_LADDRREQ) && defined(SIOCGLIFADDR)
- struct lifreq lifreq;
-#else
- char sabuf[256];
-#endif
- int i, bits, prefixlen;
-#ifdef __linux
- isc_result_t result;
-#endif
-
- REQUIRE(VALID_IFITER(iter));
- REQUIRE (iter->pos < (unsigned int) iter->ifc.ifc_len);
-
-#ifdef __linux
- result = linux_if_inet6_current(iter);
- if (result != ISC_R_NOMORE)
- return (result);
- iter->first = ISC_TRUE;
-#endif
-
- ifrp = (struct ifreq *)((char *) iter->ifc.ifc_req + iter->pos);
-
- memset(&ifreq, 0, sizeof(ifreq));
- memcpy(&ifreq, ifrp, sizeof(ifreq));
-
- family = ifreq.ifr_addr.sa_family;
-#if defined(ISC_PLATFORM_HAVEIPV6)
- if (family != AF_INET && family != AF_INET6)
-#else
- if (family != AF_INET)
-#endif
- return (ISC_R_IGNORE);
-
- memset(&iter->current, 0, sizeof(iter->current));
- iter->current.af = family;
-
- INSIST(sizeof(ifreq.ifr_name) <= sizeof(iter->current.name));
- memset(iter->current.name, 0, sizeof(iter->current.name));
- memcpy(iter->current.name, ifreq.ifr_name, sizeof(ifreq.ifr_name));
-
- get_addr(family, &iter->current.address,
- (struct sockaddr *)&ifrp->ifr_addr, ifreq.ifr_name);
-
- /*
- * If the interface does not have a address ignore it.
- */
- switch (family) {
- case AF_INET:
- if (iter->current.address.type.in.s_addr == htonl(INADDR_ANY))
- return (ISC_R_IGNORE);
- break;
-#ifdef ISC_PLATFORM_HAVEIPV6
- case AF_INET6:
- if (memcmp(&iter->current.address.type.in6, &in6addr_any,
- sizeof(in6addr_any)) == 0)
- return (ISC_R_IGNORE);
- break;
-#endif
- }
-
- /*
- * Get interface flags.
- */
-
- iter->current.flags = 0;
-
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGIFFLAGS, (char *) &ifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "%s: getting interface flags: %s",
- ifreq.ifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
-
- if ((ifreq.ifr_flags & IFF_UP) != 0)
- iter->current.flags |= INTERFACE_F_UP;
-
-#ifdef IFF_POINTOPOINT
- if ((ifreq.ifr_flags & IFF_POINTOPOINT) != 0)
- iter->current.flags |= INTERFACE_F_POINTTOPOINT;
-#endif
-
- if ((ifreq.ifr_flags & IFF_LOOPBACK) != 0)
- iter->current.flags |= INTERFACE_F_LOOPBACK;
-
- if ((ifreq.ifr_flags & IFF_BROADCAST) != 0) {
- iter->current.flags |= INTERFACE_F_BROADCAST;
- }
-
-#ifdef IFF_MULTICAST
- if ((ifreq.ifr_flags & IFF_MULTICAST) != 0) {
- iter->current.flags |= INTERFACE_F_MULTICAST;
- }
-#endif
-
- if (family == AF_INET)
- goto inet;
-
-#if !defined(ISC_PLATFORM_HAVEIF_LADDRREQ) && defined(SIOCGLIFADDR)
- memset(&lifreq, 0, sizeof(lifreq));
- memcpy(lifreq.lifr_name, iter->current.name, sizeof(lifreq.lifr_name));
- memcpy(&lifreq.lifr_addr, &iter->current.address.type.in6,
- sizeof(iter->current.address.type.in6));
-
- if (ioctl(iter->socket, SIOCGLIFADDR, &lifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "%s: getting interface address: %s",
- ifreq.ifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- prefixlen = lifreq.lifr_addrlen;
-#else
- isc_netaddr_format(&iter->current.address, sabuf, sizeof(sabuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETIFCONFIG,
- "prefix length for %s is unknown "
- "(assume 128)"), sabuf);
- prefixlen = 128;
-#endif
-
- /*
- * Netmask already zeroed.
- */
- iter->current.netmask.family = family;
- for (i = 0; i < 16; i++) {
- if (prefixlen > 8) {
- bits = 0;
- prefixlen -= 8;
- } else {
- bits = 8 - prefixlen;
- prefixlen = 0;
- }
- iter->current.netmask.type.in6.s6_addr[i] = (~0 << bits) & 0xff;
- }
- return (ISC_R_SUCCESS);
-
- inet:
- if (family != AF_INET)
- return (ISC_R_IGNORE);
-#ifdef IFF_POINTOPOINT
- /*
- * If the interface is point-to-point, get the destination address.
- */
- if ((iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) {
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGIFDSTADDR, (char *)&ifreq)
- < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETDESTADDR,
- "%s: getting "
- "destination address: %s"),
- ifreq.ifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.dstaddress,
- (struct sockaddr *)&ifreq.ifr_dstaddr, ifreq.ifr_name);
- }
-#endif
- if ((iter->current.flags & INTERFACE_F_BROADCAST) != 0) {
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGIFBRDADDR, (char *)&ifreq)
- < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETDESTADDR,
- "%s: getting "
- "broadcast address: %s"),
- ifreq.ifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.broadcast,
- (struct sockaddr *)&ifreq.ifr_broadaddr, ifreq.ifr_name);
- }
-
- /*
- * Get the network mask.
- */
- memset(&ifreq, 0, sizeof(ifreq));
- memcpy(&ifreq, ifrp, sizeof(ifreq));
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGIFNETMASK, (char *)&ifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETNETMASK,
- "%s: getting netmask: %s"),
- ifreq.ifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.netmask,
- (struct sockaddr *)&ifreq.ifr_addr, ifreq.ifr_name);
- return (ISC_R_SUCCESS);
-}
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
-static isc_result_t
-internal_current6(isc_interfaceiter_t *iter) {
- struct LIFREQ *ifrp;
- struct LIFREQ lifreq;
- int family;
- char strbuf[ISC_STRERRORSIZE];
- int fd;
-
- REQUIRE(VALID_IFITER(iter));
- if (iter->result6 != ISC_R_SUCCESS)
- return (iter->result6);
- REQUIRE(iter->pos6 < (unsigned int) iter->lifc.lifc_len);
-
- ifrp = (struct LIFREQ *)((char *) iter->lifc.lifc_req + iter->pos6);
-
- memset(&lifreq, 0, sizeof(lifreq));
- memcpy(&lifreq, ifrp, sizeof(lifreq));
-
- family = lifreq.lifr_addr.ss_family;
-#ifdef ISC_PLATFORM_HAVEIPV6
- if (family != AF_INET && family != AF_INET6)
-#else
- if (family != AF_INET)
-#endif
- return (ISC_R_IGNORE);
-
- memset(&iter->current, 0, sizeof(iter->current));
- iter->current.af = family;
-
- INSIST(sizeof(lifreq.lifr_name) <= sizeof(iter->current.name));
- memset(iter->current.name, 0, sizeof(iter->current.name));
- memcpy(iter->current.name, lifreq.lifr_name, sizeof(lifreq.lifr_name));
-
- get_addr(family, &iter->current.address,
- (struct sockaddr *)&lifreq.lifr_addr, lifreq.lifr_name);
-
- /*
- * If the interface does not have a address ignore it.
- */
- switch (family) {
- case AF_INET:
- if (iter->current.address.type.in.s_addr == htonl(INADDR_ANY))
- return (ISC_R_IGNORE);
- break;
-#ifdef ISC_PLATFORM_HAVEIPV6
- case AF_INET6:
- if (memcmp(&iter->current.address.type.in6, &in6addr_any,
- sizeof(in6addr_any)) == 0)
- return (ISC_R_IGNORE);
- break;
-#endif
- }
-
- /*
- * Get interface flags.
- */
-
- iter->current.flags = 0;
-
- if (family == AF_INET6)
- fd = iter->socket6;
- else
- fd = iter->socket;
-
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(fd, SIOCGLIFFLAGS, (char *) &lifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "%s: getting interface flags: %s",
- lifreq.lifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
-
- if ((lifreq.lifr_flags & IFF_UP) != 0)
- iter->current.flags |= INTERFACE_F_UP;
-
-#ifdef IFF_POINTOPOINT
- if ((lifreq.lifr_flags & IFF_POINTOPOINT) != 0)
- iter->current.flags |= INTERFACE_F_POINTTOPOINT;
-#endif
-
- if ((lifreq.lifr_flags & IFF_LOOPBACK) != 0)
- iter->current.flags |= INTERFACE_F_LOOPBACK;
-
- if ((lifreq.lifr_flags & IFF_BROADCAST) != 0) {
- iter->current.flags |= INTERFACE_F_BROADCAST;
- }
-
-#ifdef IFF_MULTICAST
- if ((lifreq.lifr_flags & IFF_MULTICAST) != 0) {
- iter->current.flags |= INTERFACE_F_MULTICAST;
- }
-#endif
-
-#ifdef IFF_POINTOPOINT
- /*
- * If the interface is point-to-point, get the destination address.
- */
- if ((iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) {
- /*
- * Ignore the HP/UX warning about "interger overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(fd, SIOCGLIFDSTADDR, (char *)&lifreq)
- < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETDESTADDR,
- "%s: getting "
- "destination address: %s"),
- lifreq.lifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.dstaddress,
- (struct sockaddr *)&lifreq.lifr_dstaddr,
- lifreq.lifr_name);
- }
-#endif
-
-#ifdef SIOCGLIFBRDADDR
- if ((iter->current.flags & INTERFACE_F_BROADCAST) != 0) {
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(iter->socket, SIOCGLIFBRDADDR, (char *)&lifreq)
- < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETDESTADDR,
- "%s: getting "
- "broadcast address: %s"),
- lifreq.lifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.broadcast,
- (struct sockaddr *)&lifreq.lifr_broadaddr,
- lifreq.lifr_name);
- }
-#endif /* SIOCGLIFBRDADDR */
-
- /*
- * Get the network mask. Netmask already zeroed.
- */
- memset(&lifreq, 0, sizeof(lifreq));
- memcpy(&lifreq, ifrp, sizeof(lifreq));
-
-#ifdef lifr_addrlen
- /*
- * Special case: if the system provides lifr_addrlen member, the
- * netmask of an IPv6 address can be derived from the length, since
- * an IPv6 address always has a contiguous mask.
- */
- if (family == AF_INET6) {
- int i, bits;
-
- iter->current.netmask.family = family;
- for (i = 0; i < lifreq.lifr_addrlen; i += 8) {
- bits = lifreq.lifr_addrlen - i;
- bits = (bits < 8) ? (8 - bits) : 0;
- iter->current.netmask.type.in6.s6_addr[i / 8] =
- (~0 << bits) & 0xff;
- }
-
- return (ISC_R_SUCCESS);
- }
-#endif
-
- /*
- * Ignore the HP/UX warning about "integer overflow during
- * conversion. It comes from its own macro definition,
- * and is really hard to shut up.
- */
- if (ioctl(fd, SIOCGLIFNETMASK, (char *)&lifreq) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERIOCTL,
- ISC_MSG_GETNETMASK,
- "%s: getting netmask: %s"),
- lifreq.lifr_name, strbuf);
- return (ISC_R_IGNORE);
- }
- get_addr(family, &iter->current.netmask,
- (struct sockaddr *)&lifreq.lifr_addr, lifreq.lifr_name);
-
- return (ISC_R_SUCCESS);
-}
-#endif
-
-static isc_result_t
-internal_current(isc_interfaceiter_t *iter) {
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- if (iter->mode == 6) {
- iter->result6 = internal_current6(iter);
- if (iter->result6 != ISC_R_NOMORE)
- return (iter->result6);
- }
-#endif
-#ifdef HAVE_TRUCLUSTER
- if (!iter->clua_done)
- return(internal_current_clusteralias(iter));
-#endif
- return (internal_current4(iter));
-}
-
-/*
- * Step the iterator to the next interface. Unlike
- * isc_interfaceiter_next(), this may leave the iterator
- * positioned on an interface that will ultimately
- * be ignored. Return ISC_R_NOMORE if there are no more
- * interfaces, otherwise ISC_R_SUCCESS.
- */
-static isc_result_t
-internal_next4(isc_interfaceiter_t *iter) {
- struct ifreq *ifrp;
-
- REQUIRE (iter->pos < (unsigned int) iter->ifc.ifc_len);
-
-#ifdef __linux
- if (linux_if_inet6_next(iter) == ISC_R_SUCCESS)
- return (ISC_R_SUCCESS);
- if (!iter->first)
- return (ISC_R_SUCCESS);
-#endif
- ifrp = (struct ifreq *)((char *) iter->ifc.ifc_req + iter->pos);
-
-#ifdef ISC_PLATFORM_HAVESALEN
- if (ifrp->ifr_addr.sa_len > sizeof(struct sockaddr))
- iter->pos += sizeof(ifrp->ifr_name) + ifrp->ifr_addr.sa_len;
- else
-#endif
- iter->pos += sizeof(*ifrp);
-
- if (iter->pos >= (unsigned int) iter->ifc.ifc_len)
- return (ISC_R_NOMORE);
-
- return (ISC_R_SUCCESS);
-}
-
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
-static isc_result_t
-internal_next6(isc_interfaceiter_t *iter) {
- struct LIFREQ *ifrp;
-
- if (iter->result6 != ISC_R_SUCCESS && iter->result6 != ISC_R_IGNORE)
- return (iter->result6);
-
- REQUIRE(iter->pos6 < (unsigned int) iter->lifc.lifc_len);
-
- ifrp = (struct LIFREQ *)((char *) iter->lifc.lifc_req + iter->pos6);
-
-#ifdef ISC_PLATFORM_HAVESALEN
- if (ifrp->lifr_addr.sa_len > sizeof(struct sockaddr))
- iter->pos6 += sizeof(ifrp->lifr_name) + ifrp->lifr_addr.sa_len;
- else
-#endif
- iter->pos6 += sizeof(*ifrp);
-
- if (iter->pos6 >= (unsigned int) iter->lifc.lifc_len)
- return (ISC_R_NOMORE);
-
- return (ISC_R_SUCCESS);
-}
-#endif
-
-static isc_result_t
-internal_next(isc_interfaceiter_t *iter) {
-#ifdef HAVE_TRUCLUSTER
- int clua_result;
-#endif
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- if (iter->mode == 6) {
- iter->result6 = internal_next6(iter);
- if (iter->result6 != ISC_R_NOMORE)
- return (iter->result6);
- if (iter->first6) {
- iter->first6 = ISC_FALSE;
- return (ISC_R_SUCCESS);
- }
- }
-#endif
-#ifdef HAVE_TRUCLUSTER
- if (!iter->clua_done) {
- clua_result = clua_getaliasaddress(&iter->clua_sa,
- &iter->clua_context);
- if (clua_result != CLUA_SUCCESS)
- iter->clua_done = ISC_TRUE;
- return (ISC_R_SUCCESS);
- }
-#endif
- return (internal_next4(iter));
-}
-
-static void
-internal_destroy(isc_interfaceiter_t *iter) {
- (void) close(iter->socket);
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- if (iter->socket6 != -1)
- (void) close(iter->socket6);
- if (iter->buf6 != NULL) {
- isc_mem_put(iter->mctx, iter->buf6, iter->bufsize6);
- }
-#endif
-#ifdef __linux
- if (iter->proc != NULL)
- fclose(iter->proc);
-#endif
-}
-
-static
-void internal_first(isc_interfaceiter_t *iter) {
-#ifdef HAVE_TRUCLUSTER
- int clua_result;
-#endif
- iter->pos = 0;
-#if defined(SIOCGLIFCONF) && defined(SIOCGLIFADDR)
- iter->pos6 = 0;
- if (iter->result6 == ISC_R_NOMORE)
- iter->result6 = ISC_R_SUCCESS;
- iter->first6 = ISC_TRUE;
-#endif
-#ifdef HAVE_TRUCLUSTER
- iter->clua_context = 0;
- clua_result = clua_getaliasaddress(&iter->clua_sa,
- &iter->clua_context);
- iter->clua_done = ISC_TF(clua_result != CLUA_SUCCESS);
-#endif
-#ifdef __linux
- linux_if_inet6_first(iter);
-#endif
-}
diff --git a/libisc/ifiter_sysctl.c b/libisc/ifiter_sysctl.c
deleted file mode 100644
index 6206e6e..0000000
--- a/libisc/ifiter_sysctl.c
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2003 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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: ifiter_sysctl.c,v 1.14.12.7 2004/03/08 09:04:56 marka Exp $ */
-
-/*
- * Obtain the list of network interfaces using sysctl.
- * See TCP/IP Illustrated Volume 2, sections 19.8, 19.14,
- * and 19.16.
- */
-
-#include <sys/param.h>
-#include <sys/sysctl.h>
-
-#include <net/route.h>
-#include <net/if_dl.h>
-
-/* XXX what about Alpha? */
-#ifdef sgi
-#define ROUNDUP(a) ((a) > 0 ? \
- (1 + (((a) - 1) | (sizeof(__uint64_t) - 1))) : \
- sizeof(__uint64_t))
-#else
-#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) \
- : sizeof(long))
-#endif
-
-#define IFITER_MAGIC ISC_MAGIC('I', 'F', 'I', 'S')
-#define VALID_IFITER(t) ISC_MAGIC_VALID(t, IFITER_MAGIC)
-
-struct isc_interfaceiter {
- unsigned int magic; /* Magic number. */
- isc_mem_t *mctx;
- void *buf; /* Buffer for sysctl data. */
- unsigned int bufsize; /* Bytes allocated. */
- unsigned int bufused; /* Bytes used. */
- unsigned int pos; /* Current offset in
- sysctl data. */
- isc_interface_t current; /* Current interface data. */
- isc_result_t result; /* Last result code. */
-};
-
-static int mib[6] = {
- CTL_NET,
- PF_ROUTE,
- 0,
- 0, /* Any address family. */
- NET_RT_IFLIST,
- 0 /* Flags. */
-};
-
-isc_result_t
-isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) {
- isc_interfaceiter_t *iter;
- isc_result_t result;
- size_t bufsize;
- size_t bufused;
- char strbuf[ISC_STRERRORSIZE];
-
- REQUIRE(iterp != NULL);
- REQUIRE(*iterp == NULL);
-
- iter = isc_mem_get(mctx, sizeof(*iter));
- if (iter == NULL)
- return (ISC_R_NOMEMORY);
-
- iter->mctx = mctx;
- iter->buf = 0;
-
- /*
- * Determine the amount of memory needed.
- */
- bufsize = 0;
- if (sysctl(mib, 6, NULL, &bufsize, NULL, (size_t) 0) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERSYSCTL,
- ISC_MSG_GETIFLISTSIZE,
- "getting interface "
- "list size: sysctl: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto failure;
- }
- iter->bufsize = bufsize;
-
- iter->buf = isc_mem_get(iter->mctx, iter->bufsize);
- if (iter->buf == NULL) {
- result = ISC_R_NOMEMORY;
- goto failure;
- }
-
- bufused = bufsize;
- if (sysctl(mib, 6, iter->buf, &bufused, NULL, (size_t) 0) < 0) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_IFITERSYSCTL,
- ISC_MSG_GETIFLIST,
- "getting interface list: "
- "sysctl: %s"),
- strbuf);
- result = ISC_R_UNEXPECTED;
- goto failure;
- }
- iter->bufused = bufused;
- INSIST(iter->bufused <= iter->bufsize);
-
- /*
- * A newly created iterator has an undefined position
- * until isc_interfaceiter_first() is called.
- */
- iter->pos = (unsigned int) -1;
- iter->result = ISC_R_FAILURE;
-
- iter->magic = IFITER_MAGIC;
- *iterp = iter;
- return (ISC_R_SUCCESS);
-
- failure:
- if (iter->buf != NULL)
- isc_mem_put(mctx, iter->buf, iter->bufsize);
- isc_mem_put(mctx, iter, sizeof(*iter));
- return (result);
-}
-
-/*
- * Get information about the current interface to iter->current.
- * If successful, return ISC_R_SUCCESS.
- * If the interface has an unsupported address family,
- * return ISC_R_IGNORE. In case of other failure,
- * return ISC_R_UNEXPECTED.
- */
-
-static isc_result_t
-internal_current(isc_interfaceiter_t *iter) {
- struct ifa_msghdr *ifam, *ifam_end;
-
- REQUIRE(VALID_IFITER(iter));
- REQUIRE (iter->pos < (unsigned int) iter->bufused);
-
- ifam = (struct ifa_msghdr *) ((char *) iter->buf + iter->pos);
- ifam_end = (struct ifa_msghdr *) ((char *) iter->buf + iter->bufused);
-
- if (ifam->ifam_type == RTM_IFINFO) {
- struct if_msghdr *ifm = (struct if_msghdr *) ifam;
- struct sockaddr_dl *sdl = (struct sockaddr_dl *) (ifm + 1);
- unsigned int namelen;
-
- memset(&iter->current, 0, sizeof(iter->current));
-
- namelen = sdl->sdl_nlen;
- if (namelen > sizeof(iter->current.name) - 1)
- namelen = sizeof(iter->current.name) - 1;
-
- memset(iter->current.name, 0, sizeof(iter->current.name));
- memcpy(iter->current.name, sdl->sdl_data, namelen);
-
- iter->current.flags = 0;
-
- if ((ifam->ifam_flags & IFF_UP) != 0)
- iter->current.flags |= INTERFACE_F_UP;
-
- if ((ifam->ifam_flags & IFF_POINTOPOINT) != 0)
- iter->current.flags |= INTERFACE_F_POINTTOPOINT;
-
- if ((ifam->ifam_flags & IFF_LOOPBACK) != 0)
- iter->current.flags |= INTERFACE_F_LOOPBACK;
-
- if ((ifam->ifam_flags & IFF_BROADCAST) != 0) {
- iter->current.flags |= INTERFACE_F_BROADCAST;
- }
-#ifdef IFF_MULTICAST
- if ((ifam->ifam_flags & IFF_MULTICAST) != 0) {
- iter->current.flags |= INTERFACE_F_MULTICAST;
- }
-#endif
-
- /*
- * This is not an interface address.
- * Force another iteration.
- */
- return (ISC_R_IGNORE);
- } else if (ifam->ifam_type == RTM_NEWADDR) {
- int i;
- int family;
- struct sockaddr *mask_sa = NULL;
- struct sockaddr *addr_sa = NULL;
- struct sockaddr *dst_sa = NULL;
-
- struct sockaddr *sa = (struct sockaddr *)(ifam + 1);
- family = sa->sa_family;
-
- for (i = 0; i < RTAX_MAX; i++)
- {
- if ((ifam->ifam_addrs & (1 << i)) == 0)
- continue;
-
- INSIST(sa < (struct sockaddr *) ifam_end);
-
- switch (i) {
- case RTAX_NETMASK: /* Netmask */
- mask_sa = sa;
- break;
- case RTAX_IFA: /* Interface address */
- addr_sa = sa;
- break;
- case RTAX_BRD: /* Broadcast or destination address */
- dst_sa = sa;
- break;
- }
-#ifdef ISC_PLATFORM_HAVESALEN
- sa = (struct sockaddr *)((char*)(sa)
- + ROUNDUP(sa->sa_len));
-#else
-#ifdef sgi
- /*
- * Do as the contributed SGI code does.
- */
- sa = (struct sockaddr *)((char*)(sa)
- + ROUNDUP(_FAKE_SA_LEN_DST(sa)));
-#else
- /* XXX untested. */
- sa = (struct sockaddr *)((char*)(sa)
- + ROUNDUP(sizeof(struct sockaddr)));
-#endif
-#endif
- }
-
- if (addr_sa == NULL)
- return (ISC_R_IGNORE);
-
- family = addr_sa->sa_family;
- if (family != AF_INET && family != AF_INET6)
- return (ISC_R_IGNORE);
-
- iter->current.af = family;
-
- get_addr(family, &iter->current.address, addr_sa,
- iter->current.name);
-
- if (mask_sa != NULL)
- get_addr(family, &iter->current.netmask, mask_sa,
- iter->current.name);
-
- if (dst_sa != NULL &&
- (iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0)
- get_addr(family, &iter->current.dstaddress, dst_sa,
- iter->current.name);
-
- if (dst_sa != NULL &&
- (iter->current.flags & INTERFACE_F_BROADCAST) != 0)
- get_addr(family, &iter->current.broadcast, dst_sa,
- iter->current.name);
-
-
- return (ISC_R_SUCCESS);
- } else {
- printf(isc_msgcat_get(isc_msgcat, ISC_MSGSET_IFITERSYSCTL,
- ISC_MSG_UNEXPECTEDTYPE,
- "warning: unexpected interface list "
- "message type\n"));
- return (ISC_R_IGNORE);
- }
-}
-
-/*
- * Step the iterator to the next interface. Unlike
- * isc_interfaceiter_next(), this may leave the iterator
- * positioned on an interface that will ultimately
- * be ignored. Return ISC_R_NOMORE if there are no more
- * interfaces, otherwise ISC_R_SUCCESS.
- */
-static isc_result_t
-internal_next(isc_interfaceiter_t *iter) {
- struct ifa_msghdr *ifam;
- REQUIRE (iter->pos < (unsigned int) iter->bufused);
-
- ifam = (struct ifa_msghdr *) ((char *) iter->buf + iter->pos);
-
- iter->pos += ifam->ifam_msglen;
-
- if (iter->pos >= iter->bufused)
- return (ISC_R_NOMORE);
-
- return (ISC_R_SUCCESS);
-}
-
-static void
-internal_destroy(isc_interfaceiter_t *iter) {
- UNUSED(iter); /* Unused. */
- /*
- * Do nothing.
- */
-}
-
-static
-void internal_first(isc_interfaceiter_t *iter) {
- iter->pos = 0;
-}
diff --git a/libisc/inet_aton.c b/libisc/inet_aton.c
deleted file mode 100644
index 530b010..0000000
--- a/libisc/inet_aton.c
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Portions Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Portions Copyright (C) 1996-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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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.
- */
-
-/*
- * Copyright (c) 1983, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
- * 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, and that
- * the name of Digital Equipment Corporation not be used in advertising or
- * publicity pertaining to distribution of the document or software without
- * specific, written prior permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
- * CORPORATION 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
-static char rcsid[] = "$Id: inet_aton.c,v 1.15.12.3 2004/03/08 09:04:49 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <config.h>
-
-#include <ctype.h>
-#include <stddef.h> /* Required for NULL. */
-
-#include <isc/types.h>
-#include <isc/net.h>
-
-/*
- * Check whether "cp" is a valid ascii representation
- * of an Internet address and convert to a binary address.
- * Returns 1 if the address is valid, 0 if not.
- * This replaces inet_addr, the return value from which
- * cannot distinguish between failure and a local broadcast address.
- */
-int
-isc_net_aton(const char *cp, struct in_addr *addr) {
- unsigned long val;
- int base, n;
- unsigned char c;
- isc_uint8_t parts[4];
- isc_uint8_t *pp = parts;
- int digit;
-
- c = *cp;
- for (;;) {
- /*
- * Collect number up to ``.''.
- * Values are specified as for C:
- * 0x=hex, 0=octal, isdigit=decimal.
- */
- if (!isdigit(c & 0xff))
- return (0);
- val = 0; base = 10; digit = 0;
- if (c == '0') {
- c = *++cp;
- if (c == 'x' || c == 'X')
- base = 16, c = *++cp;
- else {
- base = 8;
- digit = 1;
- }
- }
- for (;;) {
- /*
- * isascii() is valid for all integer values, and
- * when it is true, c is known to be in scope
- * for isdigit(). No cast necessary. Similar
- * comment applies for later ctype uses.
- */
- if (isascii(c) && isdigit(c)) {
- if (base == 8 && (c == '8' || c == '9'))
- return (0);
- val = (val * base) + (c - '0');
- c = *++cp;
- digit = 1;
- } else if (base == 16 && isascii(c) && isxdigit(c)) {
- val = (val << 4) |
- (c + 10 - (islower(c) ? 'a' : 'A'));
- c = *++cp;
- digit = 1;
- } else
- break;
- }
- if (c == '.') {
- /*
- * Internet format:
- * a.b.c.d
- * a.b.c (with c treated as 16 bits)
- * a.b (with b treated as 24 bits)
- */
- if (pp >= parts + 3 || val > 0xff)
- return (0);
- *pp++ = (isc_uint8_t)val;
- c = *++cp;
- } else
- break;
- }
- /*
- * Check for trailing characters.
- */
- if (c != '\0' && (!isascii(c) || !isspace(c)))
- return (0);
- /*
- * Did we get a valid digit?
- */
- if (!digit)
- return (0);
- /*
- * Concoct the address according to
- * the number of parts specified.
- */
- n = pp - parts + 1;
- switch (n) {
- case 1: /* a -- 32 bits */
- break;
-
- case 2: /* a.b -- 8.24 bits */
- if (val > 0xffffff)
- return (0);
- val |= parts[0] << 24;
- break;
-
- case 3: /* a.b.c -- 8.8.16 bits */
- if (val > 0xffff)
- return (0);
- val |= (parts[0] << 24) | (parts[1] << 16);
- break;
-
- case 4: /* a.b.c.d -- 8.8.8.8 bits */
- if (val > 0xff)
- return (0);
- val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
- break;
- }
- if (addr != NULL)
- addr->s_addr = htonl(val);
-
- return (1);
-}
diff --git a/libisc/inet_ntop.c b/libisc/inet_ntop.c
deleted file mode 100644
index 395d0e5..0000000
--- a/libisc/inet_ntop.c
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright (C) 1996-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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] =
- "$Id: inet_ntop.c,v 1.13 2001/11/27 01:56:00 gson Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <config.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <isc/net.h>
-
-#include "ntp_sprintf.h"
-
-#define NS_INT16SZ 2
-#define NS_IN6ADDRSZ 16
-
-/*
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static const char *inet_ntop4(const unsigned char *src, char *dst,
- size_t size);
-
-#ifdef AF_INET6
-static const char *inet_ntop6(const unsigned char *src, char *dst,
- size_t size);
-#endif
-
-/* char *
- * isc_net_ntop(af, src, dst, size)
- * convert a network format address to presentation format.
- * return:
- * pointer to presentation format address (`dst'), or NULL (see errno).
- * author:
- * Paul Vixie, 1996.
- */
-const char *
-isc_net_ntop(int af, const void *src, char *dst, size_t size)
-{
- switch (af) {
- case AF_INET:
- return (inet_ntop4(src, dst, size));
-#ifdef AF_INET6
- case AF_INET6:
- return (inet_ntop6(src, dst, size));
-#endif
- default:
- errno = EAFNOSUPPORT;
- return (NULL);
- }
- /* NOTREACHED */
-}
-
-/* const char *
- * inet_ntop4(src, dst, size)
- * format an IPv4 address
- * return:
- * `dst' (as a const)
- * notes:
- * (1) uses no statics
- * (2) takes a unsigned char* not an in_addr as input
- * author:
- * Paul Vixie, 1996.
- */
-static const char *
-inet_ntop4(const unsigned char *src, char *dst, size_t size)
-{
- static const char *fmt = "%u.%u.%u.%u";
- char tmp[sizeof("255.255.255.255")];
-
- if (SPRINTF((tmp, fmt, src[0], src[1], src[2], src[3])) >= size)
- {
- errno = ENOSPC;
- return (NULL);
- }
- strcpy(dst, tmp);
-
- return (dst);
-}
-
-/* const char *
- * isc_inet_ntop6(src, dst, size)
- * convert IPv6 binary address into presentation (printable) format
- * author:
- * Paul Vixie, 1996.
- */
-#ifdef AF_INET6
-static const char *
-inet_ntop6(const unsigned char *src, char *dst, size_t size)
-{
- /*
- * Note that int32_t and int16_t need only be "at least" large enough
- * to contain a value of the specified size. On some systems, like
- * Crays, there is no such thing as an integer variable with 16 bits.
- * Keep this in mind if you think this function should have been coded
- * to use pointer overlays. All the world's not a VAX.
- */
- char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")], *tp;
- struct { int base, len; } best, cur;
- unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
- int i;
-
- /*
- * Preprocess:
- * Copy the input (bytewise) array into a wordwise array.
- * Find the longest run of 0x00's in src[] for :: shorthanding.
- */
- memset(words, '\0', sizeof(words));
- for (i = 0; i < NS_IN6ADDRSZ; i++)
- words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
- best.base = -1;
- best.len = 0;
- cur.base = -1;
- cur.len = 0;
- for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
- if (words[i] == 0) {
- if (cur.base == -1)
- cur.base = i, cur.len = 1;
- else
- cur.len++;
- } else {
- if (cur.base != -1) {
- if (best.base == -1 || cur.len > best.len)
- best = cur;
- cur.base = -1;
- }
- }
- }
- if (cur.base != -1) {
- if (best.base == -1 || cur.len > best.len)
- best = cur;
- }
- if (best.base != -1 && best.len < 2)
- best.base = -1;
-
- /*
- * Format the result.
- */
- tp = tmp;
- for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) {
- /* Are we inside the best run of 0x00's? */
- if (best.base != -1 && i >= best.base &&
- i < (best.base + best.len)) {
- if (i == best.base)
- *tp++ = ':';
- continue;
- }
- /* Are we following an initial run of 0x00s or any real hex? */
- if (i != 0)
- *tp++ = ':';
- /* Is this address an encapsulated IPv4? */
- if (i == 6 && best.base == 0 &&
- (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
- if (!inet_ntop4(src+12, tp,
- sizeof(tmp) - (tp - tmp)))
- return (NULL);
- tp += strlen(tp);
- break;
- }
- tp += SPRINTF((tp, "%x", words[i]));
- }
- /* Was it a trailing run of 0x00's? */
- if (best.base != -1 && (best.base + best.len) ==
- (NS_IN6ADDRSZ / NS_INT16SZ))
- *tp++ = ':';
- *tp++ = '\0';
-
- /*
- * Check for overflow, copy, and we're done.
- */
- if ((size_t)(tp - tmp) > size) {
- errno = ENOSPC;
- return (NULL);
- }
- strcpy(dst, tmp);
- return (dst);
-}
-#endif /* AF_INET6 */
diff --git a/libisc/inet_pton.c b/libisc/inet_pton.c
deleted file mode 100644
index afda394..0000000
--- a/libisc/inet_pton.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1996-2003 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] =
- "$Id: inet_pton.c,v 1.10.2.4.2.1 2004/03/06 08:14:31 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <config.h>
-
-#include <errno.h>
-#include <string.h>
-
-#include <isc/net.h>
-
-#define NS_INT16SZ 2
-#define NS_INADDRSZ 4
-#define NS_IN6ADDRSZ 16
-
-/*
- * WARNING: Don't even consider trying to compile this on a system where
- * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
- */
-
-static int inet_pton4(const char *src, unsigned char *dst);
-static int inet_pton6(const char *src, unsigned char *dst);
-
-/* int
- * isc_net_pton(af, src, dst)
- * convert from presentation format (which usually means ASCII printable)
- * to network format (which is usually some kind of binary format).
- * return:
- * 1 if the address was valid for the specified address family
- * 0 if the address wasn't valid (`dst' is untouched in this case)
- * -1 if some other error occurred (`dst' is untouched in this case, too)
- * author:
- * Paul Vixie, 1996.
- */
-int
-isc_net_pton(int af, const char *src, void *dst) {
- switch (af) {
- case AF_INET:
- return (inet_pton4(src, dst));
- case AF_INET6:
- return (inet_pton6(src, dst));
- default:
- errno = EAFNOSUPPORT;
- return (-1);
- }
- /* NOTREACHED */
-}
-
-/* int
- * inet_pton4(src, dst)
- * like inet_aton() but without all the hexadecimal and shorthand.
- * return:
- * 1 if `src' is a valid dotted quad, else 0.
- * notice:
- * does not touch `dst' unless it's returning 1.
- * author:
- * Paul Vixie, 1996.
- */
-static int
-inet_pton4(const char *src, unsigned char *dst) {
- static const char digits[] = "0123456789";
- int saw_digit, octets, ch;
- unsigned char tmp[NS_INADDRSZ], *tp;
-
- saw_digit = 0;
- octets = 0;
- *(tp = tmp) = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr(digits, ch)) != NULL) {
- unsigned int new = *tp * 10 + (pch - digits);
-
- if (saw_digit && *tp == 0)
- return (0);
- if (new > 255)
- return (0);
- *tp = (unsigned char) new;
- if (!saw_digit) {
- if (++octets > 4)
- return (0);
- saw_digit = 1;
- }
- } else if (ch == '.' && saw_digit) {
- if (octets == 4)
- return (0);
- *++tp = 0;
- saw_digit = 0;
- } else
- return (0);
- }
- if (octets < 4)
- return (0);
- memcpy(dst, tmp, NS_INADDRSZ);
- return (1);
-}
-
-/* int
- * inet_pton6(src, dst)
- * convert presentation level address to network order binary form.
- * return:
- * 1 if `src' is a valid [RFC1884 2.2] address, else 0.
- * notice:
- * (1) does not touch `dst' unless it's returning 1.
- * (2) :: in a full address is silently ignored.
- * credit:
- * inspired by Mark Andrews.
- * author:
- * Paul Vixie, 1996.
- */
-static int
-inet_pton6(const char *src, unsigned char *dst) {
- static const char xdigits_l[] = "0123456789abcdef",
- xdigits_u[] = "0123456789ABCDEF";
- unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
- const char *xdigits, *curtok;
- int ch, saw_xdigit;
- unsigned int val;
-
- memset((tp = tmp), '\0', NS_IN6ADDRSZ);
- endp = tp + NS_IN6ADDRSZ;
- colonp = NULL;
- /* Leading :: requires some special handling. */
- if (*src == ':')
- if (*++src != ':')
- return (0);
- curtok = src;
- saw_xdigit = 0;
- val = 0;
- while ((ch = *src++) != '\0') {
- const char *pch;
-
- if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
- pch = strchr((xdigits = xdigits_u), ch);
- if (pch != NULL) {
- val <<= 4;
- val |= (pch - xdigits);
- if (val > 0xffff)
- return (0);
- saw_xdigit = 1;
- continue;
- }
- if (ch == ':') {
- curtok = src;
- if (!saw_xdigit) {
- if (colonp)
- return (0);
- colonp = tp;
- continue;
- }
- if (tp + NS_INT16SZ > endp)
- return (0);
- *tp++ = (unsigned char) ((val >> 8) & 0xff);
- *tp++ = (unsigned char) (val & 0xff);
- saw_xdigit = 0;
- val = 0;
- continue;
- }
- if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
- inet_pton4(curtok, tp) > 0) {
- tp += NS_INADDRSZ;
- saw_xdigit = 0;
- break; /* '\0' was seen by inet_pton4(). */
- }
- return (0);
- }
- if (saw_xdigit) {
- if (tp + NS_INT16SZ > endp)
- return (0);
- *tp++ = (unsigned char) ((val >> 8) & 0xff);
- *tp++ = (unsigned char) (val & 0xff);
- }
- if (colonp != NULL) {
- /*
- * Since some memmove()'s erroneously fail to handle
- * overlapping regions, we'll do the shift by hand.
- */
- const int n = tp - colonp;
- int i;
-
- if (tp == endp)
- return (0);
- for (i = 1; i <= n; i++) {
- endp[- i] = colonp[n - i];
- colonp[n - i] = 0;
- }
- tp = endp;
- }
- if (tp != endp)
- return (0);
- memcpy(dst, tmp, NS_IN6ADDRSZ);
- return (1);
-}
diff --git a/libisc/interfaceiter.c b/libisc/interfaceiter.c
deleted file mode 100644
index 7e31975..0000000
--- a/libisc/interfaceiter.c
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2003 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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: interfaceiter.c,v 1.22.2.1.10.14 2004/08/28 06:25:22 marka Exp $ */
-
-#include <config.h>
-
-#define ISC_ONLY_IPV6
-
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#ifdef HAVE_SYS_SOCKIO_H
-#include <sys/sockio.h> /* Required for ifiter_ioctl.c. */
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <isc/interfaceiter.h>
-#include <isc/magic.h>
-#include <isc/mem.h>
-#include <isc/msgs.h>
-#include <isc/net.h>
-#include <isc/print.h>
-#include <isc/result.h>
-#include <isc/strerror.h>
-#include <isc/string.h>
-#include <isc/types.h>
-#include <isc/util.h>
-
-/* Must follow <isc/net.h>. */
-#ifdef HAVE_NET_IF6_H
-#include <net/if6.h>
-#endif
-
-/* Common utility functions */
-
-/*
- * Extract the network address part from a "struct sockaddr".
- *
- * The address family is given explicitly
- * instead of using src->sa_family, because the latter does not work
- * for copying a network mask obtained by SIOCGIFNETMASK (it does
- * not have a valid address family).
- */
-
-static void
-get_addr(unsigned int family, isc_netaddr_t *dst, struct sockaddr *src,
- char *ifname)
-{
- struct sockaddr_in6 *sa6;
-
-#if !defined(ISC_PLATFORM_HAVEIFNAMETOINDEX) || \
- !defined(ISC_PLATFORM_HAVESCOPEID)
- UNUSED(ifname);
-#endif
-
- /* clear any remaining value for safety */
- memset(dst, 0, sizeof(*dst));
-
- dst->family = family;
- switch (family) {
- case AF_INET:
- memcpy(&dst->type.in,
- &((struct sockaddr_in *) src)->sin_addr,
- sizeof(struct in_addr));
- break;
- case AF_INET6:
- sa6 = (struct sockaddr_in6 *)src;
- memcpy(&dst->type.in6, &sa6->sin6_addr,
- sizeof(struct in6_addr));
-#ifdef ISC_PLATFORM_HAVESCOPEID
- if (sa6->sin6_scope_id != 0)
- isc_netaddr_setzone(dst, sa6->sin6_scope_id);
- else {
- /*
- * BSD variants embed scope zone IDs in the 128bit
- * address as a kernel internal form. Unfortunately,
- * the embedded IDs are not hidden from applications
- * when getting access to them by sysctl or ioctl.
- * We convert the internal format to the pure address
- * part and the zone ID part.
- * Since multicast addresses should not appear here
- * and they cannot be distinguished from netmasks,
- * we only consider unicast link-local addresses.
- */
- if (IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr)) {
- isc_uint16_t zone16;
-
- memcpy(&zone16, &sa6->sin6_addr.s6_addr[2],
- sizeof(zone16));
- zone16 = ntohs(zone16);
- if (zone16 != 0) {
- /* the zone ID is embedded */
- isc_netaddr_setzone(dst,
- (isc_uint32_t)zone16);
- dst->type.in6.s6_addr[2] = 0;
- dst->type.in6.s6_addr[3] = 0;
-#ifdef ISC_PLATFORM_HAVEIFNAMETOINDEX
- } else if (ifname != NULL) {
- unsigned int zone;
-
- /*
- * sin6_scope_id is still not provided,
- * but the corresponding interface name
- * is know. Use the interface ID as
- * the link ID.
- */
- zone = if_nametoindex(ifname);
- if (zone != 0) {
- isc_netaddr_setzone(dst,
- (isc_uint32_t)zone);
- }
-#endif
- }
- }
- }
-#endif
- break;
- default:
- INSIST(0);
- break;
- }
-}
-
-/*
- * Include system-dependent code.
- */
-
-#if HAVE_GETIFADDRS
-#include "ifiter_getifaddrs.c"
-#elif HAVE_IFLIST_SYSCTL
-#include "ifiter_sysctl.c"
-#else
-#include "ifiter_ioctl.c"
-#endif
-
-/*
- * The remaining code is common to the sysctl and ioctl case.
- */
-
-isc_result_t
-isc_interfaceiter_current(isc_interfaceiter_t *iter,
- isc_interface_t *ifdata)
-{
- REQUIRE(iter->result == ISC_R_SUCCESS);
- memcpy(ifdata, &iter->current, sizeof(*ifdata));
- return (ISC_R_SUCCESS);
-}
-
-isc_result_t
-isc_interfaceiter_first(isc_interfaceiter_t *iter) {
- isc_result_t result;
-
- REQUIRE(VALID_IFITER(iter));
-
- internal_first(iter);
- for (;;) {
- result = internal_current(iter);
- if (result != ISC_R_IGNORE)
- break;
- result = internal_next(iter);
- if (result != ISC_R_SUCCESS)
- break;
- }
- iter->result = result;
- return (result);
-}
-
-isc_result_t
-isc_interfaceiter_next(isc_interfaceiter_t *iter) {
- isc_result_t result;
-
- REQUIRE(VALID_IFITER(iter));
- REQUIRE(iter->result == ISC_R_SUCCESS);
-
- for (;;) {
- result = internal_next(iter);
- if (result != ISC_R_SUCCESS)
- break;
- result = internal_current(iter);
- if (result != ISC_R_IGNORE)
- break;
- }
- iter->result = result;
- return (result);
-}
-
-void
-isc_interfaceiter_destroy(isc_interfaceiter_t **iterp)
-{
- isc_interfaceiter_t *iter;
- REQUIRE(iterp != NULL);
- iter = *iterp;
- REQUIRE(VALID_IFITER(iter));
-
- internal_destroy(iter);
- if (iter->buf != NULL)
- isc_mem_put(iter->mctx, iter->buf, iter->bufsize);
-
- iter->magic = 0;
- isc_mem_put(iter->mctx, iter, sizeof(*iter));
- *iterp = NULL;
-}
diff --git a/libisc/isc_strerror.c b/libisc/isc_strerror.c
deleted file mode 100644
index 9ec4a2f..0000000
--- a/libisc/isc_strerror.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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: strerror.c,v 1.3 2001/11/20 01:45:45 gson Exp $ */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <string.h>
-
-#include <isc/mutex.h>
-#include <isc/once.h>
-#include <isc/print.h>
-#include <isc/strerror.h>
-#include <isc/util.h>
-
-#include "l_stdlib.h"
-
-#ifdef HAVE_STRERROR
-/*
- * We need to do this this way for profiled locks.
- */
-static isc_mutex_t isc_strerror_lock;
-static void init_lock(void) {
- RUNTIME_CHECK(isc_mutex_init(&isc_strerror_lock) == ISC_R_SUCCESS);
-}
-#else
-extern const char * const sys_errlist[];
-extern const int sys_nerr;
-#endif
-
-void
-isc__strerror(int num, char *buf, size_t size) {
-#ifdef HAVE_STRERROR
- char *msg;
- unsigned int unum = num;
- static isc_once_t once = ISC_ONCE_INIT;
-
- REQUIRE(buf != NULL);
-
- RUNTIME_CHECK(isc_once_do(&once, init_lock) == ISC_R_SUCCESS);
-
- LOCK(&isc_strerror_lock);
- msg = strerror(num);
- if (msg != NULL)
- snprintf(buf, size, "%s", msg);
- else
- snprintf(buf, size, "Unknown error: %u", unum);
- UNLOCK(&isc_strerror_lock);
-#else
- unsigned int unum = num;
-
- REQUIRE(buf != NULL);
-
- if (num >= 0 && num < sys_nerr)
- snprintf(buf, size, "%s", sys_errlist[num]);
- else
- snprintf(buf, size, "Unknown error: %u", unum);
-#endif
-}
diff --git a/libisc/lib.c b/libisc/lib.c
deleted file mode 100644
index 95dd479..0000000
--- a/libisc/lib.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 1999-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: lib.c,v 1.9 2001/11/19 03:08:23 mayer Exp $ */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <isc/once.h>
-#include <isc/msgs.h>
-#include <isc/lib.h>
-
-/***
- *** Globals
- ***/
-
-LIBISC_EXTERNAL_DATA isc_msgcat_t * isc_msgcat = NULL;
-
-
-/***
- *** Private
- ***/
-
-static isc_once_t msgcat_once = ISC_ONCE_INIT;
-
-
-/***
- *** Functions
- ***/
-
-static void
-open_msgcat(void) {
- isc_msgcat_open("libisc.cat", &isc_msgcat);
-}
-
-void
-isc_lib_initmsgcat(void) {
- isc_result_t result;
-
- /*
- * Initialize the ISC library's message catalog, isc_msgcat, if it
- * has not already been initialized.
- */
-
- result = isc_once_do(&msgcat_once, open_msgcat);
- if (result != ISC_R_SUCCESS) {
- /*
- * Normally we'd use RUNTIME_CHECK() or FATAL_ERROR(), but
- * we can't do that here, since they might call us!
- * (Note that the catalog might be open anyway, so we might
- * as well try to provide an internationalized message.)
- */
- fprintf(stderr, "%s:%d: %s: isc_once_do() %s.\n",
- __FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FATALERROR, "fatal error"),
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
- ISC_MSG_FAILED, "failed"));
- abort();
- }
-}
diff --git a/libisc/mem.c b/libisc/mem.c
deleted file mode 100644
index 39f1e5c..0000000
--- a/libisc/mem.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 1997-2002 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: mem.c,v 1.113 2002/05/23 04:32:30 marka Exp $ */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-
-#include <isc/mem.h>
-#include <isc/util.h>
-
-void *
-isc_mem_get(isc_mem_t *ctx, size_t size) {
- UNUSED(ctx);
- if(size == 0)
- size = 1;
- return (malloc(size));
-}
-
-void
-isc_mem_put(isc_mem_t *ctx, void *ptr, size_t size)
-{
- UNUSED(ctx);
- UNUSED(size);
- free(ptr);
-}
-
diff --git a/libisc/msgcat.c b/libisc/msgcat.c
deleted file mode 100644
index 8253a06..0000000
--- a/libisc/msgcat.c
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 1999-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: msgcat.c,v 1.12 2001/11/30 01:59:39 gson Exp $ */
-
-/*
- * Principal Author: Bob Halley
- */
-
-#include <config.h>
-
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <isc/magic.h>
-#include <isc/msgcat.h>
-#include <isc/util.h>
-
-#ifdef HAVE_CATGETS
-#include <nl_types.h> /* Required for nl_catd. */
-#endif
-
-/*
- * Implementation Notes:
- *
- * We use malloc() and free() instead of isc_mem_get() and isc_mem_put()
- * because we don't want to require a memory context to be specified
- * in order to use a message catalog.
- */
-
-struct isc_msgcat {
- unsigned int magic;
-#ifdef HAVE_CATGETS
- nl_catd catalog;
-#endif
-};
-
-#define MSGCAT_MAGIC ISC_MAGIC('M', 'C', 'a', 't')
-#define VALID_MSGCAT(m) ISC_MAGIC_VALID(m, MSGCAT_MAGIC)
-
-void
-isc_msgcat_open(const char *name, isc_msgcat_t **msgcatp) {
- isc_msgcat_t *msgcat;
-
- /*
- * Open a message catalog.
- */
-
- REQUIRE(name != NULL);
- REQUIRE(msgcatp != NULL && *msgcatp == NULL);
-
- msgcat = malloc(sizeof(*msgcat));
- if (msgcat == NULL) {
- *msgcatp = NULL;
- return;
- }
-
-#ifdef HAVE_CATGETS
- /*
- * We don't check if catopen() fails because we don't care.
- * If it does fail, then when we call catgets(), it will use
- * the default string.
- */
- msgcat->catalog = catopen(name, 0);
-#endif
- msgcat->magic = MSGCAT_MAGIC;
-
- *msgcatp = msgcat;
-}
-
-void
-isc_msgcat_close(isc_msgcat_t **msgcatp) {
- isc_msgcat_t *msgcat;
-
- /*
- * Close a message catalog.
- */
-
- REQUIRE(msgcatp != NULL);
- msgcat = *msgcatp;
- REQUIRE(VALID_MSGCAT(msgcat) || msgcat == NULL);
-
- if (msgcat != NULL) {
-#ifdef HAVE_CATGETS
- if (msgcat->catalog != (nl_catd)(-1))
- (void)catclose(msgcat->catalog);
-#endif
- msgcat->magic = 0;
- free(msgcat);
- }
-
- *msgcatp = NULL;
-}
-
-const char *
-isc_msgcat_get(isc_msgcat_t *msgcat, int set, int message,
- const char *default_text)
-{
- /*
- * Get message 'message' from message set 'set' in 'msgcat'. If it
- * is not available, use 'default'.
- */
-
- REQUIRE(VALID_MSGCAT(msgcat) || msgcat == NULL);
- REQUIRE(set > 0);
- REQUIRE(message > 0);
- REQUIRE(default_text != NULL);
-
-#ifdef HAVE_CATGETS
- if (msgcat == NULL)
- return (default_text);
- return (catgets(msgcat->catalog, set, message, default_text));
-#else
- return (default_text);
-#endif
-}
diff --git a/libisc/net.c b/libisc/net.c
deleted file mode 100644
index 3d4ab66..0000000
--- a/libisc/net.c
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2003 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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: net.c,v 1.22.2.2.10.7 2004/04/29 01:31:22 marka Exp $ */
-
-#include <config.h>
-
-#include <errno.h>
-#include <unistd.h>
-
-#include <isc/net.h>
-#include <isc/once.h>
-#include <isc/strerror.h>
-#include <isc/string.h>
-#include <isc/util.h>
-
-#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRANY)
-const struct in6_addr isc_net_in6addrany = IN6ADDR_ANY_INIT;
-#endif
-
-#if defined(ISC_PLATFORM_HAVEIPV6) && defined(ISC_PLATFORM_NEEDIN6ADDRLOOPBACK)
-const struct in6_addr isc_net_in6addrloop = IN6ADDR_LOOPBACK_INIT;
-#endif
-
-static isc_boolean_t once = ISC_FALSE;
-static isc_once_t once_ipv6only = ISC_ONCE_INIT;
-static isc_once_t once_ipv6pktinfo = ISC_ONCE_INIT;
-static isc_result_t ipv4_result = ISC_R_NOTFOUND;
-static isc_result_t ipv6_result = ISC_R_NOTFOUND;
-static isc_result_t ipv6only_result = ISC_R_NOTFOUND;
-static isc_result_t ipv6pktinfo_result = ISC_R_NOTFOUND;
-
-static isc_result_t
-try_proto(int domain) {
- int s;
- isc_result_t result = ISC_R_SUCCESS;
- char strbuf[ISC_STRERRORSIZE];
-
- s = socket(domain, SOCK_STREAM, 0);
- if (s == -1) {
- switch (errno) {
-#ifdef EAFNOSUPPORT
- case EAFNOSUPPORT:
-#endif
-#ifdef EPROTONOSUPPORT
- case EPROTONOSUPPORT:
-#endif
-#ifdef EINVAL
- case EINVAL:
-#endif
- return (ISC_R_NOTFOUND);
- default:
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "socket() failed: %s",
- strbuf);
- return (ISC_R_UNEXPECTED);
- }
- }
-
-#ifdef ISC_PLATFORM_HAVEIPV6
-#ifdef WANT_IPV6
-#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
- if (domain == PF_INET6) {
- struct sockaddr_in6 sin6;
- GETSOCKNAME_SOCKLEN_TYPE len;
-
- /*
- * Check to see if IPv6 is broken, as is common on Linux.
- */
- len = sizeof(sin6);
- if (getsockname(s, (struct sockaddr *)&sin6, &len) < 0)
- {
- result = ISC_R_NOTFOUND;
- } else {
- if (len == sizeof(struct sockaddr_in6))
- result = ISC_R_SUCCESS;
- else {
- result = ISC_R_NOTFOUND;
- }
- }
- }
-#endif
-#endif
-#endif
-
- (void)close(s);
-
- return (result);
-}
-
-static void
-initialize_action(void) {
- ipv4_result = try_proto(PF_INET);
-#ifdef ISC_PLATFORM_HAVEIPV6
-#ifdef WANT_IPV6
-#ifdef ISC_PLATFORM_HAVEIN6PKTINFO
- ipv6_result = try_proto(PF_INET6);
-#endif
-#endif
-#endif
-}
-
-static void
-initialize(void) {
- if(once == ISC_FALSE) {
- initialize_action();
- once = ISC_TRUE;
- }
-}
-
-isc_result_t
-isc_net_probeipv4(void) {
- initialize();
- return (ipv4_result);
-}
-
-isc_result_t
-isc_net_probeipv6(void) {
- initialize();
- return (ipv6_result);
-}
-
-#ifdef ISC_PLATFORM_HAVEIPV6
-#ifdef WANT_IPV6
-static void
-try_ipv6only(void) {
-#ifdef IPV6_V6ONLY
- int s, on;
- char strbuf[ISC_STRERRORSIZE];
-#endif
- isc_result_t result;
-
- result = isc_net_probeipv6();
- if (result != ISC_R_SUCCESS) {
- ipv6only_result = result;
- return;
- }
-
-#ifndef IPV6_V6ONLY
- ipv6only_result = ISC_R_NOTFOUND;
- return;
-#else
- /* check for TCP sockets */
- s = socket(PF_INET6, SOCK_STREAM, 0);
- if (s == -1) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "socket() failed: %s",
- strbuf);
- ipv6only_result = ISC_R_UNEXPECTED;
- return;
- }
-
- on = 1;
- if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) {
- ipv6only_result = ISC_R_NOTFOUND;
- goto close;
- }
-
- close(s);
-
- /* check for UDP sockets */
- s = socket(PF_INET6, SOCK_DGRAM, 0);
- if (s == -1) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "socket() failed: %s",
- strbuf);
- ipv6only_result = ISC_R_UNEXPECTED;
- return;
- }
-
- on = 1;
- if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0) {
- ipv6only_result = ISC_R_NOTFOUND;
- goto close;
- }
-
- close(s);
-
- ipv6only_result = ISC_R_SUCCESS;
-
-close:
- close(s);
- return;
-#endif /* IPV6_V6ONLY */
-}
-
-static void
-initialize_ipv6only(void) {
- RUNTIME_CHECK(isc_once_do(&once_ipv6only,
- try_ipv6only) == ISC_R_SUCCESS);
-}
-
-static void
-try_ipv6pktinfo(void) {
- int s, on;
- char strbuf[ISC_STRERRORSIZE];
- isc_result_t result;
- int optname;
-
- result = isc_net_probeipv6();
- if (result != ISC_R_SUCCESS) {
- ipv6pktinfo_result = result;
- return;
- }
-
- /* we only use this for UDP sockets */
- s = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
- if (s == -1) {
- isc__strerror(errno, strbuf, sizeof(strbuf));
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- "socket() failed: %s",
- strbuf);
- ipv6pktinfo_result = ISC_R_UNEXPECTED;
- return;
- }
-
-#ifdef IPV6_RECVPKTINFO
- optname = IPV6_RECVPKTINFO;
-#else
- optname = IPV6_PKTINFO;
-#endif
- on = 1;
- if (setsockopt(s, IPPROTO_IPV6, optname, &on, sizeof(on)) < 0) {
- ipv6pktinfo_result = ISC_R_NOTFOUND;
- goto close;
- }
-
- close(s);
- ipv6pktinfo_result = ISC_R_SUCCESS;
-
-close:
- close(s);
- return;
-}
-
-static void
-initialize_ipv6pktinfo(void) {
- RUNTIME_CHECK(isc_once_do(&once_ipv6pktinfo,
- try_ipv6pktinfo) == ISC_R_SUCCESS);
-}
-#endif /* WANT_IPV6 */
-#endif /* ISC_PLATFORM_HAVEIPV6 */
-
-isc_result_t
-isc_net_probe_ipv6only(void) {
-#ifdef ISC_PLATFORM_HAVEIPV6
-#ifdef WANT_IPV6
- initialize_ipv6only();
-#else
- ipv6only_result = ISC_R_NOTFOUND;
-#endif
-#endif
- return (ipv6only_result);
-}
-
-isc_result_t
-isc_net_probe_ipv6pktinfo(void) {
-#ifdef ISC_PLATFORM_HAVEIPV6
-#ifdef WANT_IPV6
- initialize_ipv6pktinfo();
-#else
- ipv6pktinfo_result = ISC_R_NOTFOUND;
-#endif
-#endif
- return (ipv6pktinfo_result);
-}
-
-void
-isc_net_disableipv4(void) {
- initialize();
- if (ipv4_result == ISC_R_SUCCESS)
- ipv4_result = ISC_R_DISABLED;
-}
-
-void
-isc_net_disableipv6(void) {
- initialize();
- if (ipv6_result == ISC_R_SUCCESS)
- ipv6_result = ISC_R_DISABLED;
-}
-
-void
-isc_net_enableipv4(void) {
- initialize();
- if (ipv4_result == ISC_R_DISABLED)
- ipv4_result = ISC_R_SUCCESS;
-}
-
-void
-isc_net_enableipv6(void) {
- initialize();
- if (ipv6_result == ISC_R_DISABLED)
- ipv6_result = ISC_R_SUCCESS;
-}
diff --git a/libisc/netaddr.c b/libisc/netaddr.c
deleted file mode 100644
index 1fcd102..0000000
--- a/libisc/netaddr.c
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2002 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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: netaddr.c,v 1.18.12.9 2004/05/15 03:46:12 jinmei Exp $ */
-
-#include <config.h>
-
-#define ISC_ONLY_IPV6
-
-#include <stdio.h>
-
-#include <isc/buffer.h>
-#include <isc/msgs.h>
-#include <isc/net.h>
-#include <isc/netaddr.h>
-#include <isc/print.h>
-#include <isc/sockaddr.h>
-#include <isc/string.h>
-#include <isc/util.h>
-
-isc_boolean_t
-isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b) {
- REQUIRE(a != NULL && b != NULL);
-
- if (a->family != b->family)
- return (ISC_FALSE);
-
- if (a->zone != b->zone)
- return (ISC_FALSE);
-
- switch (a->family) {
- case AF_INET:
- if (a->type.in.s_addr != b->type.in.s_addr)
- return (ISC_FALSE);
- break;
- case AF_INET6:
- if (memcmp(&a->type.in6, &b->type.in6,
- sizeof(a->type.in6)) != 0 ||
- a->zone != b->zone)
- return (ISC_FALSE);
- break;
- default:
- return (ISC_FALSE);
- }
- return (ISC_TRUE);
-}
-
-isc_boolean_t
-isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,
- unsigned int prefixlen)
-{
- const unsigned char *pa, *pb;
- unsigned int ipabytes; /* Length of whole IP address in bytes */
- unsigned int nbytes; /* Number of significant whole bytes */
- unsigned int nbits; /* Number of significant leftover bits */
-
- REQUIRE(a != NULL && b != NULL);
-
- if (a->family != b->family)
- return (ISC_FALSE);
-
- if (a->zone != b->zone)
- return (ISC_FALSE);
-
- switch (a->family) {
- case AF_INET:
- pa = (const unsigned char *) &a->type.in;
- pb = (const unsigned char *) &b->type.in;
- ipabytes = 4;
- break;
- case AF_INET6:
- pa = (const unsigned char *) &a->type.in6;
- pb = (const unsigned char *) &b->type.in6;
- ipabytes = 16;
- break;
- default:
- pa = pb = NULL; /* Avoid silly compiler warning. */
- ipabytes = 0; /* Ditto. */
- return (ISC_FALSE);
- }
-
- /*
- * Don't crash if we get a pattern like 10.0.0.1/9999999.
- */
- if (prefixlen > ipabytes * 8)
- prefixlen = ipabytes * 8;
-
- nbytes = prefixlen / 8;
- nbits = prefixlen % 8;
-
- if (nbytes > 0) {
- if (memcmp(pa, pb, nbytes) != 0)
- return (ISC_FALSE);
- }
- if (nbits > 0) {
- unsigned int bytea, byteb, mask;
- INSIST(nbytes < ipabytes);
- INSIST(nbits < 8);
- bytea = pa[nbytes];
- byteb = pb[nbytes];
- mask = (0xFF << (8-nbits)) & 0xFF;
- if ((bytea & mask) != (byteb & mask))
- return (ISC_FALSE);
- }
- return (ISC_TRUE);
-}
-
-isc_result_t
-isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target) {
- char abuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255")];
- char zbuf[sizeof("%4294967295")];
- unsigned int alen;
- int zlen;
- const char *r;
- const void *type;
-
- REQUIRE(netaddr != NULL);
-
- switch (netaddr->family) {
- case AF_INET:
- type = &netaddr->type.in;
- break;
- case AF_INET6:
- type = &netaddr->type.in6;
- break;
- default:
- return (ISC_R_FAILURE);
- }
- r = inet_ntop(netaddr->family, type, abuf, sizeof(abuf));
- if (r == NULL)
- return (ISC_R_FAILURE);
-
- alen = strlen(abuf);
- INSIST(alen < sizeof(abuf));
-
- zlen = 0;
- if (netaddr->family == AF_INET6 && netaddr->zone != 0) {
- zlen = snprintf(zbuf, sizeof(zbuf), "%%%u", netaddr->zone);
- if (zlen < 0)
- return (ISC_R_FAILURE);
- INSIST((unsigned int)zlen < sizeof(zbuf));
- }
-
- if (alen + zlen > isc_buffer_availablelength(target))
- return (ISC_R_NOSPACE);
-
- isc_buffer_putmem(target, (unsigned char *)abuf, alen);
- isc_buffer_putmem(target, (unsigned char *)zbuf, zlen);
-
- return (ISC_R_SUCCESS);
-}
-
-void
-isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size) {
- isc_result_t result;
- isc_buffer_t buf;
-
- isc_buffer_init(&buf, array, size);
- result = isc_netaddr_totext(na, &buf);
-
- /*
- * Null terminate.
- */
- if (result == ISC_R_SUCCESS) {
- if (isc_buffer_availablelength(&buf) >= 1)
- isc_buffer_putuint8(&buf, 0);
- else
- result = ISC_R_NOSPACE;
- }
-
- if (result != ISC_R_SUCCESS) {
- snprintf(array, size,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_NETADDR,
- ISC_MSG_UNKNOWNADDR,
- "<unknown address, family %u>"),
- na->family);
- array[size - 1] = '\0';
- }
-}
-
-isc_result_t
-isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp) {
- unsigned int nbits, nbytes, ipbytes, i;
- const unsigned char *p;
-
- switch (s->family) {
- case AF_INET:
- p = (const unsigned char *) &s->type.in;
- ipbytes = 4;
- break;
- case AF_INET6:
- p = (const unsigned char *) &s->type.in6;
- ipbytes = 16;
- break;
- default:
- ipbytes = 0;
- return (ISC_R_NOTIMPLEMENTED);
- }
- nbytes = nbits = 0;
- for (i = 0; i < ipbytes; i++) {
- if (p[i] != 0xFF)
- break;
- }
- nbytes = i;
- if (i < ipbytes) {
- unsigned int c = p[nbytes];
- while ((c & 0x80) != 0 && nbits < 8) {
- c <<= 1; nbits++;
- }
- if ((c & 0xFF) != 0)
- return (ISC_R_MASKNONCONTIG);
- i++;
- }
- for (; i < ipbytes; i++) {
- if (p[i] != 0)
- return (ISC_R_MASKNONCONTIG);
- i++;
- }
- *lenp = nbytes * 8 + nbits;
- return (ISC_R_SUCCESS);
-}
-
-void
-isc_netaddr_fromin(isc_netaddr_t *netaddr, const struct in_addr *ina) {
- memset(netaddr, 0, sizeof(*netaddr));
- netaddr->family = AF_INET;
- netaddr->type.in = *ina;
-}
-
-void
-isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6) {
- memset(netaddr, 0, sizeof(*netaddr));
- netaddr->family = AF_INET6;
- netaddr->type.in6 = *ina6;
-}
-
-void
-isc_netaddr_setzone(isc_netaddr_t *netaddr, isc_uint32_t zone) {
- /* we currently only support AF_INET6. */
- REQUIRE(netaddr->family == AF_INET6);
-
- netaddr->zone = zone;
-}
-
-isc_uint32_t
-isc_netaddr_getzone(const isc_netaddr_t *netaddr) {
- return (netaddr->zone);
-}
-
-void
-isc_netaddr_fromsockaddr(isc_netaddr_t *t, const isc_sockaddr_t *s) {
- int family = s->type.sa.sa_family;
- t->family = family;
- switch (family) {
- case AF_INET:
- t->type.in = s->type.sin.sin_addr;
- t->zone = 0;
- break;
- case AF_INET6:
- memcpy(&t->type.in6, &s->type.sin6.sin6_addr, 16);
-#ifdef ISC_PLATFORM_HAVESCOPEID
- t->zone = s->type.sin6.sin6_scope_id;
-#else
- t->zone = 0;
-#endif
- break;
- default:
- INSIST(0);
- }
-}
-
-void
-isc_netaddr_any(isc_netaddr_t *netaddr) {
- memset(netaddr, 0, sizeof(*netaddr));
- netaddr->family = AF_INET;
- netaddr->type.in.s_addr = INADDR_ANY;
-}
-
-#ifdef ISC_PLATFORM_HAVEIPV6
-void
-isc_netaddr_any6(isc_netaddr_t *netaddr) {
- memset(netaddr, 0, sizeof(*netaddr));
- netaddr->family = AF_INET6;
- netaddr->type.in6 = in6addr_any;
-}
-#endif
-
-isc_boolean_t
-isc_netaddr_ismulticast(isc_netaddr_t *na) {
- switch (na->family) {
- case AF_INET:
- return (ISC_TF(ISC_IPADDR_ISMULTICAST(na->type.in.s_addr)));
- case AF_INET6:
- return (ISC_TF(IN6_IS_ADDR_MULTICAST(&na->type.in6)));
- default:
- return (ISC_FALSE); /* XXXMLG ? */
- }
-}
-
-isc_boolean_t
-isc_netaddr_isexperimental(isc_netaddr_t *na) {
- switch (na->family) {
- case AF_INET:
- return (ISC_TF(ISC_IPADDR_ISEXPERIMENTAL(na->type.in.s_addr)));
- default:
- return (ISC_FALSE); /* XXXMLG ? */
- }
-}
-
-isc_boolean_t
-isc_netaddr_islinklocal(isc_netaddr_t *na) {
- switch (na->family) {
- case AF_INET:
- return (ISC_FALSE);
- case AF_INET6:
- return (ISC_TF(IN6_IS_ADDR_LINKLOCAL(&na->type.in6)));
- default:
- return (ISC_FALSE);
- }
-}
-
-isc_boolean_t
-isc_netaddr_issitelocal(isc_netaddr_t *na) {
- switch (na->family) {
- case AF_INET:
- return (ISC_FALSE);
- case AF_INET6:
- return (ISC_TF(IN6_IS_ADDR_SITELOCAL(&na->type.in6)));
- default:
- return (ISC_FALSE);
- }
-}
-
-#ifdef ISC_PLATFORM_HAVEIPV6
-void
-isc_netaddr_fromv4mapped(isc_netaddr_t *t, const isc_netaddr_t *s) {
- isc_netaddr_t *src;
-
- DE_CONST(s, src); /* Must come before IN6_IS_ADDR_V4MAPPED. */
-
- REQUIRE(s->family == AF_INET6);
- REQUIRE(IN6_IS_ADDR_V4MAPPED(&src->type.in6));
-
- memset(t, 0, sizeof(*t));
- t->family = AF_INET;
- memcpy(&t->type.in, (char *)&src->type.in6 + 12, 4);
- return;
-}
-#endif
diff --git a/libisc/netscope.c b/libisc/netscope.c
deleted file mode 100644
index f0bffc4..0000000
--- a/libisc/netscope.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 2002 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] =
- "$Id: netscope.c,v 1.5.142.7 2004/03/12 10:31:26 marka Exp $";
-#endif /* LIBC_SCCS and not lint */
-
-#include <config.h>
-
-#include <isc/string.h>
-#include <isc/net.h>
-#include <isc/netscope.h>
-#include <isc/result.h>
-
-isc_result_t
-isc_netscope_pton(int af, char *scopename, void *addr, isc_uint32_t *zoneid) {
- char *ep;
-#ifdef ISC_PLATFORM_HAVEIFNAMETOINDEX
- unsigned int ifid;
-#endif
- struct in6_addr *in6;
- isc_uint32_t zone;
- isc_uint64_t llz;
-
- /* at this moment, we only support AF_INET6 */
- if (af != AF_INET6)
- return (ISC_R_FAILURE);
-
- in6 = (struct in6_addr *)addr;
-
- /*
- * Basically, "names" are more stable than numeric IDs in terms of
- * renumbering, and are more preferred. However, since there is no
- * standard naming convention and APIs to deal with the names. Thus,
- * we only handle the case of link-local addresses, for which we use
- * interface names as link names, assuming one to one mapping between
- * interfaces and links.
- */
-#ifdef ISC_PLATFORM_HAVEIFNAMETOINDEX
- if (IN6_IS_ADDR_LINKLOCAL(in6) &&
- (ifid = if_nametoindex((const char *)scopename)) != 0)
- zone = (isc_uint32_t)ifid;
- else {
-#endif
- llz = isc_string_touint64(scopename, &ep, 10);
- if (ep == scopename)
- return (ISC_R_FAILURE);
-
- /* check overflow */
- zone = (isc_uint32_t)(llz & 0xffffffffUL);
- if (zone != llz)
- return (ISC_R_FAILURE);
-#ifdef ISC_PLATFORM_HAVEIFNAMETOINDEX
- }
-#endif
-
- *zoneid = zone;
- return (ISC_R_SUCCESS);
-}
diff --git a/libisc/sockaddr.c b/libisc/sockaddr.c
deleted file mode 100644
index 33d7a1b..0000000
--- a/libisc/sockaddr.c
+++ /dev/null
@@ -1,480 +0,0 @@
-/*
- * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
- * Copyright (C) 1999-2003 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 ISC DISCLAIMS ALL WARRANTIES WITH
- * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- * AND FITNESS. IN NO EVENT SHALL ISC 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: sockaddr.c,v 1.48.2.1.2.10 2004/05/15 03:46:12 jinmei Exp $ */
-
-#include <config.h>
-
-#define ISC_ONLY_IPV6
-
-#include <stdio.h>
-
-#include <isc/buffer.h>
-/*
- * We currently don't need hashing here
- */
-#if 0
-#include <isc/hash.h>
-#endif
-
-#include <isc/msgs.h>
-#include <isc/netaddr.h>
-#include <isc/print.h>
-#include <isc/region.h>
-#include <isc/sockaddr.h>
-#include <isc/string.h>
-#include <isc/util.h>
-
-isc_boolean_t
-isc_sockaddr_equal(const isc_sockaddr_t *a, const isc_sockaddr_t *b) {
- REQUIRE(a != NULL && b != NULL);
-
- if (a->length != b->length)
- return (ISC_FALSE);
-
- /*
- * We don't just memcmp because the sin_zero field isn't always
- * zero.
- */
-
- if (a->type.sa.sa_family != b->type.sa.sa_family)
- return (ISC_FALSE);
- switch (a->type.sa.sa_family) {
- case AF_INET:
- if (memcmp(&a->type.sin.sin_addr, &b->type.sin.sin_addr,
- sizeof(a->type.sin.sin_addr)) != 0)
- return (ISC_FALSE);
- if (a->type.sin.sin_port != b->type.sin.sin_port)
- return (ISC_FALSE);
- break;
- case AF_INET6:
- if (memcmp(&a->type.sin6.sin6_addr, &b->type.sin6.sin6_addr,
- sizeof(a->type.sin6.sin6_addr)) != 0)
- return (ISC_FALSE);
-#ifdef ISC_PLATFORM_HAVESCOPEID
- if (a->type.sin6.sin6_scope_id != b->type.sin6.sin6_scope_id)
- return (ISC_FALSE);
-#endif
- if (a->type.sin6.sin6_port != b->type.sin6.sin6_port)
- return (ISC_FALSE);
- break;
- default:
- if (memcmp(&a->type, &b->type, a->length) != 0)
- return (ISC_FALSE);
- }
- return (ISC_TRUE);
-}
-
-isc_boolean_t
-isc_sockaddr_eqaddr(const isc_sockaddr_t *a, const isc_sockaddr_t *b) {
- REQUIRE(a != NULL && b != NULL);
-
- if (a->length != b->length)
- return (ISC_FALSE);
-
- if (a->type.sa.sa_family != b->type.sa.sa_family)
- return (ISC_FALSE);
- switch (a->type.sa.sa_family) {
- case AF_INET:
- if (memcmp(&a->type.sin.sin_addr, &b->type.sin.sin_addr,
- sizeof(a->type.sin.sin_addr)) != 0)
- return (ISC_FALSE);
- break;
- case AF_INET6:
- if (memcmp(&a->type.sin6.sin6_addr, &b->type.sin6.sin6_addr,
- sizeof(a->type.sin6.sin6_addr)) != 0)
- return (ISC_FALSE);
-#ifdef ISC_PLATFORM_HAVESCOPEID
- if (a->type.sin6.sin6_scope_id != b->type.sin6.sin6_scope_id)
- return (ISC_FALSE);
-#endif
- break;
- default:
- if (memcmp(&a->type, &b->type, a->length) != 0)
- return (ISC_FALSE);
- }
- return (ISC_TRUE);
-}
-
-isc_boolean_t
-isc_sockaddr_eqaddrprefix(const isc_sockaddr_t *a, const isc_sockaddr_t *b,
- unsigned int prefixlen)
-{
- isc_netaddr_t na, nb;
- isc_netaddr_fromsockaddr(&na, a);
- isc_netaddr_fromsockaddr(&nb, b);
- return (isc_netaddr_eqprefix(&na, &nb, prefixlen));
-}
-
-isc_result_t
-isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) {
- isc_result_t result;
- isc_netaddr_t netaddr;
- char pbuf[sizeof("65000")];
- unsigned int plen;
- isc_region_t avail;
-
- REQUIRE(sockaddr != NULL);
-
- /*
- * Do the port first, giving us the opportunity to check for
- * unsupported address families before calling
- * isc_netaddr_fromsockaddr().
- */
- switch (sockaddr->type.sa.sa_family) {
- case AF_INET:
- snprintf(pbuf, sizeof(pbuf), "%u", ntohs(sockaddr->type.sin.sin_port));
- break;
- case AF_INET6:
- snprintf(pbuf, sizeof(pbuf), "%u", ntohs(sockaddr->type.sin6.sin6_port));
- break;
- default:
- return (ISC_R_FAILURE);
- }
-
- plen = strlen(pbuf);
- INSIST(plen < sizeof(pbuf));
-
- isc_netaddr_fromsockaddr(&netaddr, sockaddr);
- result = isc_netaddr_totext(&netaddr, target);
- if (result != ISC_R_SUCCESS)
- return (result);
-
- if (1 + plen + 1 > isc_buffer_availablelength(target))
- return (ISC_R_NOSPACE);
-
- isc_buffer_putmem(target, (const unsigned char *)"#", 1);
- isc_buffer_putmem(target, (const unsigned char *)pbuf, plen);
-
- /*
- * Null terminate after used region.
- */
- isc_buffer_availableregion(target, &avail);
- INSIST(avail.length >= 1);
- avail.base[0] = '\0';
-
- return (ISC_R_SUCCESS);
-}
-
-void
-isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size) {
- isc_result_t result;
- isc_buffer_t buf;
-
- isc_buffer_init(&buf, array, size);
- result = isc_sockaddr_totext(sa, &buf);
- if (result != ISC_R_SUCCESS) {
- /*
- * The message is the same as in netaddr.c.
- */
- snprintf(array, size,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_NETADDR,
- ISC_MSG_UNKNOWNADDR,
- "<unknown address, family %u>"),
- sa->type.sa.sa_family);
- array[size - 1] = '\0';
- }
-}
-
-#if 0
-/*
- * We currently don't need hashing here
- */
-unsigned int
-isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only) {
- unsigned int length = 0;
- const unsigned char *s = NULL;
- unsigned int h = 0;
- unsigned int g;
- unsigned int p = 0;
- const struct in6_addr *in6;
-
- REQUIRE(sockaddr != NULL);
-
- switch (sockaddr->type.sa.sa_family) {
- case AF_INET:
- s = (const unsigned char *)&sockaddr->type.sin.sin_addr;
- p = ntohs(sockaddr->type.sin.sin_port);
- length = sizeof(sockaddr->type.sin.sin_addr.s_addr);
- break;
-#if ISC_PLATFORM_HAVEIPV6
- case AF_INET6:
- in6 = &sockaddr->type.sin6.sin6_addr;
- if (IN6_IS_ADDR_V4MAPPED(in6)) {
- s = (const unsigned char *)&in6[12];
- length = sizeof(sockaddr->type.sin.sin_addr.s_addr);
- } else {
- s = (const unsigned char *)in6;
- length = sizeof(sockaddr->type.sin6.sin6_addr);
- }
- p = ntohs(sockaddr->type.sin6.sin6_port);
- break;
-#endif
- default:
- UNEXPECTED_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat,
- ISC_MSGSET_SOCKADDR,
- ISC_MSG_UNKNOWNFAMILY,
- "unknown address family: %d"),
- (int)sockaddr->type.sa.sa_family);
- s = (const unsigned char *)&sockaddr->type;
- length = sockaddr->length;
- p = 0;
- }
-
- h = isc_hash_calc(s, length, ISC_TRUE);
- if (!address_only) {
- g = isc_hash_calc((const unsigned char *)&p, sizeof(p),
- ISC_TRUE);
- h = h ^ g; /* XXX: we should concatenate h and p first */
- }
-
- return (h);
-}
-#endif
-
-void
-isc_sockaddr_any(isc_sockaddr_t *sockaddr)
-{
- memset(sockaddr, 0, sizeof(*sockaddr));
- sockaddr->type.sin.sin_family = AF_INET;
-#ifdef ISC_PLATFORM_HAVESALEN
- sockaddr->type.sin.sin_len = sizeof(sockaddr->type.sin);
-#endif
- sockaddr->type.sin.sin_addr.s_addr = INADDR_ANY;
- sockaddr->type.sin.sin_port = 0;
- sockaddr->length = sizeof(sockaddr->type.sin);
- ISC_LINK_INIT(sockaddr, link);
-}
-
-void
-isc_sockaddr_any6(isc_sockaddr_t *sockaddr)
-{
-#ifdef ISC_PLATFORM_HAVEIPV6
- memset(sockaddr, 0, sizeof(*sockaddr));
- sockaddr->type.sin6.sin6_family = AF_INET6;
-#ifdef ISC_PLATFORM_HAVESALEN
- sockaddr->type.sin6.sin6_len = sizeof(sockaddr->type.sin6);
-#endif
- sockaddr->type.sin6.sin6_addr = in6addr_any;
- sockaddr->type.sin6.sin6_port = 0;
- sockaddr->length = sizeof(sockaddr->type.sin6);
- ISC_LINK_INIT(sockaddr, link);
-#endif
-}
-
-void
-isc_sockaddr_fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
- in_port_t port)
-{
- memset(sockaddr, 0, sizeof(*sockaddr));
- sockaddr->type.sin.sin_family = AF_INET;
-#ifdef ISC_PLATFORM_HAVESALEN
- sockaddr->type.sin.sin_len = sizeof(sockaddr->type.sin);
-#endif
- sockaddr->type.sin.sin_addr = *ina;
- sockaddr->type.sin.sin_port = htons(port);
- sockaddr->length = sizeof(sockaddr->type.sin);
- ISC_LINK_INIT(sockaddr, link);
-}
-
-void
-isc_sockaddr_anyofpf(isc_sockaddr_t *sockaddr, int pf) {
- switch (pf) {
- case AF_INET:
- isc_sockaddr_any(sockaddr);
- break;
- case AF_INET6:
- isc_sockaddr_any6(sockaddr);
- break;
- default:
- INSIST(0);
- }
-}
-
-void
-isc_sockaddr_fromin6(isc_sockaddr_t *sockaddr, const struct in6_addr *ina6,
- in_port_t port)
-{
- memset(sockaddr, 0, sizeof(*sockaddr));
- sockaddr->type.sin6.sin6_family = AF_INET6;
-#ifdef ISC_PLATFORM_HAVESALEN
- sockaddr->type.sin6.sin6_len = sizeof(sockaddr->type.sin6);
-#endif
- sockaddr->type.sin6.sin6_addr = *ina6;
- sockaddr->type.sin6.sin6_port = htons(port);
- sockaddr->length = sizeof(sockaddr->type.sin6);
- ISC_LINK_INIT(sockaddr, link);
-}
-
-void
-isc_sockaddr_v6fromin(isc_sockaddr_t *sockaddr, const struct in_addr *ina,
- in_port_t port)
-{
- memset(sockaddr, 0, sizeof(*sockaddr));
- sockaddr->type.sin6.sin6_family = AF_INET6;
-#ifdef ISC_PLATFORM_HAVESALEN
- sockaddr->type.sin6.sin6_len = sizeof(sockaddr->type.sin6);
-#endif
- sockaddr->type.sin6.sin6_addr.s6_addr[10] = 0xff;
- sockaddr->type.sin6.sin6_addr.s6_addr[11] = 0xff;
- memcpy(&sockaddr->type.sin6.sin6_addr.s6_addr[12], ina, 4);
- sockaddr->type.sin6.sin6_port = htons(port);
- sockaddr->length = sizeof(sockaddr->type.sin6);
- ISC_LINK_INIT(sockaddr, link);
-}
-
-int
-isc_sockaddr_pf(const isc_sockaddr_t *sockaddr) {
-
- /*
- * Get the protocol family of 'sockaddr'.
- */
-
-#if (AF_INET == PF_INET && AF_INET6 == PF_INET6)
- /*
- * Assume that PF_xxx == AF_xxx for all AF and PF.
- */
- return (sockaddr->type.sa.sa_family);
-#else
- switch (sockaddr->type.sa.sa_family) {
- case AF_INET:
- return (PF_INET);
- case AF_INET6:
- return (PF_INET6);
- default:
- FATAL_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKADDR,
- ISC_MSG_UNKNOWNFAMILY,
- "unknown address family: %d"),
- (int)sockaddr->type.sa.sa_family);
- }
-#endif
-}
-
-void
-isc_sockaddr_fromnetaddr(isc_sockaddr_t *sockaddr, const isc_netaddr_t *na,
- in_port_t port)
-{
- memset(sockaddr, 0, sizeof(*sockaddr));
- sockaddr->type.sin.sin_family = na->family;
- switch (na->family) {
- case AF_INET:
- sockaddr->length = sizeof(sockaddr->type.sin);
-#ifdef ISC_PLATFORM_HAVESALEN
- sockaddr->type.sin.sin_len = sizeof(sockaddr->type.sin);
-#endif
- sockaddr->type.sin.sin_addr = na->type.in;
- sockaddr->type.sin.sin_port = htons(port);
- break;
- case AF_INET6:
- sockaddr->length = sizeof(sockaddr->type.sin6);
-#ifdef ISC_PLATFORM_HAVESALEN
- sockaddr->type.sin6.sin6_len = sizeof(sockaddr->type.sin6);
-#endif
- memcpy(&sockaddr->type.sin6.sin6_addr, &na->type.in6, 16);
-#ifdef ISC_PLATFORM_HAVESCOPEID
- sockaddr->type.sin6.sin6_scope_id = isc_netaddr_getzone(na);
-#endif
- sockaddr->type.sin6.sin6_port = htons(port);
- break;
- default:
- INSIST(0);
- }
- ISC_LINK_INIT(sockaddr, link);
-}
-
-void
-isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port) {
- switch (sockaddr->type.sa.sa_family) {
- case AF_INET:
- sockaddr->type.sin.sin_port = htons(port);
- break;
- case AF_INET6:
- sockaddr->type.sin6.sin6_port = htons(port);
- break;
- default:
- FATAL_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKADDR,
- ISC_MSG_UNKNOWNFAMILY,
- "unknown address family: %d"),
- (int)sockaddr->type.sa.sa_family);
- }
-}
-
-in_port_t
-isc_sockaddr_getport(isc_sockaddr_t *sockaddr) {
- in_port_t port = 0;
-
- switch (sockaddr->type.sa.sa_family) {
- case AF_INET:
- port = ntohs(sockaddr->type.sin.sin_port);
- break;
- case AF_INET6:
- port = ntohs(sockaddr->type.sin6.sin6_port);
- break;
- default:
- FATAL_ERROR(__FILE__, __LINE__,
- isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKADDR,
- ISC_MSG_UNKNOWNFAMILY,
- "unknown address family: %d"),
- (int)sockaddr->type.sa.sa_family);
- }
-
- return (port);
-}
-
-isc_boolean_t
-isc_sockaddr_ismulticast(isc_sockaddr_t *sockaddr) {
- isc_netaddr_t netaddr;
-
- isc_netaddr_fromsockaddr(&netaddr, sockaddr);
- return (isc_netaddr_ismulticast(&netaddr));
-}
-
-isc_boolean_t
-isc_sockaddr_isexperimental(isc_sockaddr_t *sockaddr) {
- isc_netaddr_t netaddr;
-
- if (sockaddr->type.sa.sa_family == AF_INET) {
- isc_netaddr_fromsockaddr(&netaddr, sockaddr);
- return (isc_netaddr_isexperimental(&netaddr));
- }
- return (ISC_FALSE);
-}
-
-isc_boolean_t
-isc_sockaddr_issitelocal(isc_sockaddr_t *sockaddr) {
- isc_netaddr_t netaddr;
-
- if (sockaddr->type.sa.sa_family == AF_INET6) {
- isc_netaddr_fromsockaddr(&netaddr, sockaddr);
- return (isc_netaddr_issitelocal(&netaddr));
- }
- return (ISC_FALSE);
-}
-
-isc_boolean_t
-isc_sockaddr_islinklocal(isc_sockaddr_t *sockaddr) {
- isc_netaddr_t netaddr;
-
- if (sockaddr->type.sa.sa_family == AF_INET6) {
- isc_netaddr_fromsockaddr(&netaddr, sockaddr);
- return (isc_netaddr_islinklocal(&netaddr));
- }
- return (ISC_FALSE);
-}
diff --git a/libisc/strerror.c b/libisc/strerror.c
deleted file mode 100644
index 4a0f8d8..0000000
--- a/libisc/strerror.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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: strerror.c,v 1.3 2001/11/20 01:45:45 gson Exp $ */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <string.h>
-
-#include <isc/mutex.h>
-#include <isc/once.h>
-#include <isc/print.h>
-#include <isc/strerror.h>
-#include <isc/util.h>
-
-#ifdef HAVE_STRERROR
-/*
- * We need to do this this way for profiled locks.
- */
-static isc_mutex_t isc_strerror_lock;
-static void init_lock(void) {
- RUNTIME_CHECK(isc_mutex_init(&isc_strerror_lock) == ISC_R_SUCCESS);
-}
-#else
-extern const char * const sys_errlist[];
-extern const int sys_nerr;
-#endif
-
-void
-isc__strerror(int num, char *buf, size_t size) {
-#ifdef HAVE_STRERROR
- char *msg;
- unsigned int unum = num;
- static isc_once_t once = ISC_ONCE_INIT;
-
- REQUIRE(buf != NULL);
-
- RUNTIME_CHECK(isc_once_do(&once, init_lock) == ISC_R_SUCCESS);
-
- LOCK(&isc_strerror_lock);
- msg = strerror(num);
- if (msg != NULL)
- snprintf(buf, size, "%s", msg);
- else
- snprintf(buf, size, "Unknown error: %u", unum);
- UNLOCK(&isc_strerror_lock);
-#else
- unsigned int unum = num;
-
- REQUIRE(buf != NULL);
-
- if (num >= 0 && num < sys_nerr)
- snprintf(buf, size, "%s", sys_errlist[num]);
- else
- snprintf(buf, size, "Unknown error: %u", unum);
-#endif
-}
OpenPOWER on IntegriCloud