2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * Copyright (C) 2004 by the Massachusetts Institute of Technology,
2N/A * Cambridge, MA, USA. All Rights Reserved.
2N/A *
2N/A * This software is being provided to you, the LICENSEE, by the
2N/A * Massachusetts Institute of Technology (M.I.T.) under the following
2N/A * license. By obtaining, using and/or copying this software, you agree
2N/A * that you have read, understood, and will comply with these terms and
2N/A * conditions:
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify and distribute
2N/A * this software and its documentation for any purpose and without fee or
2N/A * royalty is hereby granted, provided that you agree to comply with the
2N/A * following copyright notice and statements, including the disclaimer, and
2N/A * that the same appear on ALL copies of the software and documentation,
2N/A * including modifications that you make for internal use or for
2N/A * distribution:
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
2N/A * OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not
2N/A * limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF
2N/A * MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
2N/A * THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
2N/A * PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
2N/A *
2N/A * The name of the Massachusetts Institute of Technology or M.I.T. may NOT
2N/A * be used in advertising or publicity pertaining to distribution of the
2N/A * software. Title to copyright in this software and any associated
2N/A * documentation shall at all times remain with M.I.T., and USER agrees to
2N/A * preserve same.
2N/A *
2N/A * Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A */
2N/A
2N/A/*
2N/A * Approach overview:
2N/A *
2N/A * If a system version is available but buggy, save handles to it,
2N/A * redefine the names to refer to static functions defined here, and
2N/A * in those functions, call the system versions and fix up the
2N/A * returned data. Use the native data structures and flag values.
2N/A *
2N/A * If no system version exists, use gethostby* and fake it. Define
2N/A * the data structures and flag values locally.
2N/A *
2N/A *
2N/A * On Mac OS X, getaddrinfo results aren't cached (though
2N/A * gethostbyname results are), so we need to build a cache here. Now
2N/A * things are getting really messy. Because the cache is in use, we
2N/A * use getservbyname, and throw away thread safety. (Not that the
2N/A * cache is thread safe, but when we get locking support, that'll be
2N/A * dealt with.) This code needs tearing down and rebuilding, soon.
2N/A *
2N/A *
2N/A * Note that recent Windows developers' code has an interesting hack:
2N/A * When you include the right header files, with the right set of
2N/A * macros indicating system versions, you'll get an inline function
2N/A * that looks for getaddrinfo (or whatever) in the system library, and
2N/A * calls it if it's there. If it's not there, it fakes it with
2N/A * gethostby* calls.
2N/A *
2N/A * We're taking a simpler approach: A system provides these routines or
2N/A * it does not.
2N/A *
2N/A * Someday, we may want to take into account different versions (say,
2N/A * different revs of GNU libc) where some are broken in one way, and
2N/A * some work or are broken in another way. Cross that bridge when we
2N/A * come to it.
2N/A */
2N/A
2N/A/* To do, maybe:
2N/A *
2N/A * + For AIX 4.3.3, using the RFC 2133 definition: Implement
2N/A * AI_NUMERICHOST. It's not defined in the header file.
2N/A *
2N/A * For certain (old?) versions of GNU libc, AI_NUMERICHOST is
2N/A * defined but not implemented.
2N/A *
2N/A * + Use gethostbyname2, inet_aton and other IPv6 or thread-safe
2N/A * functions if available. But, see
2N/A * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=135182 for one
2N/A * gethostbyname2 problem on Linux. And besides, if a platform is
2N/A * supporting IPv6 at all, they really should be doing getaddrinfo
2N/A * by now.
2N/A *
2N/A * + inet_ntop, inet_pton
2N/A *
2N/A * + Conditionally export/import the function definitions, so a
2N/A * library can have a single copy instead of multiple.
2N/A *
2N/A * + Upgrade host requirements to include working implementations of
2N/A * these functions, and throw all this away. Pleeease? :-)
2N/A */
2N/A
2N/A#include "port-sockets.h"
2N/A#include "socket-utils.h"
2N/A#include "k5-platform.h"
2N/A#include "k5-thread.h"
2N/A
2N/A#include "fake-addrinfo.h"
2N/A
2N/A#if defined (__APPLE__) && defined (__MACH__) && 0
2N/A#define FAI_CACHE
2N/A#endif
2N/A
2N/Astruct face {
2N/A struct in_addr *addrs4;
2N/A struct in6_addr *addrs6;
2N/A unsigned int naddrs4, naddrs6;
2N/A time_t expiration;
2N/A char *canonname, *name;
2N/A struct face *next;
2N/A};
2N/A
2N/A/* fake addrinfo cache */
2N/Astruct fac {
2N/A k5_mutex_t lock;
2N/A struct face *data;
2N/A};
2N/A
2N/Aextern struct fac krb5int_fac;
2N/A
2N/Aextern int krb5int_init_fac (void);
2N/Aextern void krb5int_fini_fac (void);