getipnode.c revision dafcb997e390efa4423883dafd100c975c4095d6
2728d0618e15ee3a2ecc5f6d15acd7898e6de85aTinderbox User * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * Copyright (C) 1999-2003 Internet Software Consortium.
7e09576b7739de29ade3fc4d11daa1836d300459Tinderbox User * Permission to use, copy, modify, and distribute this software for any
7e09576b7739de29ade3fc4d11daa1836d300459Tinderbox User * purpose with or without fee is hereby granted, provided that the above
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * copyright notice and this permission notice appear in all copies.
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews/* $Id: getipnode.c,v 1.37 2004/03/05 05:12:45 marka Exp $ */
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews#include <lwres/netdb.h> /* XXX #include <netdb.h> */
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark AndrewsLIBLWRES_EXTERNAL_DATA const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrewsstatic const unsigned char in6addr_compat[12] = {
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews#define IN6_IS_ADDR_V4COMPAT(x) (!memcmp((x)->s6_addr, in6addr_compat, 12) && \
f5c17a057fc5974bb51d7bc8c5827a7fd6dc9aeeEvan Hunt#define IN6_IS_ADDR_V4MAPPED(x) (!memcmp((x)->s6_addr, in6addr_mapped, 12))
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews *** Forward declarations.
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrewsstatic struct hostent *
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrewscopyandmerge(struct hostent *, struct hostent *, int, int *);
78608b0a454246d0e1e0169f1d671b8427e48199Francis Dupontstatic struct hostent *
78608b0a454246d0e1e0169f1d671b8427e48199Francis Duponthostfromaddr(lwres_gnbaresponse_t *addr, int af, const void *src);
78608b0a454246d0e1e0169f1d671b8427e48199Francis Dupontstatic struct hostent *
78608b0a454246d0e1e0169f1d671b8427e48199Francis Duponthostfromname(lwres_gabnresponse_t *name, int af);
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews *** Public functions.
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * AI_V4MAPPED + AF_INET6
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * If no IPv6 address then a query for IPv4 and map returned values.
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * AI_ALL + AI_V4MAPPED + AF_INET6
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * Return IPv6 and IPv4 mapped.
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * AI_ADDRCONFIG
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * Only return IPv6 / IPv4 address if there is an interface of that
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrews * type active.
c40906dfad6dd6e3a3e3c94b8c8847bc9bc064e5Mark Andrewslwres_getipnodebyname(const char *name, int af, int flags, int *error_num) {
f5c17a057fc5974bb51d7bc8c5827a7fd6dc9aeeEvan Hunt struct hostent he, *he1 = NULL, *he2 = NULL, *he3 = NULL;
f5c17a057fc5974bb51d7bc8c5827a7fd6dc9aeeEvan Hunt * If we care about active interfaces then check.
return (NULL);
return (NULL);
const char *const_name;
char *deconst_name;
goto cleanup;
goto cleanup;
if (have_v4 &&
goto cleanup;
if (n == LWRES_R_NOTFOUND)
goto cleanup;
return (he3);
struct hostent *
const void *konst;
return (NULL);
switch (af) {
case AF_INET:
return (NULL);
case AF_INET6:
return (NULL);
return (NULL);
* Look up IPv4 and IPv4 mapped/compatible addresses.
if (n == LWRES_R_SUCCESS)
if (n == LWRES_R_SUCCESS)
if (n != LWRES_R_SUCCESS) {
if (n == LWRES_R_NOTFOUND)
return (NULL);
return (he1);
return (NULL);
return (he2);
return (NULL);
if (n == LWRES_R_SUCCESS)
if (n == LWRES_R_SUCCESS)
return (NULL);
return (he1);
char **cpp;
cpp++;
addresses++;
cpp++;
names++;
!defined(IRIX_EMUL_IOCTL_SIOCGIFCONF)
#ifdef __hpux
#ifdef __hpux
int s, cpsize, n;
goto err_ret;
goto err_ret;
#ifdef ISC_HAVE_LIFC_FAMILY
#ifdef ISC_HAVE_LIFC_FLAGS
goto err_ret;
goto err_ret;
#ifdef LWRES_PLATFORM_HAVESALEN
#ifdef FIX_ZERO_SA_LEN
#ifdef HAVE_MINIMUM_IFREQ
(int)(sizeof(struct sockaddr));
case AF_INET:
if (*have_v4 == 0) {
&((struct sockaddr_in *)
sizeof(in4));
case AF_INET6:
if (*have_v6 == 0) {
&((struct sockaddr_in6 *)
sizeof(in6));
sizeof(in6)) == 0)
close(s);
close(s);
!defined(IRIX_EMUL_IOCTL_SIOCGIFCONF)
goto err_ret;
goto err_ret;
#ifdef IRIX_EMUL_IOCTL_SIOCGIFCONF
goto err_ret;
goto err_ret;
#ifdef LWRES_PLATFORM_HAVESALEN
#ifdef FIX_ZERO_SA_LEN
#ifdef HAVE_MINIMUM_IFREQ
(int)(sizeof(struct sockaddr));
case AF_INET:
if (*have_v4 == 0) {
&((struct sockaddr_in *)
sizeof(in4));
case AF_INET6:
if (*have_v6 == 0) {
&((struct sockaddr_in6 *)
sizeof(in6));
sizeof(in6)) == 0)
close(s);
close(s);
static struct hostent *
int len = 0;
addresses++;
cpp++;
names++;
cpp++;
addresses++;
cpp++;
names++;
cpp++;
return (NULL);
goto no_recovery;
goto cleanup0;
goto cleanup1;
sizeof(in6addr_mapped));
INADDRSZ);
cpp++;
npp++;
goto cleanup1;
sizeof(in6addr_mapped));
INADDRSZ);
cpp++;
npp++;
goto cleanup1;
goto cleanup2;
npp++;
cpp++;
goto cleanup2;
return (he);
cpp++;
cpp++;
return (NULL);
static struct hostent *
goto cleanup;
switch (af) {
case AF_INET:
case AF_INET6:
INSIST(0);
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
goto cleanup;
return (he);
return (NULL);
static struct hostent *
goto cleanup;
switch (af) {
case AF_INET:
case AF_INET6:
INSIST(0);
goto cleanup;
goto cleanup;
goto cleanup;
return (he);
return (NULL);