landing patch for bug 211501 "NSPR should provide getaddrinfo" r=wtc

This commit is contained in:
darin%meer.net 2003-09-11 21:42:16 +00:00
Родитель 6d37955ac2
Коммит ad3f5bd55a
23 изменённых файлов: 564 добавлений и 67 удалений

Просмотреть файл

@ -39,3 +39,4 @@
*/
#error "Do not include this header file."

57
nsprpub/configure поставляемый
Просмотреть файл

@ -4535,6 +4535,25 @@ EOF
fi
;;
esac
case "${target_os}" in
solaris2.3*)
;;
solaris2.4*)
;;
solaris2.5*)
;;
solaris2.6*)
;;
solaris2.7*)
;;
*)
# Solaris 8 or higher has IPv6.
cat >> confdefs.h <<\EOF
#define _PR_INET6 1
EOF
;;
esac
if test "$OS_TEST" = "sun4u"; then
# 64-bit Solaris requires SPARC V9 architecture, so the following
# is not needed.
@ -4727,7 +4746,7 @@ case $target in
;;
*)
echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
echo "configure:4731: checking for dlopen in -ldl" >&5
echo "configure:4750: checking for dlopen in -ldl" >&5
ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
@ -4735,7 +4754,7 @@ else
ac_save_LIBS="$LIBS"
LIBS="-ldl $LIBS"
cat > conftest.$ac_ext <<EOF
#line 4739 "configure"
#line 4758 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
@ -4746,7 +4765,7 @@ int main() {
dlopen()
; return 0; }
EOF
if { (eval echo configure:4750: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
if { (eval echo configure:4769: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
@ -4763,17 +4782,17 @@ if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
echo "$ac_t""yes" 1>&6
ac_safe=`echo "dlfcn.h" | sed 'y%./+-%__p_%'`
echo $ac_n "checking for dlfcn.h""... $ac_c" 1>&6
echo "configure:4767: checking for dlfcn.h" >&5
echo "configure:4786: checking for dlfcn.h" >&5
if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 4772 "configure"
#line 4791 "configure"
#include "confdefs.h"
#include <dlfcn.h>
EOF
ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
{ (eval echo configure:4777: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
{ (eval echo configure:4796: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
if test -z "$ac_err"; then
rm -rf conftest*
@ -4806,13 +4825,13 @@ esac
if test $ac_cv_prog_gcc = yes; then
echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6
echo "configure:4810: checking whether ${CC-cc} needs -traditional" >&5
echo "configure:4829: checking whether ${CC-cc} needs -traditional" >&5
if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
ac_pattern="Autoconf.*'x'"
cat > conftest.$ac_ext <<EOF
#line 4816 "configure"
#line 4835 "configure"
#include "confdefs.h"
#include <sgtty.h>
Autoconf TIOCGETP
@ -4830,7 +4849,7 @@ rm -f conftest*
if test $ac_cv_prog_gcc_traditional = no; then
cat > conftest.$ac_ext <<EOF
#line 4834 "configure"
#line 4853 "configure"
#include "confdefs.h"
#include <termio.h>
Autoconf TCGETA
@ -4854,12 +4873,12 @@ fi
for ac_func in lchown strerror
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:4858: checking for $ac_func" >&5
echo "configure:4877: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
#line 4863 "configure"
#line 4882 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@ -4882,7 +4901,7 @@ $ac_func();
; return 0; }
EOF
if { (eval echo configure:4886: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
if { (eval echo configure:4905: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
@ -4921,7 +4940,7 @@ hpux*)
if test -z "$GNU_CC"; then
echo $ac_n "checking for +Olit support""... $ac_c" 1>&6
echo "configure:4925: checking for +Olit support" >&5
echo "configure:4944: checking for +Olit support" >&5
if eval "test \"`echo '$''{'ac_cv_hpux_usable_olit_option'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@ -4955,7 +4974,7 @@ esac
echo $ac_n "checking for pthread_create in -lpthreads""... $ac_c" 1>&6
echo "configure:4959: checking for pthread_create in -lpthreads" >&5
echo "configure:4978: checking for pthread_create in -lpthreads" >&5
echo "
#include <pthread.h>
void *foo(void *v) { return v; }
@ -4977,7 +4996,7 @@ echo "
echo "$ac_t""no" 1>&6
echo $ac_n "checking for pthread_create in -lpthread""... $ac_c" 1>&6
echo "configure:4981: checking for pthread_create in -lpthread" >&5
echo "configure:5000: checking for pthread_create in -lpthread" >&5
echo "
#include <pthread.h>
void *foo(void *v) { return v; }
@ -4999,7 +5018,7 @@ echo "
echo "$ac_t""no" 1>&6
echo $ac_n "checking for pthread_create in -lc_r""... $ac_c" 1>&6
echo "configure:5003: checking for pthread_create in -lc_r" >&5
echo "configure:5022: checking for pthread_create in -lc_r" >&5
echo "
#include <pthread.h>
void *foo(void *v) { return v; }
@ -5021,7 +5040,7 @@ echo "
echo "$ac_t""no" 1>&6
echo $ac_n "checking for pthread_create in -lc""... $ac_c" 1>&6
echo "configure:5025: checking for pthread_create in -lc" >&5
echo "configure:5044: checking for pthread_create in -lc" >&5
echo "
#include <pthread.h>
void *foo(void *v) { return v; }
@ -5173,7 +5192,7 @@ if test -n "$USE_PTHREADS"; then
rm -f conftest*
ac_cv_have_dash_pthread=no
echo $ac_n "checking whether ${CC-cc} accepts -pthread""... $ac_c" 1>&6
echo "configure:5177: checking whether ${CC-cc} accepts -pthread" >&5
echo "configure:5196: checking whether ${CC-cc} accepts -pthread" >&5
echo 'int main() { return 0; }' | cat > conftest.c
${CC-cc} -pthread -o conftest conftest.c > conftest.out 2>&1
if test $? -eq 0; then
@ -5196,7 +5215,7 @@ echo "configure:5177: checking whether ${CC-cc} accepts -pthread" >&5
ac_cv_have_dash_pthreads=no
if test "$ac_cv_have_dash_pthread" = "no"; then
echo $ac_n "checking whether ${CC-cc} accepts -pthreads""... $ac_c" 1>&6
echo "configure:5200: checking whether ${CC-cc} accepts -pthreads" >&5
echo "configure:5219: checking whether ${CC-cc} accepts -pthreads" >&5
echo 'int main() { return 0; }' | cat > conftest.c
${CC-cc} -pthreads -o conftest conftest.c > conftest.out 2>&1
if test $? -eq 0; then

Просмотреть файл

@ -1731,6 +1731,22 @@ mips-sony-newsos*)
fi
;;
esac
case "${target_os}" in
solaris2.3*)
;;
solaris2.4*)
;;
solaris2.5*)
;;
solaris2.6*)
;;
solaris2.7*)
;;
*)
# Solaris 8 or higher has IPv6.
AC_DEFINE(_PR_INET6)
;;
esac
if test "$OS_TEST" = "sun4u"; then
# 64-bit Solaris requires SPARC V9 architecture, so the following
# is not needed.

Просмотреть файл

@ -74,6 +74,7 @@
#ifdef _PR_INET6
#define _PR_HAVE_INET_NTOP
#define _PR_HAVE_GETHOSTBYNAME2
#define _PR_HAVE_GETADDRINFO
#endif
#define _PR_HAVE_SYSV_SEMAPHORES
#define PR_HAVE_SYSV_NAMED_SHARED_MEMORY

Просмотреть файл

@ -69,6 +69,7 @@
#define _PR_HAVE_INET_NTOP
#define _PR_HAVE_GETIPNODEBYNAME
#define _PR_HAVE_GETIPNODEBYADDR
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#endif

Просмотреть файл

@ -68,6 +68,7 @@
* thread-safe. AI_V4MAPPED|AI_ADDRCONFIG doesn't work either.
*/
#define _PR_HAVE_GETHOSTBYNAME2
#define _PR_HAVE_GETADDRINFO
/*
* On Mac OS X 10.2, gethostbyaddr fails with h_errno=NO_RECOVERY
* if you pass an IPv4-mapped IPv6 address to it.

Просмотреть файл

@ -92,6 +92,7 @@
#define _PR_INET6
#define _PR_HAVE_INET_NTOP
#define _PR_HAVE_GETHOSTBYNAME2
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#endif

Просмотреть файл

@ -83,6 +83,7 @@
#define _PR_HAVE_INET_NTOP
#define _PR_HAVE_GETIPNODEBYNAME
#define _PR_HAVE_GETIPNODEBYADDR
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#endif

Просмотреть файл

@ -82,6 +82,7 @@
#define _PR_HAVE_INET_NTOP
#define _PR_HAVE_GETIPNODEBYNAME
#define _PR_HAVE_GETIPNODEBYADDR
#define _PR_HAVE_GETADDRINFO
#endif
/* Initialization entry points */

Просмотреть файл

@ -124,6 +124,7 @@ extern PRInt32 _PR_ia64_AtomicSet(PRInt32 *val, PRInt32 newval);
#define _PR_INET6
#define _PR_HAVE_INET_NTOP
#define _PR_HAVE_GETHOSTBYNAME2
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#endif
#define _PR_HAVE_SYSV_SEMAPHORES

Просмотреть файл

@ -82,6 +82,7 @@
#define _PR_INET6
#define _PR_HAVE_INET_NTOP
#define _PR_HAVE_GETHOSTBYNAME2
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#endif

Просмотреть файл

@ -105,11 +105,23 @@ struct ip_mreq {
#endif
#define _PR_HAVE_GETIPNODEBYNAME
#define _PR_HAVE_GETIPNODEBYADDR
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#ifdef _PR_INET6
#define _PR_HAVE_INET_NTOP
#else
#define AF_INET6 26
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#define AI_CANONNAME 0x00000002
#define AI_V4MAPPED 0x00000010
#define AI_ALL 0x00000008
#define AI_ADDRCONFIG 0x00000020

Просмотреть файл

@ -64,11 +64,23 @@
#define _PR_HAVE_LARGE_OFF_T
#define _PR_HAVE_GETIPNODEBYNAME
#define _PR_HAVE_GETIPNODEBYADDR
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#ifdef _PR_INET6
#define _PR_HAVE_INET_NTOP
#else
#define AF_INET6 26
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#define AI_CANONNAME 0x00000002
#define AI_V4MAPPED 0x00000010
#define AI_ALL 0x00000008
#define AI_ADDRCONFIG 0x00000020

Просмотреть файл

@ -109,12 +109,24 @@
#endif
#define _PR_HAVE_GETIPNODEBYNAME
#define _PR_HAVE_GETIPNODEBYADDR
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#define _PR_ACCEPT_INHERIT_NONBLOCK
#ifdef _PR_INET6
#define _PR_HAVE_INET_NTOP
#else
#define AF_INET6 26
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#define AI_CANONNAME 0x0010
#define AI_V4MAPPED 0x0001
#define AI_ALL 0x0002
#define AI_ADDRCONFIG 0x0004

Просмотреть файл

@ -51,6 +51,23 @@
#define HAVE_DLL
#undef HAVE_THREAD_AFFINITY
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#ifndef _PR_INET6
#define AF_INET6 23
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#define AI_CANONNAME 0x2
#endif
#define _PR_HAVE_THREADSAFE_GETHOST
#define _PR_HAVE_ATOMIC_OPS
#define PR_HAVE_WIN32_NAMED_SHARED_MEMORY

Просмотреть файл

@ -66,6 +66,23 @@
#define HAVE_DLL
#define HAVE_CUSTOM_USER_THREADS
#define HAVE_THREAD_AFFINITY
#define _PR_HAVE_GETADDRINFO
#define _PR_INET6_PROBE
#ifndef _PR_INET6
#define AF_INET6 23
struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char *ai_canonname;
struct sockaddr *ai_addr;
struct addrinfo *ai_next;
};
#define AI_CANONNAME 0x2
#endif
#define _PR_HAVE_THREADSAFE_GETHOST
#define _PR_HAVE_ATOMIC_OPS
#define _PR_HAVE_ATOMIC_CAS
#define PR_HAVE_WIN32_NAMED_SHARED_MEMORY

Просмотреть файл

@ -139,6 +139,10 @@ typedef enum PRTransmitFileFlags {
#define PR_AF_INET6 100
#endif
#ifndef PR_AF_UNSPEC
#define PR_AF_UNSPEC 0
#endif
/*
**************************************************************************
** A network address

Просмотреть файл

@ -385,6 +385,88 @@ NSPR_API(PRStatus) PR_GetProtoByName(
NSPR_API(PRStatus) PR_GetProtoByNumber(
PRInt32 protocolnumber, char* buffer, PRInt32 bufsize, PRProtoEnt* result);
/***********************************************************************
** FUNCTION:
** DESCRIPTION: PR_GetAddrInfoByName()
** Lookup a host by name. Equivalent to getaddrinfo(host, NULL, ...) of
** RFC 3493.
**
** INPUTS:
** char *hostname Character string defining the host name of interest
** PRUint16 af Must be PR_AF_UNSPEC
** PRIntn flags Must be PR_AI_ADDRCONFIG
** RETURN:
** PRAddrInfo* Handle to a data structure containing the results
** of the host lookup. Use PR_EnumerateAddrInfo to
** inspect the PRNetAddr values stored in this object.
** When no longer needed, this handle must be destroyed
** with a call to PR_FreeAddrInfo. If a lookup error
** occurs, then NULL will be returned.
***********************************************************************/
typedef struct PRAddrInfo PRAddrInfo;
NSPR_API(PRAddrInfo*) PR_GetAddrInfoByName(
const char *hostname, PRUint16 af, PRIntn flags);
/***********************************************************************
** FUNCTION:
** DESCRIPTION: PR_FreeAddrInfo()
** Destroy the PRAddrInfo handle allocated by PR_GetAddrInfoByName().
**
** INPUTS:
** PRAddrInfo *addrInfo
** The handle resulting from a successful call to
** PR_GetAddrInfoByName().
** RETURN:
** void
***********************************************************************/
NSPR_API(void) PR_FreeAddrInfo(PRAddrInfo *addrInfo);
/***********************************************************************
** FUNCTION:
** DESCRIPTION: PR_EnumerateAddrInfo()
** A stateless enumerator over a PRAddrInfo handle acquired from
** PR_GetAddrInfoByName() to inspect the possible network addresses.
**
** INPUTS:
** void *enumPtr Index pointer of the enumeration. The enumeration
** starts and ends with a value of NULL.
** PRAddrInfo *addrInfo
** The PRAddrInfo handle returned by a successful
** call to PR_GetAddrInfoByName().
** PRUint16 port The port number to be assigned as part of the
** PRNetAddr.
** OUTPUTS:
** PRNetAddr *result A pointer to an address structure that will be
** filled in by the call to the enumeration if the
** result of the call is greater than zero.
** RETURN:
** void* The value that should be used for the next call
** of the enumerator ('enumPtr'). The enumeration
** is ended if this value is returned NULL.
***********************************************************************/
NSPR_API(void *) PR_EnumerateAddrInfo(
void *enumPtr, const PRAddrInfo *addrInfo, PRUint16 port, PRNetAddr *result);
/***********************************************************************
** FUNCTION:
** DESCRIPTION: PR_GetCanonNameFromAddrInfo()
** Extracts the canonical name of the hostname passed to
** PR_GetAddrInfoByName().
**
** INPUTS:
** PRAddrInfo *addrInfo
** The PRAddrInfo handle returned by a successful
** call to PR_GetAddrInfoByName().
** RETURN:
** const char * A const pointer to the canonical hostname stored
** in the given PRAddrInfo handle. This pointer is
** invalidated once the PRAddrInfo handle is destroyed
** by a call to PR_FreeAddrInfo().
***********************************************************************/
NSPR_API(const char *) PR_GetCanonNameFromAddrInfo(
const PRAddrInfo *addrInfo);
/***********************************************************************
** FUNCTIONS: PR_ntohs, PR_ntohl, PR_ntohll, PR_htons, PR_htonl, PR_htonll
**

Просмотреть файл

@ -276,51 +276,41 @@ static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketRecvFrom(PRFileDesc *fd, void *buf,
#if defined(_PR_INET6_PROBE)
PRBool _pr_ipv6_is_present;
PR_EXTERN(PRBool) _pr_test_ipv6_socket();
#if defined(_PR_HAVE_GETIPNODEBYNAME)
void *_pr_getipnodebyname_fp;
void *_pr_getipnodebyaddr_fp;
void *_pr_freehostent_fp;
extern PRBool _pr_test_ipv6_socket(void);
#if !defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
extern PRStatus _pr_find_getipnodebyname(void);
#endif
#if !defined(_PR_INET6) && defined(_PR_HAVE_GETADDRINFO)
extern PRStatus _pr_find_getaddrinfo(void);
#endif
static PRBool
_pr_probe_ipv6_presence(void)
{
#if !defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
if (_pr_find_getipnodebyname() != PR_SUCCESS)
return PR_FALSE;
#endif
#if !defined(_PR_INET6) && defined(_PR_HAVE_GETADDRINFO)
if (_pr_find_getaddrinfo() != PR_SUCCESS)
return PR_FALSE;
#endif
return _pr_test_ipv6_socket();
}
#endif /* _PR_INET6_PROBE */
PRStatus _pr_init_ipv6()
{
const PRIOMethods *stubMethods;
#if defined(_PR_INET6_PROBE)
#if !defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
PRLibrary *lib;
#if defined(VMS)
#define GETIPNODEBYNAME getenv("GETIPNODEBYNAME")
#define GETIPNODEBYADDR getenv("GETIPNODEBYADDR")
#define FREEHOSTENT getenv("FREEHOSTENT")
#else
#define GETIPNODEBYNAME "getipnodebyname"
#define GETIPNODEBYADDR "getipnodebyaddr"
#define FREEHOSTENT "freehostent"
#endif
_pr_getipnodebyname_fp = PR_FindSymbolAndLibrary(GETIPNODEBYNAME, &lib);
if (NULL != _pr_getipnodebyname_fp) {
_pr_freehostent_fp = PR_FindSymbol(lib, FREEHOSTENT);
if (NULL != _pr_freehostent_fp) {
_pr_getipnodebyaddr_fp = PR_FindSymbol(lib, GETIPNODEBYADDR);
if (NULL != _pr_getipnodebyaddr_fp)
_pr_ipv6_is_present = PR_TRUE;
else
_pr_ipv6_is_present = PR_FALSE;
} else
_pr_ipv6_is_present = PR_FALSE;
(void)PR_UnloadLibrary(lib);
} else
_pr_ipv6_is_present = PR_FALSE;
if (PR_TRUE == _pr_ipv6_is_present)
#endif
_pr_ipv6_is_present = _pr_test_ipv6_socket();
if (PR_TRUE == _pr_ipv6_is_present)
return PR_SUCCESS;
_pr_ipv6_is_present = _pr_probe_ipv6_presence();
if (PR_TRUE == _pr_ipv6_is_present)
return PR_SUCCESS;
#endif
_pr_ipv6_to_ipv4_id = PR_GetUniqueIdentity("Ipv6_to_Ipv4 layer");

Просмотреть файл

@ -715,15 +715,51 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByName(
return rv;
}
#if defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
#if !defined(_PR_INET6) && \
defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
typedef struct hostent * (*_pr_getipnodebyname_t)(const char *, int,
int, int *);
typedef struct hostent * (*_pr_getipnodebyaddr_t)(const void *, size_t,
int, int *);
typedef void (*_pr_freehostent_t)(struct hostent *);
extern void * _pr_getipnodebyname_fp;
extern void * _pr_getipnodebyaddr_fp;
extern void * _pr_freehostent_fp;
static void * _pr_getipnodebyname_fp;
static void * _pr_getipnodebyaddr_fp;
static void * _pr_freehostent_fp;
/*
* Look up the addresses of getipnodebyname, getipnodebyaddr,
* and freehostent.
*/
PRStatus
_pr_find_getipnodebyname(void)
{
PRLibrary *lib;
PRStatus rv;
#if defined(VMS)
#define GETIPNODEBYNAME getenv("GETIPNODEBYNAME")
#define GETIPNODEBYADDR getenv("GETIPNODEBYADDR")
#define FREEHOSTENT getenv("FREEHOSTENT")
#else
#define GETIPNODEBYNAME "getipnodebyname"
#define GETIPNODEBYADDR "getipnodebyaddr"
#define FREEHOSTENT "freehostent"
#endif
_pr_getipnodebyname_fp = PR_FindSymbolAndLibrary(GETIPNODEBYNAME, &lib);
if (NULL != _pr_getipnodebyname_fp) {
_pr_freehostent_fp = PR_FindSymbol(lib, FREEHOSTENT);
if (NULL != _pr_freehostent_fp) {
_pr_getipnodebyaddr_fp = PR_FindSymbol(lib, GETIPNODEBYADDR);
if (NULL != _pr_getipnodebyaddr_fp)
rv = PR_SUCCESS;
else
rv = PR_FAILURE;
} else
rv = PR_FAILURE;
(void)PR_UnloadLibrary(lib);
} else
rv = PR_FAILURE;
return rv;
}
#endif
#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
@ -1876,3 +1912,256 @@ PR_IMPLEMENT(PRUint64) PR_htonll(PRUint64 n)
return n;
#endif
} /* htonll */
/*
* Implementation of PR_GetAddrInfoByName and friends
*
* Compile-time options:
*
* _PR_HAVE_GETADDRINFO Define this macro if the target system provides
* getaddrinfo. With this defined, NSPR will require
* getaddrinfo at run time. If this if not defined,
* then NSPR will attempt to dynamically resolve
* getaddrinfo, falling back to PR_GetHostByName if
* getaddrinfo does not exist on the target system.
*
* Since getaddrinfo is a relatively new system call on many systems,
* we are forced to dynamically resolve it at run time in most cases.
* The exception includes any system (such as Mac OS X) that is known to
* provide getaddrinfo in all versions that NSPR cares to support.
*/
#if defined(_PR_HAVE_GETADDRINFO)
#if defined(_PR_INET6)
typedef struct addrinfo PRADDRINFO;
#define GETADDRINFO getaddrinfo
#define FREEADDRINFO freeaddrinfo
#elif defined(_PR_INET6_PROBE)
typedef struct addrinfo PRADDRINFO;
/* getaddrinfo/freeaddrinfo prototypes */
#if defined(WIN32)
#define FUNC_MODIFIER __stdcall
#else
#define FUNC_MODIFIER
#endif
typedef int (FUNC_MODIFIER * FN_GETADDRINFO)
(const char *nodename,
const char *servname,
const PRADDRINFO *hints,
PRADDRINFO **res);
typedef int (FUNC_MODIFIER * FN_FREEADDRINFO)
(PRADDRINFO *ai);
/* global state */
static FN_GETADDRINFO _pr_getaddrinfo = NULL;
static FN_FREEADDRINFO _pr_freeaddrinfo = NULL;
#if defined(VMS)
#define GETADDRINFO_SYMBOL getenv("GETADDRINFO")
#define FREEADDRINFO_SYMBOL getenv("FREEADDRINFO")
#else
#define GETADDRINFO_SYMBOL "getaddrinfo"
#define FREEADDRINFO_SYMBOL "freeaddrinfo"
#endif
PRStatus
_pr_find_getaddrinfo(void)
{
PRLibrary *lib;
#ifdef WIN32
/*
* On windows, we need to search ws2_32.dll for getaddrinfo and
* freeaddrinfo. This library might not be loaded yet.
*/
lib = PR_LoadLibrary("ws2_32.dll");
if (!lib) {
return PR_FAILURE;
}
_pr_getaddrinfo = (FN_GETADDRINFO)
PR_FindFunctionSymbol(lib, GETADDRINFO_SYMBOL);
_pr_freeaddrinfo = (FN_FREEADDRINFO)
PR_FindFunctionSymbol(lib, FREEADDRINFO_SYMBOL);
if (!_pr_getaddrinfo || !_pr_freeaddrinfo) {
PR_UnloadLibrary(lib);
return PR_FAILURE;
}
/* Keep ws2_32.dll loaded. */
return PR_SUCCESS;
#else
/*
* Resolve getaddrinfo by searching all loaded libraries. Then
* search library containing getaddrinfo for freeaddrinfo.
*/
_pr_getaddrinfo = (FN_GETADDRINFO)
PR_FindFunctionSymbolAndLibrary(GETADDRINFO_SYMBOL, &lib);
if (!_pr_getaddrinfo) {
return PR_FAILURE;
}
_pr_freeaddrinfo = (FN_FREEADDRINFO)
PR_FindFunctionSymbol(lib, FREEADDRINFO_SYMBOL);
PR_UnloadLibrary(lib);
if (!_pr_freeaddrinfo) {
return PR_FAILURE;
}
return PR_SUCCESS;
#endif
}
#define GETADDRINFO (*_pr_getaddrinfo)
#define FREEADDRINFO (*_pr_freeaddrinfo)
#endif /* _PR_INET6 */
#endif /* _PR_HAVE_GETADDRINFO */
/*
* If getaddrinfo does not exist, then we will fall back on
* PR_GetHostByName, which requires that we allocate a buffer for the
* PRHostEnt data structure and its members.
*/
typedef struct PRAddrInfoFB {
char buf[PR_NETDB_BUF_SIZE];
PRHostEnt hostent;
} PRAddrInfoFB;
static PRAddrInfo *
pr_GetAddrInfoByNameFB(const char *hostname,
PRUint16 af,
PRIntn flags)
{
PRStatus rv;
PRAddrInfoFB *ai;
/* fallback on PR_GetHostByName */
ai = PR_NEW(PRAddrInfoFB);
if (!ai) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
return NULL;
}
rv = PR_GetHostByName(hostname, ai->buf, sizeof ai->buf, &ai->hostent);
if (rv == PR_FAILURE) {
PR_Free(ai);
return NULL;
}
return (PRAddrInfo *) ai;
}
PR_IMPLEMENT(PRAddrInfo *) PR_GetAddrInfoByName(const char *hostname,
PRUint16 af,
PRIntn flags)
{
/* restrict input to supported values */
if (af != PR_AF_UNSPEC || flags != PR_AI_ADDRCONFIG) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
if (!_pr_initialized) _PR_ImplicitInitialization();
#if !defined(_PR_HAVE_GETADDRINFO)
return pr_GetAddrInfoByNameFB(hostname, af, flags);
#else
#if defined(_PR_INET6_PROBE)
if (!_pr_ipv6_is_present) {
return pr_GetAddrInfoByNameFB(hostname, af, flags);
}
#endif
{
PRADDRINFO *res, hints;
PRStatus rv;
/*
* we assume a RFC 2553 compliant getaddrinfo. this may at some
* point need to be customized as platforms begin to adopt the
* RFC 3493.
*/
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
hints.ai_family = AF_UNSPEC;
rv = GETADDRINFO(hostname, NULL, &hints, &res);
if (rv == 0)
return (PRAddrInfo *) res;
PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, rv);
}
return NULL;
#endif
}
PR_IMPLEMENT(void) PR_FreeAddrInfo(PRAddrInfo *ai)
{
#if defined(_PR_HAVE_GETADDRINFO)
#if defined(_PR_INET6_PROBE)
if (!_pr_ipv6_is_present)
PR_Free((PRAddrInfoFB *) ai);
else
#endif
FREEADDRINFO((PRADDRINFO *) ai);
#else
PR_Free((PRAddrInfoFB *) ai);
#endif
}
PR_IMPLEMENT(void *) PR_EnumerateAddrInfo(void *iterPtr,
const PRAddrInfo *base,
PRUint16 port,
PRNetAddr *result)
{
#if defined(_PR_HAVE_GETADDRINFO)
PRADDRINFO *ai;
#if defined(_PR_INET6_PROBE)
if (!_pr_ipv6_is_present) {
/* using PRAddrInfoFB */
PRIntn iter = (PRIntn) iterPtr;
iter = PR_EnumerateHostEnt(iter, &((PRAddrInfoFB *) base)->hostent, port, result);
if (iter < 0)
iter = 0;
return (void *) iter;
}
#endif
if (iterPtr)
ai = ((PRADDRINFO *) iterPtr)->ai_next;
else
ai = (PRADDRINFO *) base;
if (ai) {
/* copy sockaddr to PRNetAddr */
memcpy(result, ai->ai_addr, ai->ai_addrlen);
if (ai->ai_addrlen < sizeof(PRNetAddr))
memset(((char*)result)+ai->ai_addrlen, 0, sizeof(PRNetAddr) - ai->ai_addrlen);
if (port != 0)
result->inet.port = PR_htons(port);
}
return ai;
#else
/* using PRAddrInfoFB */
PRIntn iter = (PRIntn) iterPtr;
iter = PR_EnumerateHostEnt(iter, &((PRAddrInfoFB *) base)->hostent, port, result);
if (iter < 0)
iter = 0;
return (void *) iter;
#endif
}
PR_IMPLEMENT(const char *) PR_GetCanonNameFromAddrInfo(const PRAddrInfo *ai)
{
#if defined(_PR_HAVE_GETADDRINFO)
#if defined(_PR_INET6_PROBE)
if (!_pr_ipv6_is_present)
return ((const PRAddrInfoFB *) ai)->hostent.h_name;
#endif
return ((const PRADDRINFO *) ai)->ai_canonname;
#else
return ((const PRAddrInfoFB *) ai)->hostent.h_name;
#endif
}

Просмотреть файл

@ -447,3 +447,11 @@ EXPORTS ;-
;+ global:
PR_GetPathSeparator;
;+} NSPR_4.3;
;+
;+NSPR_4.5 {
;+ global:
PR_EnumerateAddrInfo;
PR_FreeAddrInfo;
PR_GetAddrInfoByName;
PR_GetCanonNameFromAddrInfo;
;+} NSPR_4.4;

Просмотреть файл

@ -1,6 +1,6 @@
! Fixed section of symbol vector for LIBNSPR4 (non-debug)
!
GSMATCH=LEQUAL,2,5
GSMATCH=LEQUAL,2,7
case_sensitive=YES
!
! --------------------------------------------------------------------------
@ -31,6 +31,15 @@ case_sensitive=YES
! Ident 2,5 introduced for post Mozilla 1.3.
! LL_MaxUint introduced. Replaces Stub54.
! --------------------------------------------------------------------------
! Ident 2,6 introduced for post Mozilla 1.4.
! PR_GetPathSeparator introduced in NSPR 4.4.
! This replaces stub 53
! --------------------------------------------------------------------------
! Ident 2,7 introduced for post Mozilla 1.4.
! PR_GetAddrInfoByName, PR_FreeAddrInfo, PR_EnumerateAddrInfo and
! PR_GetCanonNameFromAddrInfo introduced in NSPR 4.5.
! These replace stubs 49-52
! --------------------------------------------------------------------------
!
SYMBOL_VECTOR=(PR_Accept=PROCEDURE)
SYMBOL_VECTOR=(PR_AcceptRead=PROCEDURE)
@ -473,12 +482,12 @@ SYMBOL_VECTOR=(PR_VMS_Stub45=PROCEDURE)
SYMBOL_VECTOR=(PR_VMS_Stub46=PROCEDURE)
SYMBOL_VECTOR=(PR_VMS_Stub47=PROCEDURE)
SYMBOL_VECTOR=(PR_VMS_Stub48=PROCEDURE)
SYMBOL_VECTOR=(PR_VMS_Stub49=PROCEDURE)
SYMBOL_VECTOR=(PR_VMS_Stub50=PROCEDURE)
SYMBOL_VECTOR=(PR_VMS_Stub51=PROCEDURE)
SYMBOL_VECTOR=(PR_VMS_Stub52=PROCEDURE)
SYMBOL_VECTOR=(PR_VMS_Stub53=PROCEDURE)
SYMBOL_VECTOR=(LL_MaxUint=PROCEDURE)
SYMBOL_VECTOR=(PR_GetAddrInfoByName=PROCEDURE) ! was Stub49
SYMBOL_VECTOR=(PR_FreeAddrInfo=PROCEDURE) ! was Stub50
SYMBOL_VECTOR=(PR_EnumerateAddrInfo=PROCEDURE) ! was Stub51
SYMBOL_VECTOR=(PR_GetCanonNameFromAddrInfo=PROCEDURE) ! was Stub52
SYMBOL_VECTOR=(PR_GetPathSeparator=PROCEDURE) ! was Stub53
SYMBOL_VECTOR=(LL_MaxUint=PROCEDURE) ! was Stub54
!
SYMBOL_VECTOR=(PR_CallOnceWithArg=PROCEDURE)
SYMBOL_VECTOR=(PR_GetLibraryFilePathname=PROCEDURE)

Просмотреть файл

@ -76,6 +76,7 @@ CSRCS = \
foreign.c \
forktest.c \
fsync.c \
getai.c \
gethost.c \
getproto.c \
i2l.c \