|
Packit |
fd8b60 |
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
Packit |
fd8b60 |
/*
|
|
Packit |
fd8b60 |
* Copyright (C) 2001,2002,2003,2004 by the Massachusetts Institute of Technology,
|
|
Packit |
fd8b60 |
* Cambridge, MA, USA. All Rights Reserved.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* This software is being provided to you, the LICENSEE, by the
|
|
Packit |
fd8b60 |
* Massachusetts Institute of Technology (M.I.T.) under the following
|
|
Packit |
fd8b60 |
* license. By obtaining, using and/or copying this software, you agree
|
|
Packit |
fd8b60 |
* that you have read, understood, and will comply with these terms and
|
|
Packit |
fd8b60 |
* conditions:
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Export of this software from the United States of America may
|
|
Packit |
fd8b60 |
* require a specific license from the United States Government.
|
|
Packit |
fd8b60 |
* It is the responsibility of any person or organization contemplating
|
|
Packit |
fd8b60 |
* export to obtain such a license before exporting.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* WITHIN THAT CONSTRAINT, permission to use, copy, modify and distribute
|
|
Packit |
fd8b60 |
* this software and its documentation for any purpose and without fee or
|
|
Packit |
fd8b60 |
* royalty is hereby granted, provided that you agree to comply with the
|
|
Packit |
fd8b60 |
* following copyright notice and statements, including the disclaimer, and
|
|
Packit |
fd8b60 |
* that the same appear on ALL copies of the software and documentation,
|
|
Packit |
fd8b60 |
* including modifications that you make for internal use or for
|
|
Packit |
fd8b60 |
* distribution:
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS
|
|
Packit |
fd8b60 |
* OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not
|
|
Packit |
fd8b60 |
* limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
|
Packit |
fd8b60 |
* MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF
|
|
Packit |
fd8b60 |
* THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY
|
|
Packit |
fd8b60 |
* PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* The name of the Massachusetts Institute of Technology or M.I.T. may NOT
|
|
Packit |
fd8b60 |
* be used in advertising or publicity pertaining to distribution of the
|
|
Packit |
fd8b60 |
* software. Title to copyright in this software and any associated
|
|
Packit |
fd8b60 |
* documentation shall at all times remain with M.I.T., and USER agrees to
|
|
Packit |
fd8b60 |
* preserve same.
|
|
Packit |
fd8b60 |
*
|
|
Packit |
fd8b60 |
* Furthermore if you modify this software you must label
|
|
Packit |
fd8b60 |
* your software as modified software and not distribute it in such a
|
|
Packit |
fd8b60 |
* fashion that it might be confused with the original M.I.T. software.
|
|
Packit |
fd8b60 |
*/
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Approach overview:
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
If a system version is available but buggy, save handles to it (via
|
|
Packit |
fd8b60 |
inline functions in a support library), redefine the names to refer
|
|
Packit |
fd8b60 |
to library functions, and in those functions, call the system
|
|
Packit |
fd8b60 |
versions and fix up the returned data. Use the native data
|
|
Packit |
fd8b60 |
structures and flag values.
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
If no system version exists, use gethostby* and fake it. Define
|
|
Packit |
fd8b60 |
the data structures and flag values locally.
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
On macOS, getaddrinfo results aren't cached (though
|
|
Packit |
fd8b60 |
gethostbyname results are), so we need to build a cache here. Now
|
|
Packit |
fd8b60 |
things are getting really messy. Because the cache is in use, we
|
|
Packit |
fd8b60 |
use getservbyname, and throw away thread safety. (Not that the
|
|
Packit |
fd8b60 |
cache is thread safe, but when we get locking support, that'll be
|
|
Packit |
fd8b60 |
dealt with.) This code needs tearing down and rebuilding, soon.
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
Note that recent Windows developers' code has an interesting hack:
|
|
Packit |
fd8b60 |
When you include the right header files, with the right set of
|
|
Packit |
fd8b60 |
macros indicating system versions, you'll get an inline function
|
|
Packit |
fd8b60 |
that looks for getaddrinfo (or whatever) in the system library, and
|
|
Packit |
fd8b60 |
calls it if it's there. If it's not there, it fakes it with
|
|
Packit |
fd8b60 |
gethostby* calls.
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
We're taking a simpler approach: A system provides these routines or
|
|
Packit |
fd8b60 |
it does not.
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
Someday, we may want to take into account different versions (say,
|
|
Packit |
fd8b60 |
different revs of GNU libc) where some are broken in one way, and
|
|
Packit |
fd8b60 |
some work or are broken in another way. Cross that bridge when we
|
|
Packit |
fd8b60 |
come to it. */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* To do, maybe:
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
+ For AIX 4.3.3, using the RFC 2133 definition: Implement
|
|
Packit |
fd8b60 |
AI_NUMERICHOST. It's not defined in the header file.
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
For certain (old?) versions of GNU libc, AI_NUMERICHOST is
|
|
Packit |
fd8b60 |
defined but not implemented.
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
+ Use gethostbyname2, inet_aton and other IPv6 or thread-safe
|
|
Packit |
fd8b60 |
functions if available. But, see
|
|
Packit |
fd8b60 |
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=135182 for one
|
|
Packit |
fd8b60 |
gethostbyname2 problem on Linux. And besides, if a platform is
|
|
Packit |
fd8b60 |
supporting IPv6 at all, they really should be doing getaddrinfo
|
|
Packit |
fd8b60 |
by now.
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
+ inet_ntop, inet_pton
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
+ Conditionally export/import the function definitions, so a
|
|
Packit |
fd8b60 |
library can have a single copy instead of multiple.
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
+ Upgrade host requirements to include working implementations of
|
|
Packit |
fd8b60 |
these functions, and throw all this away. Pleeease? :-) */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifndef FAI_DEFINED
|
|
Packit |
fd8b60 |
#define FAI_DEFINED
|
|
Packit |
fd8b60 |
#include "port-sockets.h"
|
|
Packit |
fd8b60 |
#include "socket-utils.h"
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#if !defined (HAVE_GETADDRINFO)
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#undef addrinfo
|
|
Packit |
fd8b60 |
#define addrinfo my_fake_addrinfo
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
struct addrinfo {
|
|
Packit |
fd8b60 |
int ai_family; /* PF_foo */
|
|
Packit |
fd8b60 |
int ai_socktype; /* SOCK_foo */
|
|
Packit |
fd8b60 |
int ai_protocol; /* 0, IPPROTO_foo */
|
|
Packit |
fd8b60 |
int ai_flags; /* AI_PASSIVE etc */
|
|
Packit |
fd8b60 |
size_t ai_addrlen; /* real length of socket address */
|
|
Packit |
fd8b60 |
char *ai_canonname; /* canonical name of host */
|
|
Packit |
fd8b60 |
struct sockaddr *ai_addr; /* pointer to variable-size address */
|
|
Packit |
fd8b60 |
struct addrinfo *ai_next; /* next in linked list */
|
|
Packit |
fd8b60 |
};
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#undef AI_PASSIVE
|
|
Packit |
fd8b60 |
#define AI_PASSIVE 0x01
|
|
Packit |
fd8b60 |
#undef AI_CANONNAME
|
|
Packit |
fd8b60 |
#define AI_CANONNAME 0x02
|
|
Packit |
fd8b60 |
#undef AI_NUMERICHOST
|
|
Packit |
fd8b60 |
#define AI_NUMERICHOST 0x04
|
|
Packit |
fd8b60 |
/* RFC 2553 says these are part of the interface for getipnodebyname,
|
|
Packit |
fd8b60 |
not for getaddrinfo. RFC 3493 says they're part of the interface
|
|
Packit |
fd8b60 |
for getaddrinfo, and getipnodeby* are deprecated. Our fake
|
|
Packit |
fd8b60 |
getaddrinfo implementation here does IPv4 only anyways. */
|
|
Packit |
fd8b60 |
#undef AI_V4MAPPED
|
|
Packit |
fd8b60 |
#define AI_V4MAPPED 0
|
|
Packit |
fd8b60 |
#undef AI_ADDRCONFIG
|
|
Packit |
fd8b60 |
#define AI_ADDRCONFIG 0
|
|
Packit |
fd8b60 |
#undef AI_ALL
|
|
Packit |
fd8b60 |
#define AI_ALL 0
|
|
Packit |
fd8b60 |
#undef AI_DEFAULT
|
|
Packit |
fd8b60 |
#define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG)
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#ifndef NI_MAXHOST
|
|
Packit |
fd8b60 |
#define NI_MAXHOST 1025
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
#ifndef NI_MAXSERV
|
|
Packit |
fd8b60 |
#define NI_MAXSERV 32
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#undef NI_NUMERICHOST
|
|
Packit |
fd8b60 |
#define NI_NUMERICHOST 0x01
|
|
Packit |
fd8b60 |
#undef NI_NUMERICSERV
|
|
Packit |
fd8b60 |
#define NI_NUMERICSERV 0x02
|
|
Packit |
fd8b60 |
#undef NI_NAMEREQD
|
|
Packit |
fd8b60 |
#define NI_NAMEREQD 0x04
|
|
Packit |
fd8b60 |
#undef NI_DGRAM
|
|
Packit |
fd8b60 |
#define NI_DGRAM 0x08
|
|
Packit |
fd8b60 |
#undef NI_NOFQDN
|
|
Packit |
fd8b60 |
#define NI_NOFQDN 0x10
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#undef EAI_ADDRFAMILY
|
|
Packit |
fd8b60 |
#define EAI_ADDRFAMILY 1
|
|
Packit |
fd8b60 |
#undef EAI_AGAIN
|
|
Packit |
fd8b60 |
#define EAI_AGAIN 2
|
|
Packit |
fd8b60 |
#undef EAI_BADFLAGS
|
|
Packit |
fd8b60 |
#define EAI_BADFLAGS 3
|
|
Packit |
fd8b60 |
#undef EAI_FAIL
|
|
Packit |
fd8b60 |
#define EAI_FAIL 4
|
|
Packit |
fd8b60 |
#undef EAI_FAMILY
|
|
Packit |
fd8b60 |
#define EAI_FAMILY 5
|
|
Packit |
fd8b60 |
#undef EAI_MEMORY
|
|
Packit |
fd8b60 |
#define EAI_MEMORY 6
|
|
Packit |
fd8b60 |
#undef EAI_NODATA
|
|
Packit |
fd8b60 |
#define EAI_NODATA 7
|
|
Packit |
fd8b60 |
#undef EAI_NONAME
|
|
Packit |
fd8b60 |
#define EAI_NONAME 8
|
|
Packit |
fd8b60 |
#undef EAI_SERVICE
|
|
Packit |
fd8b60 |
#define EAI_SERVICE 9
|
|
Packit |
fd8b60 |
#undef EAI_SOCKTYPE
|
|
Packit |
fd8b60 |
#define EAI_SOCKTYPE 10
|
|
Packit |
fd8b60 |
#undef EAI_SYSTEM
|
|
Packit |
fd8b60 |
#define EAI_SYSTEM 11
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#endif /* ! HAVE_GETADDRINFO */
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Fudge things on older gai implementations. */
|
|
Packit |
fd8b60 |
/* AIX 4.3.3 is based on RFC 2133; no AI_NUMERICHOST. */
|
|
Packit |
fd8b60 |
#ifndef AI_NUMERICHOST
|
|
Packit |
fd8b60 |
# define AI_NUMERICHOST 0
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
/* Partial RFC 2553 implementations may not have AI_ADDRCONFIG and
|
|
Packit |
fd8b60 |
friends, which RFC 3493 says are now part of the getaddrinfo
|
|
Packit |
fd8b60 |
interface, and we'll want to use. */
|
|
Packit |
fd8b60 |
#ifndef AI_ADDRCONFIG
|
|
Packit |
fd8b60 |
# define AI_ADDRCONFIG 0
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
#ifndef AI_V4MAPPED
|
|
Packit |
fd8b60 |
# define AI_V4MAPPED 0
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
#ifndef AI_ALL
|
|
Packit |
fd8b60 |
# define AI_ALL 0
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
#ifndef AI_DEFAULT
|
|
Packit |
fd8b60 |
# define AI_DEFAULT (AI_ADDRCONFIG|AI_V4MAPPED)
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#if defined(NEED_INSIXADDR_ANY)
|
|
Packit |
fd8b60 |
/* If compiling with IPv6 support and C library does not define in6addr_any */
|
|
Packit |
fd8b60 |
extern const struct in6_addr krb5int_in6addr_any;
|
|
Packit |
fd8b60 |
#undef in6addr_any
|
|
Packit |
fd8b60 |
#define in6addr_any krb5int_in6addr_any
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
/* Call out to stuff defined in libkrb5support. */
|
|
Packit |
fd8b60 |
extern int krb5int_getaddrinfo (const char *node, const char *service,
|
|
Packit |
fd8b60 |
const struct addrinfo *hints,
|
|
Packit |
fd8b60 |
struct addrinfo **aip);
|
|
Packit |
fd8b60 |
extern void krb5int_freeaddrinfo (struct addrinfo *ai);
|
|
Packit |
fd8b60 |
extern const char *krb5int_gai_strerror(int err);
|
|
Packit |
fd8b60 |
extern int krb5int_getnameinfo (const struct sockaddr *sa, socklen_t salen,
|
|
Packit |
fd8b60 |
char *hbuf, size_t hbuflen,
|
|
Packit |
fd8b60 |
char *sbuf, size_t sbuflen,
|
|
Packit |
fd8b60 |
int flags);
|
|
Packit |
fd8b60 |
#ifndef IMPLEMENT_FAKE_GETADDRINFO
|
|
Packit |
fd8b60 |
#undef getaddrinfo
|
|
Packit |
fd8b60 |
#define getaddrinfo krb5int_getaddrinfo
|
|
Packit |
fd8b60 |
#undef freeaddrinfo
|
|
Packit |
fd8b60 |
#define freeaddrinfo krb5int_freeaddrinfo
|
|
Packit |
fd8b60 |
#undef gai_strerror
|
|
Packit |
fd8b60 |
#define gai_strerror krb5int_gai_strerror
|
|
Packit |
fd8b60 |
#undef getnameinfo
|
|
Packit |
fd8b60 |
#define getnameinfo krb5int_getnameinfo
|
|
Packit |
fd8b60 |
#endif
|
|
Packit |
fd8b60 |
|
|
Packit |
fd8b60 |
#endif /* FAI_DEFINED */
|