Index: trunk/src/libs/xpcom18a4/Makefile.kmk
===================================================================
--- trunk/src/libs/xpcom18a4/Makefile.kmk	(revision 101792)
+++ trunk/src/libs/xpcom18a4/Makefile.kmk	(revision 101793)
@@ -189,5 +189,4 @@
 	nsprpub/pr/include/prmem.h \
 	nsprpub/pr/include/prmon.h \
-	nsprpub/pr/include/prnetdb.h \
 	nsprpub/pr/include/prpdce.h \
 	nsprpub/pr/include/prprf.h \
@@ -515,5 +514,4 @@
 	nsprpub/pr/src/io/prfdcach.c \
 	nsprpub/pr/src/io/priometh.c \
-	nsprpub/pr/src/io/pripv6.c \
 	nsprpub/pr/src/io/prmapopt.c \
 	nsprpub/pr/src/io/prlayer.c \
@@ -540,5 +538,4 @@
 	nsprpub/pr/src/misc/prlog2.c \
 	nsprpub/pr/src/misc/prlong.c \
-	nsprpub/pr/src/misc/prnetdb.c \
 	nsprpub/pr/src/misc/prtime.c \
 	nsprpub/pr/src/threads/prcmon.c \
Index: trunk/src/libs/xpcom18a4/nsprpub/pr/include/prio.h
===================================================================
--- trunk/src/libs/xpcom18a4/nsprpub/pr/include/prio.h	(revision 101792)
+++ trunk/src/libs/xpcom18a4/nsprpub/pr/include/prio.h	(revision 101793)
@@ -103,7 +103,4 @@
 #define PR_MakeDir VBoxNsprPR_MakeDir
 #define PR_RmDir VBoxNsprPR_RmDir
-#define PR_NewUDPSocket VBoxNsprPR_NewUDPSocket
-#define PR_NewTCPSocket VBoxNsprPR_NewTCPSocket
-#define PR_OpenUDPSocket VBoxNsprPR_OpenUDPSocket
 #define PR_OpenTCPSocket VBoxNsprPR_OpenTCPSocket
 #define PR_ConnectContinue VBoxNsprPR_ConnectContinue
@@ -116,5 +113,4 @@
 #define PR_TransmitFile VBoxNsprPR_TransmitFile
 #define PR_SendFile VBoxNsprPR_SendFile
-#define PR_NewTCPSocketPair VBoxNsprPR_NewTCPSocketPair
 #define PR_GetSockName VBoxNsprPR_GetSockName
 #define PR_GetPeerName VBoxNsprPR_GetPeerName
@@ -1255,62 +1251,4 @@
 /*
  *************************************************************************
- * FUNCTION: PR_NewUDPSocket
- * DESCRIPTION:
- *     Create a new UDP socket.
- * INPUTS:
- *     None
- * OUTPUTS:
- *     None
- * RETURN: PRFileDesc*
- *     Upon successful completion, PR_NewUDPSocket returns a pointer
- *     to the PRFileDesc created for the newly opened UDP socket.
- *     Returns a NULL pointer if the creation of a new UDP socket failed.
- *
- **************************************************************************
- */
-
-NSPR_API(PRFileDesc*)    PR_NewUDPSocket(void);
-
-/*
- *************************************************************************
- * FUNCTION: PR_NewTCPSocket
- * DESCRIPTION:
- *     Create a new TCP socket.
- * INPUTS:
- *     None
- * OUTPUTS:
- *     None
- * RETURN: PRFileDesc*
- *     Upon successful completion, PR_NewTCPSocket returns a pointer
- *     to the PRFileDesc created for the newly opened TCP socket.
- *     Returns a NULL pointer if the creation of a new TCP socket failed.
- *
- **************************************************************************
- */
-
-NSPR_API(PRFileDesc*)    PR_NewTCPSocket(void);
-
-/*
- *************************************************************************
- * FUNCTION: PR_OpenUDPSocket
- * DESCRIPTION:
- *     Create a new UDP socket of the specified address family.
- * INPUTS:
- *     PRIntn af
- *       Address family
- * OUTPUTS:
- *     None
- * RETURN: PRFileDesc*
- *     Upon successful completion, PR_OpenUDPSocket returns a pointer
- *     to the PRFileDesc created for the newly opened UDP socket.
- *     Returns a NULL pointer if the creation of a new UDP socket failed.
- *
- **************************************************************************
- */
-
-NSPR_API(PRFileDesc*)    PR_OpenUDPSocket(PRIntn af);
-
-/*
- *************************************************************************
  * FUNCTION: PR_OpenTCPSocket
  * DESCRIPTION:
@@ -1801,26 +1739,4 @@
 /*
 *************************************************************************
-** FUNCTION: PR_NewTCPSocketPair
-** DESCRIPTION:
-**    Create a new TCP socket pair. The returned descriptors can be used
-**    interchangeably; they are interconnected full-duplex descriptors: data
-**    written to one can be read from the other and vice-versa.
-**
-** INPUTS:
-**    None
-** OUTPUTS:
-**    PRFileDesc *fds[2]
-**        The file descriptor pair for the newly created TCP sockets.
-** RETURN: PRStatus
-**     Upon successful completion of TCP socket pair, PR_NewTCPSocketPair 
-**     returns PR_SUCCESS.  Otherwise, it returns PR_FAILURE.  Further
-**     failure information can be obtained by calling PR_GetError().
-** XXX can we implement this on windoze and mac?
-**************************************************************************
-**/
-NSPR_API(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2]);
-
-/*
-*************************************************************************
 ** FUNCTION: PR_GetSockName
 ** DESCRIPTION:
Index: trunk/src/libs/xpcom18a4/nsprpub/pr/src/io/pripv6.c
===================================================================
--- trunk/src/libs/xpcom18a4/nsprpub/pr/src/io/pripv6.c	(revision 101792)
+++ 	(revision )
@@ -1,382 +1,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Netscape Portable Runtime (NSPR).
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998-2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
-** File:        pripv6.c
-** Description: Support for various functions unique to IPv6
-*/
-#include "primpl.h"
-#include <string.h>
-
-#if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
-
-static PRIOMethods ipv6_to_v4_tcpMethods;
-static PRIOMethods ipv6_to_v4_udpMethods;
-static PRDescIdentity _pr_ipv6_to_ipv4_id;
-extern PRBool IsValidNetAddr(const PRNetAddr *addr);
-extern PRIPv6Addr _pr_in6addr_any;
-extern PRIPv6Addr _pr_in6addr_loopback;
-
-/*
- * convert an IPv4-mapped IPv6 addr to an IPv4 addr
- */
-static void _PR_ConvertToIpv4NetAddr(const PRNetAddr *src_v6addr,
-											PRNetAddr *dst_v4addr)
-{
-const PRUint8 *srcp;
-
-	PR_ASSERT(PR_AF_INET6 == src_v6addr->ipv6.family);
-
-	if (PR_IsNetAddrType(src_v6addr, PR_IpAddrV4Mapped)) {
-		srcp = src_v6addr->ipv6.ip.pr_s6_addr;
-		memcpy((char *) &dst_v4addr->inet.ip, srcp + 12, 4);
-    } else if (PR_IsNetAddrType(src_v6addr, PR_IpAddrAny)) {
-        dst_v4addr->inet.ip = htonl(INADDR_ANY);
-    } else if (PR_IsNetAddrType(src_v6addr, PR_IpAddrLoopback)) {
-        dst_v4addr->inet.ip = htonl(INADDR_LOOPBACK);
-    }
-	dst_v4addr->inet.family = PR_AF_INET;
-	dst_v4addr->inet.port = src_v6addr->ipv6.port;
-}
-
-/*
- * convert an IPv4 addr to an IPv4-mapped IPv6 addr
- */
-static void _PR_ConvertToIpv6NetAddr(const PRNetAddr *src_v4addr,
-                                            PRNetAddr *dst_v6addr)
-{
-PRUint8 *dstp;
-
-	PR_ASSERT(PR_AF_INET == src_v4addr->inet.family);
-	dst_v6addr->ipv6.family = PR_AF_INET6;
-	dst_v6addr->ipv6.port = src_v4addr->inet.port;
-
- 	if (htonl(INADDR_ANY) == src_v4addr->inet.ip) {
-		dst_v6addr->ipv6.ip = _pr_in6addr_any;
-	} else {
-		dstp = dst_v6addr->ipv6.ip.pr_s6_addr;
-		memset(dstp, 0, 10);
-		memset(dstp + 10, 0xff, 2);
-		memcpy(dstp + 12,(char *) &src_v4addr->inet.ip, 4);
-	}
-}
-
-static PRStatus PR_CALLBACK Ipv6ToIpv4SocketBind(PRFileDesc *fd,
-								const PRNetAddr *addr)
-{
-	PRNetAddr tmp_ipv4addr;
-	const PRNetAddr *tmp_addrp;
-	PRFileDesc *lo = fd->lower;
-
-	if (PR_AF_INET6 != addr->raw.family) {
-        PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
-		return PR_FAILURE;
-	}
-	if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
-    			PR_IsNetAddrType(addr, PR_IpAddrAny)) {
-		_PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
-		tmp_addrp = &tmp_ipv4addr;
-	} else {
-        PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, 0);
-		return PR_FAILURE;
-	}
-	return((lo->methods->bind)(lo,tmp_addrp));
-}
-
-static PRStatus PR_CALLBACK Ipv6ToIpv4SocketConnect(
-    PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
-{
-	PRNetAddr tmp_ipv4addr;
-	const PRNetAddr *tmp_addrp;
-
-	if (PR_AF_INET6 != addr->raw.family) {
-        PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
-		return PR_FAILURE;
-	}
-	if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
-			PR_IsNetAddrType(addr, PR_IpAddrLoopback)) {
-		_PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
-		tmp_addrp = &tmp_ipv4addr;
-	} else {
-        PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, 0);
-		return PR_FAILURE;
-	}
-	return (fd->lower->methods->connect)(fd->lower, tmp_addrp, timeout);
-}
-
-static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketSendTo(
-    PRFileDesc *fd, const void *buf, PRInt32 amount,
-    PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout)
-{
-	PRNetAddr tmp_ipv4addr;
-	const PRNetAddr *tmp_addrp;
-
-	if (PR_AF_INET6 != addr->raw.family) {
-        PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
-		return PR_FAILURE;
-	}
-	if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
-			PR_IsNetAddrType(addr, PR_IpAddrLoopback)) {
-		_PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
-		tmp_addrp = &tmp_ipv4addr;
-	} else {
-        PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, 0);
-		return PR_FAILURE;
-	}
-    return (fd->lower->methods->sendto)(
-        fd->lower, buf, amount, flags, tmp_addrp, timeout);
-}
-
-static PRFileDesc* PR_CALLBACK Ipv6ToIpv4SocketAccept (
-    PRFileDesc *fd, PRNetAddr *addr, PRIntervalTime timeout)
-{
-    PRStatus rv;
-    PRFileDesc *newfd;
-    PRFileDesc *newstack;
-	PRNetAddr tmp_ipv4addr;
-    PRNetAddr *addrlower = NULL;
-
-    PR_ASSERT(fd != NULL);
-    PR_ASSERT(fd->lower != NULL);
-
-    newstack = PR_NEW(PRFileDesc);
-    if (NULL == newstack)
-    {
-        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
-        return NULL;
-    }
-    *newstack = *fd;  /* make a copy of the accepting layer */
-
-    if (addr)
-        addrlower = &tmp_ipv4addr;
-    newfd = (fd->lower->methods->accept)(fd->lower, addrlower, timeout);
-    if (NULL == newfd)
-    {
-        PR_DELETE(newstack);
-        return NULL;
-    }
-    if (addr)
-        _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, addr);
-
-    rv = PR_PushIOLayer(newfd, PR_TOP_IO_LAYER, newstack);
-    PR_ASSERT(PR_SUCCESS == rv);
-    return newfd;  /* that's it */
-}
-
-static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketAcceptRead(PRFileDesc *sd,
-			PRFileDesc **nd, PRNetAddr **ipv6_raddr, void *buf, PRInt32 amount,
-							PRIntervalTime timeout)
-{
-    PRInt32 nbytes;
-    PRStatus rv;
-	PRNetAddr tmp_ipv4addr;
-    PRFileDesc *newstack;
-
-    PR_ASSERT(sd != NULL);
-    PR_ASSERT(sd->lower != NULL);
-
-    newstack = PR_NEW(PRFileDesc);
-    if (NULL == newstack)
-    {
-        PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
-        return -1;
-    }
-    *newstack = *sd;  /* make a copy of the accepting layer */
-
-    nbytes = sd->lower->methods->acceptread(
-        sd->lower, nd, ipv6_raddr, buf, amount, timeout);
-    if (-1 == nbytes)
-    {
-        PR_DELETE(newstack);
-        return nbytes;
-    }
-	tmp_ipv4addr = **ipv6_raddr;	/* copy */
-	_PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, *ipv6_raddr);
-
-    /* this PR_PushIOLayer call cannot fail */
-    rv = PR_PushIOLayer(*nd, PR_TOP_IO_LAYER, newstack);
-    PR_ASSERT(PR_SUCCESS == rv);
-    return nbytes;
-}
-
-static PRStatus PR_CALLBACK Ipv6ToIpv4SocketGetName(PRFileDesc *fd,
-										PRNetAddr *ipv6addr)
-{
-	PRStatus result;
-	PRNetAddr tmp_ipv4addr;
-
-	result = (fd->lower->methods->getsockname)(fd->lower, &tmp_ipv4addr);
-	if (PR_SUCCESS == result) {
-		_PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
-		PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
-	}
-	return result;
-}
-
-static PRStatus PR_CALLBACK Ipv6ToIpv4SocketGetPeerName(PRFileDesc *fd,
-										PRNetAddr *ipv6addr)
-{
-	PRStatus result;
-	PRNetAddr tmp_ipv4addr;
-
-	result = (fd->lower->methods->getpeername)(fd->lower, &tmp_ipv4addr);
-	if (PR_SUCCESS == result) {
-		_PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
-		PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
-	}
-	return result;
-}
-
-static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketRecvFrom(PRFileDesc *fd, void *buf,
-			PRInt32 amount, PRIntn flags, PRNetAddr *ipv6addr,
-				PRIntervalTime timeout)
-{
-	PRNetAddr tmp_ipv4addr;
-	PRInt32 result;
-
-    result = (fd->lower->methods->recvfrom)(
-        fd->lower, buf, amount, flags, &tmp_ipv4addr, timeout);
-	if (-1 != result) {
-		_PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
-		PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
-	}
-	return result;
-}
-
-#if defined(_PR_INET6_PROBE)
-PRBool _pr_ipv6_is_present;
-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)
-    _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");
-    PR_ASSERT(PR_INVALID_IO_LAYER != _pr_ipv6_to_ipv4_id);
-
-	stubMethods = PR_GetDefaultIOMethods();
-
-	ipv6_to_v4_tcpMethods = *stubMethods;  /* first get the entire batch */
-	/* then override the ones we care about */
-	ipv6_to_v4_tcpMethods.connect = Ipv6ToIpv4SocketConnect;
-	ipv6_to_v4_tcpMethods.bind = Ipv6ToIpv4SocketBind;
-	ipv6_to_v4_tcpMethods.accept = Ipv6ToIpv4SocketAccept;
-	ipv6_to_v4_tcpMethods.acceptread = Ipv6ToIpv4SocketAcceptRead;
-	ipv6_to_v4_tcpMethods.getsockname = Ipv6ToIpv4SocketGetName;
-	ipv6_to_v4_tcpMethods.getpeername = Ipv6ToIpv4SocketGetPeerName;
-/*
-	ipv6_to_v4_tcpMethods.getsocketoption = Ipv6ToIpv4GetSocketOption;
-	ipv6_to_v4_tcpMethods.setsocketoption = Ipv6ToIpv4SetSocketOption;
-*/
-	ipv6_to_v4_udpMethods = *stubMethods;  /* first get the entire batch */
-	/* then override the ones we care about */
-	ipv6_to_v4_udpMethods.connect = Ipv6ToIpv4SocketConnect;
-	ipv6_to_v4_udpMethods.bind = Ipv6ToIpv4SocketBind;
-	ipv6_to_v4_udpMethods.sendto = Ipv6ToIpv4SocketSendTo;
-	ipv6_to_v4_udpMethods.recvfrom = Ipv6ToIpv4SocketRecvFrom;
-	ipv6_to_v4_tcpMethods.getsockname = Ipv6ToIpv4SocketGetName;
-	ipv6_to_v4_tcpMethods.getpeername = Ipv6ToIpv4SocketGetPeerName;
-/*
-	ipv6_to_v4_tcpMethods.getsocketoption = Ipv6ToIpv4GetSocketOption;
-	ipv6_to_v4_tcpMethods.setsocketoption = Ipv6ToIpv4SetSocketOption;
-*/
-	return PR_SUCCESS;
-}
-
-PR_IMPLEMENT(PRStatus) _pr_push_ipv6toipv4_layer(PRFileDesc *fd)
-{
-	PRFileDesc *ipv6_fd = NULL;
-
-	/*
-	 * For platforms with no support for IPv6 
-	 * create layered socket for IPv4-mapped IPv6 addresses
-	 */
-	if (fd->methods->file_type == PR_DESC_SOCKET_TCP)
-		ipv6_fd = PR_CreateIOLayerStub(_pr_ipv6_to_ipv4_id,
-									&ipv6_to_v4_tcpMethods);
-	else
-		ipv6_fd = PR_CreateIOLayerStub(_pr_ipv6_to_ipv4_id,
-									&ipv6_to_v4_udpMethods);
-	if (NULL == ipv6_fd) {
-		goto errorExit;
-	} 
-	ipv6_fd->secret = NULL;
-
-	if (PR_PushIOLayer(fd, PR_TOP_IO_LAYER, ipv6_fd) == PR_FAILURE) {
-		goto errorExit;
-	}
-
-	return PR_SUCCESS;
-errorExit:
-
-	if (ipv6_fd)
-		ipv6_fd->dtor(ipv6_fd);
-	return PR_FAILURE;
-}
-
-#endif /* !defined(_PR_INET6) || defined(_PR_INET6_PROBE) */
Index: trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c
===================================================================
--- trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c	(revision 101792)
+++ trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prinit.c	(revision 101793)
@@ -216,5 +216,4 @@
     _PR_InitCMon();
     _PR_InitIO();
-    _PR_InitNet();
     _PR_InitLog();
     _PR_InitLinker();
@@ -223,8 +222,4 @@
 
     nspr_InitializePRErrorTable();
-
-#if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
-	_pr_init_ipv6();
-#endif
 
     _PR_MD_FINAL_INIT();
@@ -429,5 +424,4 @@
          * _PR_XXXCleanup() that we can call here.
          */
-        _PR_CleanupNet();
         _PR_CleanupIO();
 #ifdef WINNT
Index: trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prnetdb.c
===================================================================
--- trunk/src/libs/xpcom18a4/nsprpub/pr/src/misc/prnetdb.c	(revision 101792)
+++ 	(revision )
@@ -1,2189 +1,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is the Netscape Portable Runtime (NSPR).
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998-2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#include "primpl.h"
-
-#include <string.h>
-
-/*
- * On Unix, the error code for gethostbyname() and gethostbyaddr()
- * is returned in the global variable h_errno, instead of the usual
- * errno.
- */
-#if defined(XP_UNIX)
-#if defined(_PR_NEED_H_ERRNO)
-extern int h_errno;
-#endif
-#define _MD_GETHOST_ERRNO() h_errno
-#else
-#define _MD_GETHOST_ERRNO() _MD_ERRNO()
-#endif
-
-/*
- * The meaning of the macros related to gethostbyname, gethostbyaddr,
- * and gethostbyname2 is defined below.
- * - _PR_HAVE_THREADSAFE_GETHOST: the gethostbyXXX functions return
- *   the result in thread specific storage.  For example, AIX, HP-UX,
- *   and OSF1.
- * -  _PR_HAVE_GETHOST_R: have the gethostbyXXX_r functions. See next
- *   two macros.
- * - _PR_HAVE_GETHOST_R_INT: the gethostbyXXX_r functions return an
- *   int.  For example, Linux glibc.
- * - _PR_HAVE_GETHOST_R_POINTER: the gethostbyXXX_r functions return
- *   a struct hostent* pointer.  For example, Solaris and IRIX.
- */
-#if defined(_PR_NO_PREEMPT) || defined(_PR_HAVE_GETHOST_R) \
-    || defined(_PR_HAVE_THREADSAFE_GETHOST)
-#define _PR_NO_DNS_LOCK
-#endif
-
-#if defined(_PR_NO_DNS_LOCK)
-#define LOCK_DNS()
-#define UNLOCK_DNS()
-#else
-PRLock *_pr_dnsLock = NULL;
-#define LOCK_DNS() PR_Lock(_pr_dnsLock)
-#define UNLOCK_DNS() PR_Unlock(_pr_dnsLock)
-#endif  /* defined(_PR_NO_DNS_LOCK) */
-
-/*
- * Some platforms have the reentrant getprotobyname_r() and
- * getprotobynumber_r().  However, they come in two flavors.
- * Some return a pointer to struct protoent, others return
- * an int.
- */
-#if defined(XP_BEOS) && defined(BONE_VERSION)
-#include <arpa/inet.h>  /* pick up define for inet_addr */
-#include <sys/socket.h>
-#define _PR_HAVE_GETPROTO_R
-#define _PR_HAVE_GETPROTO_R_POINTER
-#endif
-
-#if defined(SOLARIS) || (defined(BSDI) && defined(_REENTRANT)) \
-	|| (defined(LINUX) && defined(_REENTRANT) \
-        && !(defined(__GLIBC__) && __GLIBC__ >= 2))
-#define _PR_HAVE_GETPROTO_R
-#define _PR_HAVE_GETPROTO_R_POINTER
-#endif
-
-#if defined(OSF1) \
-        || defined(AIX4_3_PLUS) || (defined(AIX) && defined(_THREAD_SAFE)) \
-	|| (defined(HPUX10_10) && defined(_REENTRANT)) \
-        || (defined(HPUX10_20) && defined(_REENTRANT))
-#define _PR_HAVE_GETPROTO_R
-#define _PR_HAVE_GETPROTO_R_INT
-#endif
-
-#if (defined(LINUX) && defined(__GLIBC__) && __GLIBC__ >= 2)
-#define _PR_HAVE_GETPROTO_R
-#define _PR_HAVE_5_ARG_GETPROTO_R
-#endif
-
-#if !defined(_PR_HAVE_GETPROTO_R)
-PRLock* _getproto_lock = NULL;
-#endif
-
-#if defined(_PR_INET6_PROBE)
-PR_EXTERN(PRBool) _pr_ipv6_is_present;
-#endif
-
-#define _PR_IN6_IS_ADDR_UNSPECIFIED(a)				\
-				(((a)->pr_s6_addr32[0] == 0) &&	\
-				((a)->pr_s6_addr32[1] == 0) &&		\
-				((a)->pr_s6_addr32[2] == 0) &&		\
-				((a)->pr_s6_addr32[3] == 0))
- 
-#define _PR_IN6_IS_ADDR_LOOPBACK(a)					\
-               (((a)->pr_s6_addr32[0] == 0)	&&	\
-               ((a)->pr_s6_addr32[1] == 0)		&&	\
-               ((a)->pr_s6_addr32[2] == 0)		&&	\
-               ((a)->pr_s6_addr[12] == 0)		&&	\
-               ((a)->pr_s6_addr[13] == 0)		&&	\
-               ((a)->pr_s6_addr[14] == 0)		&&	\
-               ((a)->pr_s6_addr[15] == 0x1U))
- 
-const PRIPv6Addr _pr_in6addr_any =	{{{ 0, 0, 0, 0,
-										0, 0, 0, 0,
-										0, 0, 0, 0,
-										0, 0, 0, 0 }}};
-
-const PRIPv6Addr _pr_in6addr_loopback = {{{ 0, 0, 0, 0,
-											0, 0, 0, 0,
-											0, 0, 0, 0,
-											0, 0, 0, 0x1U }}};
-/*
- * The values at bytes 10 and 11 are compared using pointers to
- * 8-bit fields, and not 32-bit fields, to make the comparison work on
- * both big-endian and little-endian systems
- */
-
-#define _PR_IN6_IS_ADDR_V4MAPPED(a)			\
-		(((a)->pr_s6_addr32[0] == 0) 	&&	\
-		((a)->pr_s6_addr32[1] == 0)	&&	\
-		((a)->pr_s6_addr[8] == 0)		&&	\
-		((a)->pr_s6_addr[9] == 0)		&&	\
-		((a)->pr_s6_addr[10] == 0xff)	&&	\
-		((a)->pr_s6_addr[11] == 0xff))
-
-#define _PR_IN6_IS_ADDR_V4COMPAT(a)			\
-		(((a)->pr_s6_addr32[0] == 0) &&	\
-		((a)->pr_s6_addr32[1] == 0) &&		\
-		((a)->pr_s6_addr32[2] == 0))
-
-#define _PR_IN6_V4MAPPED_TO_IPADDR(a) ((a)->pr_s6_addr32[3])
-
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
-
-/*
- * The _pr_QueryNetIfs() function finds out if the system has
- * IPv4 or IPv6 source addresses configured and sets _pr_have_inet_if
- * and _pr_have_inet6_if accordingly.
- *
- * We have an implementation using SIOCGIFCONF ioctl and a
- * default implementation that simply sets _pr_have_inet_if
- * and _pr_have_inet6_if to true.  A better implementation
- * would be to use the routing sockets (see Chapter 17 of
- * W. Richard Stevens' Unix Network Programming, Vol. 1, 2nd. Ed.)
- */
-
-static PRLock *_pr_query_ifs_lock = NULL;
-static PRBool _pr_have_inet_if = PR_FALSE;
-static PRBool _pr_have_inet6_if = PR_FALSE;
-
-#undef DEBUG_QUERY_IFS
-
-#if defined(AIX) \
-    || (defined(DARWIN) && (!defined(HAVE_GETIFADDRS) \
-        || (defined(MACOS_DEPLOYMENT_TARGET) \
-        && MACOS_DEPLOYMENT_TARGET < 100200)))
-
-/*
- * Use SIOCGIFCONF ioctl on platforms that don't have routing
- * sockets.  Warning: whether SIOCGIFCONF ioctl returns AF_INET6
- * network interfaces is not portable.
- *
- * The _pr_QueryNetIfs() function is derived from the code in
- * src/lib/libc/net/getifaddrs.c in BSD Unix and the code in
- * Section 16.6 of W. Richard Stevens' Unix Network Programming,
- * Vol. 1, 2nd. Ed.
- */
-
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <net/if.h>
-
-#ifdef DEBUG_QUERY_IFS
-static void
-_pr_PrintIfreq(struct ifreq *ifr)
-{
-    PRNetAddr addr;
-    struct sockaddr *sa;
-    const char* family;
-    char addrstr[64];
-
-    sa = &ifr->ifr_addr;
-    if (sa->sa_family == AF_INET) {
-        struct sockaddr_in *sin = (struct sockaddr_in *)sa;
-        family = "inet";
-        memcpy(&addr.inet.ip, &sin->sin_addr, sizeof(sin->sin_addr));
-    } else if (sa->sa_family == AF_INET6) {
-        struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
-        family = "inet6";
-        memcpy(&addr.ipv6.ip, &sin6->sin6_addr, sizeof(sin6->sin6_addr));
-    } else {
-        return;  /* skip if not AF_INET or AF_INET6 */
-    }
-    addr.raw.family = sa->sa_family;
-    PR_NetAddrToString(&addr, addrstr, sizeof(addrstr));
-    printf("%s: %s %s\n", ifr->ifr_name, family, addrstr);
-}
-#endif
-
-static void
-_pr_QueryNetIfs(void)
-{
-    int sock;
-    int rv;
-    struct ifconf ifc;
-    struct ifreq *ifr;
-    struct ifreq *lifr;
-    PRUint32 len, lastlen;
-    char *buf;
-
-    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
-        return;
-    }
-
-    /* Issue SIOCGIFCONF request in a loop. */
-    lastlen = 0;
-    len = 100 * sizeof(struct ifreq);  /* initial buffer size guess */
-    for (;;) {
-        buf = (char *)PR_Malloc(len);
-        if (NULL == buf) {
-            close(sock);
-            return;
-        }
-        ifc.ifc_buf = buf;
-        ifc.ifc_len = len;
-        rv = ioctl(sock, SIOCGIFCONF, &ifc);
-        if (rv < 0) {
-            if (errno != EINVAL || lastlen != 0) {
-                close(sock);
-                PR_Free(buf);
-                return;
-            }
-        } else {
-            if (ifc.ifc_len == lastlen)
-                break;  /* success, len has not changed */
-            lastlen = ifc.ifc_len;
-        }
-        len += 10 * sizeof(struct ifreq);  /* increment */
-        PR_Free(buf);
-    }
-    close(sock);
-
-    ifr = ifc.ifc_req;
-    lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len];
-
-    while (ifr < lifr) {
-        struct sockaddr *sa;
-        int sa_len;
-
-#ifdef DEBUG_QUERY_IFS
-        _pr_PrintIfreq(ifr);
-#endif
-        sa = &ifr->ifr_addr;
-        if (sa->sa_family == AF_INET) {
-            struct sockaddr_in *sin = (struct sockaddr_in *) sa;
-            if (sin->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) {
-                _pr_have_inet_if = PR_TRUE;
-            } 
-        } else if (sa->sa_family == AF_INET6) {
-            struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
-            if (!IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)
-                    && !IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
-                _pr_have_inet6_if = PR_TRUE;
-            } 
-        }
-
-#ifdef _PR_HAVE_SOCKADDR_LEN
-        sa_len = PR_MAX(sa->sa_len, sizeof(struct sockaddr));
-#else
-        switch (sa->sa_family) {
-#ifdef AF_LINK
-        case AF_LINK:
-            sa_len = sizeof(struct sockaddr_dl);
-            break;
-#endif
-        case AF_INET6:
-            sa_len = sizeof(struct sockaddr_in6);
-            break;
-        default:
-            sa_len = sizeof(struct sockaddr);
-            break;
-        }
-#endif
-        ifr = (struct ifreq *)(((char *)sa) + sa_len);
-    }
-    PR_Free(buf);
-}
-
-#elif (defined(DARWIN) && defined(HAVE_GETIFADDRS)) || defined(FREEBSD) \
-    || defined(NETBSD) || defined(OPENBSD)
-
-/*
- * Use the BSD getifaddrs function.
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <ifaddrs.h>
-#include <netinet/in.h>
-
-#ifdef DEBUG_QUERY_IFS
-static void
-_pr_PrintIfaddrs(struct ifaddrs *ifa)
-{
-    struct sockaddr *sa;
-    const char* family;
-    void *addrp;
-    char addrstr[64];
-
-    sa = ifa->ifa_addr;
-    if (sa->sa_family == AF_INET) {
-        struct sockaddr_in *sin = (struct sockaddr_in *)sa;
-        family = "inet";
-        addrp = &sin->sin_addr;
-    } else if (sa->sa_family == AF_INET6) {
-        struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
-        family = "inet6";
-        addrp = &sin6->sin6_addr;
-    } else {
-        return;  /* skip if not AF_INET or AF_INET6 */
-    }
-    inet_ntop(sa->sa_family, addrp, addrstr, sizeof(addrstr));
-    printf("%s: %s %s\n", ifa->ifa_name, family, addrstr);
-}
-#endif
-
-static void
-_pr_QueryNetIfs(void)
-{
-    struct ifaddrs *ifp;
-    struct ifaddrs *ifa;
-
-    if (getifaddrs(&ifp) == -1) {
-        return;
-    }
-    for (ifa = ifp; ifa; ifa = ifa->ifa_next) {
-        struct sockaddr *sa;
-
-#ifdef DEBUG_QUERY_IFS
-        _pr_PrintIfaddrs(ifa);
-#endif
-        sa = ifa->ifa_addr;
-        if (sa->sa_family == AF_INET) {
-            struct sockaddr_in *sin = (struct sockaddr_in *) sa;
-            if (sin->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) {
-                _pr_have_inet_if = 1;
-            } 
-        } else if (sa->sa_family == AF_INET6) {
-            struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
-            if (!IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)
-                    && !IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
-                _pr_have_inet6_if = 1;
-            } 
-        }
-    } 
-    freeifaddrs(ifp);
-}
-
-#else  /* default */
-
-/*
- * Emulate the code in NSPR 4.2 or older.  PR_GetIPNodeByName behaves
- * as if the system had both IPv4 and IPv6 source addresses configured.
- */
-static void
-_pr_QueryNetIfs(void)
-{
-    _pr_have_inet_if = PR_TRUE;
-    _pr_have_inet6_if = PR_TRUE;
-}
-
-#endif
-
-#endif  /* _PR_INET6 && _PR_HAVE_GETHOSTBYNAME2 */
-
-void _PR_InitNet(void)
-{
-#if defined(XP_UNIX)
-#ifdef HAVE_NETCONFIG
-	/*
-	 * This one-liner prevents the endless re-open's and re-read's of
-	 * /etc/netconfig on EACH and EVERY call to accept(), connect(), etc.
-	 */
-	 (void)setnetconfig();
-#endif
-#endif
-#if !defined(_PR_NO_DNS_LOCK)
-	_pr_dnsLock = PR_NewLock();
-#endif
-#if !defined(_PR_HAVE_GETPROTO_R)
-	_getproto_lock = PR_NewLock();
-#endif
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
-	_pr_query_ifs_lock = PR_NewLock();
-#endif
-}
-
-void _PR_CleanupNet(void)
-{
-#if !defined(_PR_NO_DNS_LOCK)
-    if (_pr_dnsLock) {
-        PR_DestroyLock(_pr_dnsLock);
-        _pr_dnsLock = NULL;
-    }
-#endif
-#if !defined(_PR_HAVE_GETPROTO_R)
-    if (_getproto_lock) {
-        PR_DestroyLock(_getproto_lock);
-        _getproto_lock = NULL;
-    }
-#endif
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
-    if (_pr_query_ifs_lock) {
-        PR_DestroyLock(_pr_query_ifs_lock);
-        _pr_query_ifs_lock = NULL;
-    }
-#endif
-}
-
-/*
-** Allocate space from the buffer, aligning it to "align" before doing
-** the allocation. "align" must be a power of 2.
-*/
-static char *Alloc(PRIntn amount, char **bufp, PRIntn *buflenp, PRIntn align)
-{
-	char *buf = *bufp;
-	PRIntn buflen = *buflenp;
-
-	if (align && ((long)buf & (align - 1))) {
-		PRIntn skip = align - ((ptrdiff_t)buf & (align - 1));
-		if (buflen < skip) {
-			return 0;
-		}
-		buf += skip;
-		buflen -= skip;
-	}
-	if (buflen < amount) {
-		return 0;
-	}
-	*bufp = buf + amount;
-	*buflenp = buflen - amount;
-	return buf;
-}
-
-typedef enum _PRIPAddrConversion {
-    _PRIPAddrNoConversion,
-    _PRIPAddrIPv4Mapped,
-    _PRIPAddrIPv4Compat
-} _PRIPAddrConversion;
-
-/*
-** Convert an IPv4 address (v4) to an IPv4-mapped IPv6 address (v6).
-*/
-static void MakeIPv4MappedAddr(const char *v4, char *v6)
-{
-    memset(v6, 0, 10);
-    memset(v6 + 10, 0xff, 2);
-    memcpy(v6 + 12, v4, 4);
-}
-
-/*
-** Convert an IPv4 address (v4) to an IPv4-compatible IPv6 address (v6).
-*/
-static void MakeIPv4CompatAddr(const char *v4, char *v6)
-{
-    memset(v6, 0, 12);
-    memcpy(v6 + 12, v4, 4);
-}
-
-/*
-** Copy a hostent, and all of the memory that it refers to into
-** (hopefully) stacked buffers.
-*/
-static PRStatus CopyHostent(
-    struct hostent *from,
-    char **buf,
-    PRIntn *bufsize,
-    _PRIPAddrConversion conversion,
-    PRHostEnt *to)
-{
-	PRIntn len, na;
-	char **ap;
-
-	if (conversion != _PRIPAddrNoConversion
-			&& from->h_addrtype == AF_INET) {
-		PR_ASSERT(from->h_length == 4);
-		to->h_addrtype = PR_AF_INET6;
-		to->h_length = 16;
-	} else {
-#if defined(_PR_INET6) || defined(_PR_INET6_PROBE)
-		if (AF_INET6 == from->h_addrtype)
-			to->h_addrtype = PR_AF_INET6;
-		else
-#endif
-			to->h_addrtype = from->h_addrtype;
-		to->h_length = from->h_length;
-	}
-
-	/* Copy the official name */
-	if (!from->h_name) return PR_FAILURE;
-	len = strlen(from->h_name) + 1;
-	to->h_name = Alloc(len, buf, bufsize, 0);
-	if (!to->h_name) return PR_FAILURE;
-	memcpy(to->h_name, from->h_name, len);
-
-	/* Count the aliases, then allocate storage for the pointers */
-	if (!from->h_aliases) {
-		na = 1;
-	} else {
-		for (na = 1, ap = from->h_aliases; *ap != 0; na++, ap++){;} /* nothing to execute */
-	}
-	to->h_aliases = (char**)Alloc(
-	    na * sizeof(char*), buf, bufsize, sizeof(char**));
-	if (!to->h_aliases) return PR_FAILURE;
-
-	/* Copy the aliases, one at a time */
-	if (!from->h_aliases) {
-		to->h_aliases[0] = 0;
-	} else {
-		for (na = 0, ap = from->h_aliases; *ap != 0; na++, ap++) {
-			len = strlen(*ap) + 1;
-			to->h_aliases[na] = Alloc(len, buf, bufsize, 0);
-			if (!to->h_aliases[na]) return PR_FAILURE;
-			memcpy(to->h_aliases[na], *ap, len);
-		}
-		to->h_aliases[na] = 0;
-	}
-
-	/* Count the addresses, then allocate storage for the pointers */
-	for (na = 1, ap = from->h_addr_list; *ap != 0; na++, ap++){;} /* nothing to execute */
-	to->h_addr_list = (char**)Alloc(
-	    na * sizeof(char*), buf, bufsize, sizeof(char**));
-	if (!to->h_addr_list) return PR_FAILURE;
-
-	/* Copy the addresses, one at a time */
-	for (na = 0, ap = from->h_addr_list; *ap != 0; na++, ap++) {
-		to->h_addr_list[na] = Alloc(to->h_length, buf, bufsize, 0);
-		if (!to->h_addr_list[na]) return PR_FAILURE;
-		if (conversion != _PRIPAddrNoConversion
-				&& from->h_addrtype == AF_INET) {
-			if (conversion == _PRIPAddrIPv4Mapped) {
-				MakeIPv4MappedAddr(*ap, to->h_addr_list[na]);
-			} else {
-				PR_ASSERT(conversion == _PRIPAddrIPv4Compat);
-				MakeIPv4CompatAddr(*ap, to->h_addr_list[na]);
-			}
-		} else {
-			memcpy(to->h_addr_list[na], *ap, to->h_length);
-		}
-	}
-	to->h_addr_list[na] = 0;
-	return PR_SUCCESS;
-}
-
-#if !defined(_PR_HAVE_GETPROTO_R)
-/*
-** Copy a protoent, and all of the memory that it refers to into
-** (hopefully) stacked buffers.
-*/
-static PRStatus CopyProtoent(
-    struct protoent *from, char *buf, PRIntn bufsize, PRProtoEnt *to)
-{
-	PRIntn len, na;
-	char **ap;
-
-	/* Do the easy stuff */
-	to->p_num = from->p_proto;
-
-	/* Copy the official name */
-	if (!from->p_name) return PR_FAILURE;
-	len = strlen(from->p_name) + 1;
-	to->p_name = Alloc(len, &buf, &bufsize, 0);
-	if (!to->p_name) return PR_FAILURE;
-	memcpy(to->p_name, from->p_name, len);
-
-	/* Count the aliases, then allocate storage for the pointers */
-	for (na = 1, ap = from->p_aliases; *ap != 0; na++, ap++){;} /* nothing to execute */
-	to->p_aliases = (char**)Alloc(
-	    na * sizeof(char*), &buf, &bufsize, sizeof(char**));
-	if (!to->p_aliases) return PR_FAILURE;
-
-	/* Copy the aliases, one at a time */
-	for (na = 0, ap = from->p_aliases; *ap != 0; na++, ap++) {
-		len = strlen(*ap) + 1;
-		to->p_aliases[na] = Alloc(len, &buf, &bufsize, 0);
-		if (!to->p_aliases[na]) return PR_FAILURE;
-		memcpy(to->p_aliases[na], *ap, len);
-	}
-	to->p_aliases[na] = 0;
-
-	return PR_SUCCESS;
-}
-#endif /* !defined(_PR_HAVE_GETPROTO_R) */
-
-/*
- * #################################################################
- * NOTE: tmphe, tmpbuf, bufsize, h, and h_err are local variables
- * or arguments of PR_GetHostByName, PR_GetIPNodeByName, and
- * PR_GetHostByAddr.  DO NOT CHANGE THE NAMES OF THESE LOCAL 
- * VARIABLES OR ARGUMENTS.
- * #################################################################
- */
-#if defined(_PR_HAVE_GETHOST_R_INT)
-
-#define GETHOSTBYNAME(name) \
-    (gethostbyname_r(name, &tmphe, tmpbuf, bufsize, &h, &h_err), h)
-#define GETHOSTBYNAME2(name, af) \
-    (gethostbyname2_r(name, af, &tmphe, tmpbuf, bufsize, &h, &h_err), h)
-#define GETHOSTBYADDR(addr, addrlen, af) \
-    (gethostbyaddr_r(addr, addrlen, af, \
-    &tmphe, tmpbuf, bufsize, &h, &h_err), h)
-
-#elif defined(_PR_HAVE_GETHOST_R_POINTER)
-
-#define GETHOSTBYNAME(name) \
-    gethostbyname_r(name, &tmphe, tmpbuf, bufsize, &h_err)
-#define GETHOSTBYNAME2(name, af) \
-    gethostbyname2_r(name, af, &tmphe, tmpbuf, bufsize, &h_err)
-#define GETHOSTBYADDR(addr, addrlen, af) \
-    gethostbyaddr_r(addr, addrlen, af, &tmphe, tmpbuf, bufsize, &h_err)
-
-#else
-
-#define GETHOSTBYNAME(name) gethostbyname(name)
-#define GETHOSTBYNAME2(name, af) gethostbyname2(name, af)
-#define GETHOSTBYADDR(addr, addrlen, af) gethostbyaddr(addr, addrlen, af)
-
-#endif  /* definition of GETHOSTBYXXX */
-
-PR_IMPLEMENT(PRStatus) PR_GetHostByName(
-    const char *name, char *buf, PRIntn bufsize, PRHostEnt *hp)
-{
-	struct hostent *h;
-	PRStatus rv = PR_FAILURE;
-#if defined(_PR_HAVE_GETHOST_R)
-    char localbuf[PR_NETDB_BUF_SIZE];
-    char *tmpbuf;
-    struct hostent tmphe;
-    int h_err;
-#endif
-
-    if (!_pr_initialized) _PR_ImplicitInitialization();
-
-#if defined(_PR_HAVE_GETHOST_R)
-    tmpbuf = localbuf;
-    if (bufsize > sizeof(localbuf))
-    {
-        tmpbuf = (char *)PR_Malloc(bufsize);
-        if (NULL == tmpbuf)
-        {
-            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
-            return rv;
-        }
-    }
-#endif
-
-	LOCK_DNS();
-
-#ifdef XP_OS2_VACPP
-	h = GETHOSTBYNAME((char *)name);
-#else
-	h = GETHOSTBYNAME(name);
-#endif
-    
-	if (NULL == h)
-	{
-	    PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
-	}
-	else
-	{
-		_PRIPAddrConversion conversion = _PRIPAddrNoConversion;
-		rv = CopyHostent(h, &buf, &bufsize, conversion, hp);
-		if (PR_SUCCESS != rv)
-		    PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
-	}
-	UNLOCK_DNS();
-#if defined(_PR_HAVE_GETHOST_R)
-    if (tmpbuf != localbuf)
-        PR_Free(tmpbuf);
-#endif
-	return rv;
-}
-
-#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 *);
-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)
-/*
-** Append the V4 addresses to the end of the list
-*/
-static PRStatus AppendV4AddrsToHostent(
-    struct hostent *from,
-    char **buf,
-    PRIntn *bufsize,
-    PRHostEnt *to)
-{
-    PRIntn na, na_old;
-    char **ap;
-    char **new_addr_list;
-			
-    /* Count the addresses, then grow storage for the pointers */
-    for (na_old = 0, ap = to->h_addr_list; *ap != 0; na_old++, ap++)
-        {;} /* nothing to execute */
-    for (na = na_old + 1, ap = from->h_addr_list; *ap != 0; na++, ap++)
-        {;} /* nothing to execute */
-    new_addr_list = (char**)Alloc(
-        na * sizeof(char*), buf, bufsize, sizeof(char**));
-    if (!new_addr_list) return PR_FAILURE;
-
-    /* Copy the V6 addresses, one at a time */
-    for (na = 0, ap = to->h_addr_list; *ap != 0; na++, ap++) {
-        new_addr_list[na] = to->h_addr_list[na];
-    }
-    to->h_addr_list = new_addr_list;
-
-    /* Copy the V4 addresses, one at a time */
-    for (ap = from->h_addr_list; *ap != 0; na++, ap++) {
-        to->h_addr_list[na] = Alloc(to->h_length, buf, bufsize, 0);
-        if (!to->h_addr_list[na]) return PR_FAILURE;
-        MakeIPv4MappedAddr(*ap, to->h_addr_list[na]);
-    }
-    to->h_addr_list[na] = 0;
-    return PR_SUCCESS;
-}
-#endif
-
-PR_IMPLEMENT(PRStatus) PR_GetIPNodeByName(
-    const char *name, PRUint16 af, PRIntn flags,
-    char *buf, PRIntn bufsize, PRHostEnt *hp)
-{
-	struct hostent *h = 0;
-	PRStatus rv = PR_FAILURE;
-#if defined(_PR_HAVE_GETHOST_R)
-    char localbuf[PR_NETDB_BUF_SIZE];
-    char *tmpbuf;
-    struct hostent tmphe;
-    int h_err;
-#endif
-#if defined(_PR_HAVE_GETIPNODEBYNAME)
-	PRUint16 md_af = af;
-	int error_num;
-	int tmp_flags = 0;
-#endif
-#if defined(_PR_HAVE_GETHOSTBYNAME2)
-    PRBool did_af_inet = PR_FALSE;
-#endif
-
-    if (!_pr_initialized) _PR_ImplicitInitialization();
-
-    if (af != PR_AF_INET && af != PR_AF_INET6) {
-        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-        return PR_FAILURE;
-    }
-
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
-    PR_Lock(_pr_query_ifs_lock);
-    /*
-     * Keep querying the presence of IPv4 and IPv6 interfaces until
-     * at least one is up.  This allows us to detect the local
-     * machine going from offline to online.
-     */
-    if (!_pr_have_inet_if && !_pr_have_inet6_if) {
-	_pr_QueryNetIfs();
-#ifdef DEBUG_QUERY_IFS
-	if (_pr_have_inet_if)
-		printf("Have IPv4 source address\n");
-	if (_pr_have_inet6_if)
-		printf("Have IPv6 source address\n");
-#endif
-    }
-    PR_Unlock(_pr_query_ifs_lock);
-#endif
-
-#if defined(_PR_HAVE_GETIPNODEBYNAME)
-	if (flags & PR_AI_V4MAPPED)
-		tmp_flags |= AI_V4MAPPED;
-	if (flags & PR_AI_ADDRCONFIG)
-		tmp_flags |= AI_ADDRCONFIG;
-	if (flags & PR_AI_ALL)
-		tmp_flags |= AI_ALL;
-    if (af == PR_AF_INET6)
-    	md_af = AF_INET6;
-	else
-    	md_af = af;
-#endif
-
-#if defined(_PR_HAVE_GETHOST_R)
-    tmpbuf = localbuf;
-    if (bufsize > sizeof(localbuf))
-    {
-        tmpbuf = (char *)PR_Malloc(bufsize);
-        if (NULL == tmpbuf)
-        {
-            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
-            return rv;
-        }
-    }
-#endif
-
-    /* Do not need to lock the DNS lock if getipnodebyname() is called */
-#ifdef _PR_INET6
-#ifdef _PR_HAVE_GETHOSTBYNAME2
-    LOCK_DNS();
-    if (af == PR_AF_INET6)
-    {
-        if ((flags & PR_AI_ADDRCONFIG) == 0 || _pr_have_inet6_if)
-        {
-#ifdef _PR_INET6_PROBE
-          if (_pr_ipv6_is_present == PR_TRUE)
-#endif
-            h = GETHOSTBYNAME2(name, AF_INET6); 
-        }
-        if ((NULL == h) && (flags & PR_AI_V4MAPPED)
-        && ((flags & PR_AI_ADDRCONFIG) == 0 || _pr_have_inet_if))
-        {
-            did_af_inet = PR_TRUE;
-            h = GETHOSTBYNAME2(name, AF_INET);
-        }
-    }
-    else
-    {
-        if ((flags & PR_AI_ADDRCONFIG) == 0 || _pr_have_inet_if)
-        {
-            did_af_inet = PR_TRUE;
-            h = GETHOSTBYNAME2(name, af);
-        }
-    }
-#elif defined(_PR_HAVE_GETIPNODEBYNAME)
-    h = getipnodebyname(name, md_af, tmp_flags, &error_num);
-#else
-#error "Unknown name-to-address translation function"
-#endif	/* _PR_HAVE_GETHOSTBYNAME2 */
-#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
-    if (_pr_ipv6_is_present == PR_TRUE)
-    {
-#ifdef PR_GETIPNODE_NOT_THREADSAFE
-        LOCK_DNS();
-#endif
-    	h = (*((_pr_getipnodebyname_t)_pr_getipnodebyname_fp))(name, md_af, tmp_flags, &error_num);
-    }
-    else
-    {
-        LOCK_DNS();
-    	h = GETHOSTBYNAME(name);
-    }
-#else /* _PR_INET6 */
-    LOCK_DNS();
-#ifdef XP_OS2_VACPP
-    h = GETHOSTBYNAME((char *)name);
-#else
-    h = GETHOSTBYNAME(name);
-#endif
-#endif /* _PR_INET6 */
-    
-	if (NULL == h)
-	{
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
-	    PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
-#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
-    	if (_pr_ipv6_is_present == PR_TRUE)
-	    	PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
-		else
-	    	PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
-#else
-	    PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
-#endif
-	}
-	else
-	{
-		_PRIPAddrConversion conversion = _PRIPAddrNoConversion;
-
-		if (af == PR_AF_INET6) conversion = _PRIPAddrIPv4Mapped;
-		rv = CopyHostent(h, &buf, &bufsize, conversion, hp);
-		if (PR_SUCCESS != rv)
-		    PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
-		freehostent(h);
-#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
-    	if (_pr_ipv6_is_present == PR_TRUE)
-			(*((_pr_freehostent_t)_pr_freehostent_fp))(h);
-#endif
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
-		if ((PR_SUCCESS == rv) && (flags & PR_AI_V4MAPPED)
-				&& ((flags & PR_AI_ALL)
-				|| ((flags & PR_AI_ADDRCONFIG) && _pr_have_inet_if))
-				&& !did_af_inet && (h = GETHOSTBYNAME2(name, AF_INET)) != 0) {
-			rv = AppendV4AddrsToHostent(h, &buf, &bufsize, hp);
-			if (PR_SUCCESS != rv)
-				PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
-		}
-#endif
-	}
-
-    /* Must match the convoluted logic above for LOCK_DNS() */
-#ifdef _PR_INET6
-#ifdef _PR_HAVE_GETHOSTBYNAME2
-    UNLOCK_DNS();
-#endif	/* _PR_HAVE_GETHOSTBYNAME2 */
-#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
-#ifdef PR_GETIPNODE_NOT_THREADSAFE
-    UNLOCK_DNS();
-#else
-    if (_pr_ipv6_is_present == PR_FALSE)
-        UNLOCK_DNS();
-#endif
-#else /* _PR_INET6 */
-    UNLOCK_DNS();
-#endif /* _PR_INET6 */
-
-#if defined(_PR_HAVE_GETHOST_R)
-    if (tmpbuf != localbuf)
-        PR_Free(tmpbuf);
-#endif
-
-	return rv;
-}
-
-PR_IMPLEMENT(PRStatus) PR_GetHostByAddr(
-    const PRNetAddr *hostaddr, char *buf, PRIntn bufsize, PRHostEnt *hostentry)
-{
-	struct hostent *h;
-	PRStatus rv = PR_FAILURE;
-	const void *addr;
-	PRUint32 tmp_ip;
-	int addrlen;
-	PRInt32 af;
-#if defined(_PR_HAVE_GETHOST_R)
-    char localbuf[PR_NETDB_BUF_SIZE];
-    char *tmpbuf;
-    struct hostent tmphe;
-    int h_err;
-#endif
-#if defined(_PR_HAVE_GETIPNODEBYADDR)
-	int error_num;
-#endif
-
-    if (!_pr_initialized) _PR_ImplicitInitialization();
-
-	if (hostaddr->raw.family == PR_AF_INET6)
-	{
-#if defined(_PR_INET6_PROBE)
-		if (_pr_ipv6_is_present == PR_TRUE)
-			af = AF_INET6;
-		else
-			af = AF_INET;
-#elif defined(_PR_INET6)
-		af = AF_INET6;
-#else
-		af = AF_INET;
-#endif
-#if defined(_PR_GHBA_DISALLOW_V4MAPPED)
-		if (_PR_IN6_IS_ADDR_V4MAPPED(&hostaddr->ipv6.ip))
-			af = AF_INET;
-#endif
-	}
-	else
-	{
-		PR_ASSERT(hostaddr->raw.family == AF_INET);
-		af = AF_INET;
-	}
-	if (hostaddr->raw.family == PR_AF_INET6) {
-#if defined(_PR_INET6) || defined(_PR_INET6_PROBE)
-		if (af == AF_INET6) {
-			addr = &hostaddr->ipv6.ip;
-			addrlen = sizeof(hostaddr->ipv6.ip);
-		}
-		else
-#endif
-		{
-			PR_ASSERT(af == AF_INET);
-			if (!_PR_IN6_IS_ADDR_V4MAPPED(&hostaddr->ipv6.ip)) {
-				PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-				return rv;
-			}
-			tmp_ip = _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)
-												&hostaddr->ipv6.ip);
-			addr = &tmp_ip;
-			addrlen = sizeof(tmp_ip);
-		}
-	} else {
-		PR_ASSERT(hostaddr->raw.family == AF_INET);
-		PR_ASSERT(af == AF_INET);
-		addr = &hostaddr->inet.ip;
-		addrlen = sizeof(hostaddr->inet.ip);
-	}
-
-#if defined(_PR_HAVE_GETHOST_R)
-    tmpbuf = localbuf;
-    if (bufsize > sizeof(localbuf))
-    {
-        tmpbuf = (char *)PR_Malloc(bufsize);
-        if (NULL == tmpbuf)
-        {
-            PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
-            return rv;
-        }
-    }
-#endif
-
-    /* Do not need to lock the DNS lock if getipnodebyaddr() is called */
-#if defined(_PR_HAVE_GETIPNODEBYADDR) && defined(_PR_INET6)
-	h = getipnodebyaddr(addr, addrlen, af, &error_num);
-#elif defined(_PR_HAVE_GETIPNODEBYADDR) && defined(_PR_INET6_PROBE)
-    if (_pr_ipv6_is_present == PR_TRUE)
-    {
-#ifdef PR_GETIPNODE_NOT_THREADSAFE
-        LOCK_DNS();
-#endif
-    	h = (*((_pr_getipnodebyaddr_t)_pr_getipnodebyaddr_fp))(addr, addrlen,
-				af, &error_num);
-    }
-	else
-    {
-        LOCK_DNS();
-		h = GETHOSTBYADDR(addr, addrlen, af);
-    }
-#else	/* _PR_HAVE_GETIPNODEBYADDR */
-    LOCK_DNS();
-#ifdef XP_OS2_VACPP
-	h = GETHOSTBYADDR((char *)addr, addrlen, af);
-#else
-	h = GETHOSTBYADDR(addr, addrlen, af);
-#endif
-#endif /* _PR_HAVE_GETIPNODEBYADDR */
-	if (NULL == h)
-	{
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYADDR)
-		PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
-#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYADDR)
-    	if (_pr_ipv6_is_present == PR_TRUE)
-	    	PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
-		else
-	    	PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
-#else
-		PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
-#endif
-	}
-	else
-	{
-		_PRIPAddrConversion conversion = _PRIPAddrNoConversion;
-		if (hostaddr->raw.family == PR_AF_INET6) {
-			if (af == AF_INET) {
-				if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr*)
-												&hostaddr->ipv6.ip)) {
-					conversion = _PRIPAddrIPv4Mapped;
-				} else if (_PR_IN6_IS_ADDR_V4COMPAT((PRIPv6Addr *)
-													&hostaddr->ipv6.ip)) {
-					conversion = _PRIPAddrIPv4Compat;
-				}
-			}
-		}
-		rv = CopyHostent(h, &buf, &bufsize, conversion, hostentry);
-		if (PR_SUCCESS != rv) {
-		    PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
-		}
-#if defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYADDR)
-		freehostent(h);
-#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYADDR)
-    	if (_pr_ipv6_is_present == PR_TRUE)
-			(*((_pr_freehostent_t)_pr_freehostent_fp))(h);
-#endif
-	}
-
-    /* Must match the convoluted logic above for LOCK_DNS() */
-#if defined(_PR_HAVE_GETIPNODEBYADDR) && defined(_PR_INET6)
-#elif defined(_PR_HAVE_GETIPNODEBYADDR) && defined(_PR_INET6_PROBE)
-#ifdef PR_GETIPNODE_NOT_THREADSAFE
-    UNLOCK_DNS();
-#else
-    if (_pr_ipv6_is_present == PR_FALSE)
-        UNLOCK_DNS();
-#endif
-#else	/* _PR_HAVE_GETIPNODEBYADDR */
-    UNLOCK_DNS();
-#endif /* _PR_HAVE_GETIPNODEBYADDR */
-
-#if defined(_PR_HAVE_GETHOST_R)
-    if (tmpbuf != localbuf)
-        PR_Free(tmpbuf);
-#endif
-
-	return rv;
-}
-
-/******************************************************************************/
-/*
- * Some systems define a reentrant version of getprotobyname(). Too bad
- * the signature isn't always the same. But hey, they tried. If there
- * is such a definition, use it. Otherwise, grab a lock and do it here.
- */
-/******************************************************************************/
-
-#if !defined(_PR_HAVE_GETPROTO_R)
-/*
- * This may seem like a silly thing to do, but the compiler SHOULD
- * complain if getprotobyname_r() is implemented on some system and
- * we're not using it. For sure these signatures are different than
- * any usable implementation.
- */
-
-static struct protoent *getprotobyname_r(const char* name)
-{
-#ifdef XP_OS2_VACPP
-	return getprotobyname((char *)name);
-#else
-	return getprotobyname(name);
-#endif
-} /* getprotobyname_r */
-
-static struct protoent *getprotobynumber_r(PRInt32 number)
-{
-	return getprotobynumber(number);
-} /* getprotobynumber_r */
-
-#endif /* !defined(_PR_HAVE_GETPROTO_R) */
-
-PR_IMPLEMENT(PRStatus) PR_GetProtoByName(
-    const char* name, char* buffer, PRInt32 buflen, PRProtoEnt* result)
-{
-	PRStatus rv = PR_SUCCESS;
-#if defined(_PR_HAVE_GETPROTO_R)
-	struct protoent* res = (struct protoent*)result;
-#endif
-
-    if (!_pr_initialized) _PR_ImplicitInitialization();
-
-#if defined(_PR_HAVE_GETPROTO_R_INT)
-    {
-        /*
-        ** The protoent_data has a pointer as the first field.
-        ** That implies the buffer better be aligned, and char*
-        ** doesn't promise much.
-        */
-        PRUptrdiff aligned = (PRUptrdiff)buffer;
-        if (0 != (aligned & (sizeof(struct protoent_data*) - 1)))
-        {
-            aligned += sizeof(struct protoent_data*) - 1;
-            aligned &= ~(sizeof(struct protoent_data*) - 1);
-            buflen -= (aligned - (PRUptrdiff)buffer);
-            buffer = (char*)aligned;
-        }
-    }
-#endif  /* defined(_PR_HAVE_GETPROTO_R_INT) */
-
-    if (PR_NETDB_BUF_SIZE > buflen)
-    {
-        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-        return PR_FAILURE;
-    }
-
-#if defined(_PR_HAVE_GETPROTO_R_POINTER)
-    if (NULL == getprotobyname_r(name, res, buffer, buflen))
-    {
-        PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
-        return PR_FAILURE;
-    }
-#elif defined(_PR_HAVE_GETPROTO_R_INT)
-    /*
-    ** The buffer needs to be zero'd, and it should be
-    ** at least the size of a struct protoent_data.
-    */
-    memset(buffer, 0, buflen);
-	if (-1 == getprotobyname_r(name, res, (struct protoent_data*)buffer))
-    {
-        PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
-        return PR_FAILURE;
-    }
-#elif defined(_PR_HAVE_5_ARG_GETPROTO_R)
-    /* The 5th argument for getprotobyname_r() cannot be NULL */
-    if (-1 == getprotobyname_r(name, res, buffer, buflen, &res))
-    {
-        PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
-        return PR_FAILURE;
-    }
-#else  /* do it the hard way */
-	{
-		struct protoent *staticBuf;
-		PR_Lock(_getproto_lock);
-		staticBuf = getprotobyname_r(name);
-		if (NULL == staticBuf)
-		{
-		    rv = PR_FAILURE;
-		    PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
-        }
-		else
-		{
-			rv = CopyProtoent(staticBuf, buffer, buflen, result);
-			if (PR_FAILURE == rv)
-			    PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
-        }
-		PR_Unlock(_getproto_lock);
-	}
-#endif  /* all that */
-    return rv;
-}
-
-PR_IMPLEMENT(PRStatus) PR_GetProtoByNumber(
-    PRInt32 number, char* buffer, PRInt32 buflen, PRProtoEnt* result)
-{
-	PRStatus rv = PR_SUCCESS;
-#if defined(_PR_HAVE_GETPROTO_R)
-	struct protoent* res = (struct protoent*)result;
-#endif
-
-    if (!_pr_initialized) _PR_ImplicitInitialization();
-
-#if defined(_PR_HAVE_GETPROTO_R_INT)
-    {
-        /*
-        ** The protoent_data has a pointer as the first field.
-        ** That implies the buffer better be aligned, and char*
-        ** doesn't promise much.
-        */
-        PRUptrdiff aligned = (PRUptrdiff)buffer;
-        if (0 != (aligned & (sizeof(struct protoent_data*) - 1)))
-        {
-            aligned += sizeof(struct protoent_data*) - 1;
-            aligned &= ~(sizeof(struct protoent_data*) - 1);
-            buflen -= (aligned - (PRUptrdiff)buffer);
-            buffer = (char*)aligned;
-        }
-    }
-#endif /* defined(_PR_HAVE_GETPROTO_R_INT) */
-
-    if (PR_NETDB_BUF_SIZE > buflen)
-    {
-        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-        return PR_FAILURE;
-    }
-
-#if defined(_PR_HAVE_GETPROTO_R_POINTER)
-    if (NULL == getprotobynumber_r(number, res, buffer, buflen))
-    {
-        PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
-        return PR_FAILURE;
-    }
-
-#elif defined(_PR_HAVE_GETPROTO_R_INT)
-    /*
-    ** The buffer needs to be zero'd for these OS's.
-    */
-    memset(buffer, 0, buflen);
-	if (-1 == getprotobynumber_r(number, res, (struct protoent_data*)buffer))
-    {
-        PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
-        return PR_FAILURE;
-    }
-#elif defined(_PR_HAVE_5_ARG_GETPROTO_R)
-    /* The 5th argument for getprotobynumber_r() cannot be NULL */
-    if (-1 == getprotobynumber_r(number, res, buffer, buflen, &res))
-    {
-        PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
-        return PR_FAILURE;
-    }
-#else  /* do it the hard way */
-	{
-		struct protoent *staticBuf;
-		PR_Lock(_getproto_lock);
-		staticBuf = getprotobynumber_r(number);
-		if (NULL == staticBuf)
-		{
-		    rv = PR_FAILURE;
-		    PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
-        }
-		else
-		{
-			rv = CopyProtoent(staticBuf, buffer, buflen, result);
-			if (PR_FAILURE == rv)
-			    PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
-        }
-		PR_Unlock(_getproto_lock);
-	}
-#endif  /* all that crap */
-    return rv;
-
-}
-
-PRUintn _PR_NetAddrSize(const PRNetAddr* addr)
-{
-    PRUintn addrsize;
-
-    /*
-     * RFC 2553 added a new field (sin6_scope_id) to
-     * struct sockaddr_in6.  PRNetAddr's ipv6 member has a
-     * scope_id field to match the new field.  In order to
-     * work with older implementations supporting RFC 2133,
-     * we take the size of struct sockaddr_in6 instead of
-     * addr->ipv6.
-     */
-    if (AF_INET == addr->raw.family)
-        addrsize = sizeof(addr->inet);
-    else if (PR_AF_INET6 == addr->raw.family)
-#if defined(_PR_INET6)
-        addrsize = sizeof(struct sockaddr_in6);
-#else
-        addrsize = sizeof(addr->ipv6);
-#endif
-#if defined(XP_UNIX) || defined(XP_OS2_EMX)
-    else if (AF_UNIX == addr->raw.family)
-        addrsize = sizeof(addr->local);
-#endif
-    else addrsize = 0;
-
-    return addrsize;
-}  /* _PR_NetAddrSize */
-
-PR_IMPLEMENT(PRIntn) PR_EnumerateHostEnt(
-    PRIntn enumIndex, const PRHostEnt *hostEnt, PRUint16 port, PRNetAddr *address)
-{
-    void *addr = hostEnt->h_addr_list[enumIndex++];
-    memset(address, 0, sizeof(PRNetAddr));
-    if (NULL == addr) enumIndex = 0;
-    else
-    {
-        address->raw.family = hostEnt->h_addrtype;
-        if (PR_AF_INET6 == hostEnt->h_addrtype)
-        {
-            address->ipv6.port = htons(port);
-        	address->ipv6.flowinfo = 0;
-        	address->ipv6.scope_id = 0;
-            memcpy(&address->ipv6.ip, addr, hostEnt->h_length);
-        }
-        else
-        {
-            PR_ASSERT(AF_INET == hostEnt->h_addrtype);
-            address->inet.port = htons(port);
-            memcpy(&address->inet.ip, addr, hostEnt->h_length);
-        }
-    }
-    return enumIndex;
-}  /* PR_EnumerateHostEnt */
-
-PR_IMPLEMENT(PRStatus) PR_InitializeNetAddr(
-    PRNetAddrValue val, PRUint16 port, PRNetAddr *addr)
-{
-    PRStatus rv = PR_SUCCESS;
-    if (!_pr_initialized) _PR_ImplicitInitialization();
-
-	if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->inet));
-	addr->inet.family = AF_INET;
-	addr->inet.port = htons(port);
-	switch (val)
-	{
-	case PR_IpAddrNull:
-		break;  /* don't overwrite the address */
-	case PR_IpAddrAny:
-		addr->inet.ip = htonl(INADDR_ANY);
-		break;
-	case PR_IpAddrLoopback:
-		addr->inet.ip = htonl(INADDR_LOOPBACK);
-		break;
-	default:
-		PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-		rv = PR_FAILURE;
-	}
-    return rv;
-}  /* PR_InitializeNetAddr */
-
-PR_IMPLEMENT(PRStatus) PR_SetNetAddr(
-    PRNetAddrValue val, PRUint16 af, PRUint16 port, PRNetAddr *addr)
-{
-    PRStatus rv = PR_SUCCESS;
-    if (!_pr_initialized) _PR_ImplicitInitialization();
-
-    if (af == PR_AF_INET6)
-    {
-        if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->ipv6));
-        addr->ipv6.family = af;
-        addr->ipv6.port = htons(port);
-        addr->ipv6.flowinfo = 0;
-        addr->ipv6.scope_id = 0;
-        switch (val)
-        {
-        case PR_IpAddrNull:
-            break;  /* don't overwrite the address */
-        case PR_IpAddrAny:
-            addr->ipv6.ip = _pr_in6addr_any;
-            break;
-        case PR_IpAddrLoopback:
-            addr->ipv6.ip = _pr_in6addr_loopback;
-            break;
-        default:
-            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-            rv = PR_FAILURE;
-        }
-    }
-    else
-    {
-        if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->inet));
-        addr->inet.family = af;
-        addr->inet.port = htons(port);
-        switch (val)
-        {
-        case PR_IpAddrNull:
-            break;  /* don't overwrite the address */
-        case PR_IpAddrAny:
-            addr->inet.ip = htonl(INADDR_ANY);
-            break;
-        case PR_IpAddrLoopback:
-            addr->inet.ip = htonl(INADDR_LOOPBACK);
-            break;
-        default:
-            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-            rv = PR_FAILURE;
-        }
-    }
-    return rv;
-}  /* PR_SetNetAddr */
-
-PR_IMPLEMENT(PRBool)
-PR_IsNetAddrType(const PRNetAddr *addr, PRNetAddrValue val)
-{
-    if (addr->raw.family == PR_AF_INET6) {
-        if (val == PR_IpAddrAny) {
-			if (_PR_IN6_IS_ADDR_UNSPECIFIED((PRIPv6Addr *)&addr->ipv6.ip)) {
-            	return PR_TRUE;
-			} else if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)
-					&& _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip)
-							== htonl(INADDR_ANY)) {
-            	return PR_TRUE;
-			}
-        } else if (val == PR_IpAddrLoopback) {
-            if (_PR_IN6_IS_ADDR_LOOPBACK((PRIPv6Addr *)&addr->ipv6.ip)) {
-            	return PR_TRUE;
-			} else if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)
-					&& _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip)
-							== htonl(INADDR_LOOPBACK)) {
-            	return PR_TRUE;
-			}
-        } else if (val == PR_IpAddrV4Mapped
-                && _PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)) {
-            return PR_TRUE;
-        }
-    } else {
-        if (addr->raw.family == AF_INET) {
-            if (val == PR_IpAddrAny && addr->inet.ip == htonl(INADDR_ANY)) {
-                return PR_TRUE;
-            } else if (val == PR_IpAddrLoopback
-                    && addr->inet.ip == htonl(INADDR_LOOPBACK)) {
-                return PR_TRUE;
-            }
-        }
-    }
-    return PR_FALSE;
-}
-
-#ifndef _PR_HAVE_INET_NTOP
-#define XX 127
-static const unsigned char index_hex[256] = {
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-     0, 1, 2, 3,  4, 5, 6, 7,  8, 9,XX,XX, XX,XX,XX,XX,
-    XX,10,11,12, 13,14,15,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,10,11,12, 13,14,15,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-    XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
-};
-
-/*
- * StringToV6Addr() returns 1 if the conversion succeeds,
- * or 0 if the input is not a valid IPv6 address string.
- * (Same as inet_pton(AF_INET6, string, addr).)
- */
-static int StringToV6Addr(const char *string, PRIPv6Addr *addr)
-{
-    const unsigned char *s = (const unsigned char *)string;
-    int section = 0;        /* index of the current section (a 16-bit
-                             * piece of the address */
-    int double_colon = -1;  /* index of the section after the first
-                             * 16-bit group of zeros represented by
-                             * the double colon */
-    unsigned int val;
-    int len;
-
-    /* Handle initial (double) colon */
-    if (*s == ':') {
-        if (s[1] != ':') return 0;
-        s += 2;
-        addr->pr_s6_addr16[0] = 0;
-        section = double_colon = 1;
-    }
-
-    while (*s) {
-        if (section == 8) return 0; /* too long */
-        if (*s == ':') {
-            if (double_colon != -1) return 0; /* two double colons */
-            addr->pr_s6_addr16[section++] = 0;
-            double_colon = section;
-            s++;
-            continue;
-        }
-        for (len = val = 0; len < 4 && index_hex[*s] != XX; len++) {
-            val = (val << 4) + index_hex[*s++];
-        }
-        if (*s == '.') {
-            if (len == 0) return 0; /* nothing between : and . */
-            break;
-        }
-        if (*s == ':') {
-            s++;
-            if (!*s) return 0; /* cannot end with single colon */
-        } else if (*s) {
-            return 0; /* bad character */
-        }
-        addr->pr_s6_addr16[section++] = htons((unsigned short)val);
-    }
-    
-    if (*s == '.') {
-        /* Have a trailing v4 format address */
-        if (section > 6) return 0; /* not enough room */
-
-        /*
-         * The number before the '.' is decimal, but we parsed it
-         * as hex.  That means it is in BCD.  Check it for validity
-         * and convert it to binary.
-         */
-        if (val > 0x0255 || (val & 0xf0) > 0x90 || (val & 0xf) > 9) return 0;
-        val = (val >> 8) * 100 + ((val >> 4) & 0xf) * 10 + (val & 0xf);
-        addr->pr_s6_addr[2 * section] = val;
-
-        s++;
-        val = index_hex[*s++];
-        if (val > 9) return 0;
-        while (*s >= '0' && *s <= '9') {
-            val = val * 10 + *s++ - '0';
-            if (val > 255) return 0;
-        }
-        if (*s != '.') return 0; /* must have exactly 4 decimal numbers */
-        addr->pr_s6_addr[2 * section + 1] = val;
-        section++;
-
-        s++;
-        val = index_hex[*s++];
-        if (val > 9) return 0;
-        while (*s >= '0' && *s <= '9') {
-            val = val * 10 + *s++ - '0';
-            if (val > 255) return 0;
-        }
-        if (*s != '.') return 0; /* must have exactly 4 decimal numbers */
-        addr->pr_s6_addr[2 * section] = val;
-
-        s++;
-        val = index_hex[*s++];
-        if (val > 9) return 0;
-        while (*s >= '0' && *s <= '9') {
-            val = val * 10 + *s++ - '0';
-            if (val > 255) return 0;
-        }
-        if (*s) return 0; /* must have exactly 4 decimal numbers */
-        addr->pr_s6_addr[2 * section + 1] = val;
-        section++;
-    }
-    
-    if (double_colon != -1) {
-        /* Stretch the double colon */
-        int tosection;
-        int ncopy = section - double_colon;
-        for (tosection = 7; ncopy--; tosection--) {
-            addr->pr_s6_addr16[tosection] = 
-                addr->pr_s6_addr16[double_colon + ncopy];
-        }
-        while (tosection >= double_colon) {
-            addr->pr_s6_addr16[tosection--] = 0;
-        }
-    } else if (section != 8) {
-        return 0; /* too short */
-    }
-    return 1;
-}
-#undef XX
-            
-static const char *basis_hex = "0123456789abcdef";
-
-/*
- * V6AddrToString() returns a pointer to the buffer containing
- * the text string if the conversion succeeds, and NULL otherwise.
- * (Same as inet_ntop(AF_INET6, addr, buf, size), except that errno
- * is not set on failure.)
- */
-static const char *V6AddrToString(
-    const PRIPv6Addr *addr, char *buf, PRUint32 size)
-{
-#define STUFF(c) do { \
-    if (!size--) return NULL; \
-    *buf++ = (c); \
-} while (0)
-
-    int double_colon = -1;          /* index of the first 16-bit
-                                     * group of zeros represented
-                                     * by the double colon */
-    int double_colon_length = 1;    /* use double colon only if
-                                     * there are two or more 16-bit
-                                     * groups of zeros */
-    int zero_length;
-    int section;
-    unsigned int val;
-    const char *bufcopy = buf;
-
-    /* Scan to find the placement of the double colon */
-    for (section = 0; section < 8; section++) {
-        if (addr->pr_s6_addr16[section] == 0) {
-            zero_length = 1;
-            section++;
-            while (section < 8 && addr->pr_s6_addr16[section] == 0) {
-                zero_length++;
-                section++;
-            }
-            /* Select the longest sequence of zeros */
-            if (zero_length > double_colon_length) {
-                double_colon = section - zero_length;
-                double_colon_length = zero_length;
-            }
-        }
-    }
-
-    /* Now start converting to a string */
-    section = 0;
-
-    if (double_colon == 0) {
-        if (double_colon_length == 6 ||
-            (double_colon_length == 5 && addr->pr_s6_addr16[5] == 0xffff)) {
-            /* ipv4 format address */
-            STUFF(':');
-            STUFF(':');
-            if (double_colon_length == 5) {
-                STUFF('f');
-                STUFF('f');
-                STUFF('f');
-                STUFF('f');
-                STUFF(':');
-            }
-            if (addr->pr_s6_addr[12] > 99) STUFF(addr->pr_s6_addr[12]/100 + '0');
-            if (addr->pr_s6_addr[12] > 9) STUFF((addr->pr_s6_addr[12]%100)/10 + '0');
-            STUFF(addr->pr_s6_addr[12]%10 + '0');
-            STUFF('.');
-            if (addr->pr_s6_addr[13] > 99) STUFF(addr->pr_s6_addr[13]/100 + '0');
-            if (addr->pr_s6_addr[13] > 9) STUFF((addr->pr_s6_addr[13]%100)/10 + '0');
-            STUFF(addr->pr_s6_addr[13]%10 + '0');
-            STUFF('.');
-            if (addr->pr_s6_addr[14] > 99) STUFF(addr->pr_s6_addr[14]/100 + '0');
-            if (addr->pr_s6_addr[14] > 9) STUFF((addr->pr_s6_addr[14]%100)/10 + '0');
-            STUFF(addr->pr_s6_addr[14]%10 + '0');
-            STUFF('.');
-            if (addr->pr_s6_addr[15] > 99) STUFF(addr->pr_s6_addr[15]/100 + '0');
-            if (addr->pr_s6_addr[15] > 9) STUFF((addr->pr_s6_addr[15]%100)/10 + '0');
-            STUFF(addr->pr_s6_addr[15]%10 + '0');
-            STUFF('\0');
-            return bufcopy;
-        }
-    }
-
-    while (section < 8) {
-        if (section == double_colon) {
-            STUFF(':');
-            STUFF(':');
-            section += double_colon_length;
-            continue;
-        }
-        val = ntohs(addr->pr_s6_addr16[section]);
-        if (val > 0xfff) {
-            STUFF(basis_hex[val >> 12]);
-        }
-        if (val > 0xff) {
-            STUFF(basis_hex[(val >> 8) & 0xf]);
-        }
-        if (val > 0xf) {
-            STUFF(basis_hex[(val >> 4) & 0xf]);
-        }
-        STUFF(basis_hex[val & 0xf]);
-        section++;
-        if (section < 8 && section != double_colon) STUFF(':');
-    }
-    STUFF('\0');
-    return bufcopy;
-#undef STUFF    
-}
-
-#endif /* !_PR_HAVE_INET_NTOP */
-
-PR_IMPLEMENT(PRStatus) PR_StringToNetAddr(const char *string, PRNetAddr *addr)
-{
-    PRStatus status = PR_SUCCESS;
-    PRIntn rv;
-
-#if defined(_PR_HAVE_INET_NTOP)
-    rv = inet_pton(AF_INET6, string, &addr->ipv6.ip);
-    if (1 == rv)
-    {
-        addr->raw.family = PR_AF_INET6;
-    }
-    else
-    {
-        PR_ASSERT(0 == rv);
-        /* clean up after the failed inet_pton() call */
-        memset(&addr->ipv6.ip, 0, sizeof(addr->ipv6.ip));
-        rv = inet_pton(AF_INET, string, &addr->inet.ip);
-        if (1 == rv)
-        {
-            addr->raw.family = AF_INET;
-        }
-        else
-        {
-            PR_ASSERT(0 == rv);
-            PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-            status = PR_FAILURE;
-        }
-    }
-#else /* _PR_HAVE_INET_NTOP */
-    rv = StringToV6Addr(string, &addr->ipv6.ip);
-    if (1 == rv) {
-        addr->raw.family = PR_AF_INET6;
-        return PR_SUCCESS;
-    }
-    PR_ASSERT(0 == rv);
-    /* clean up after the failed StringToV6Addr() call */
-    memset(&addr->ipv6.ip, 0, sizeof(addr->ipv6.ip));
-
-    addr->inet.family = AF_INET;
-#ifdef XP_OS2_VACPP
-    addr->inet.ip = inet_addr((char *)string);
-#else
-    addr->inet.ip = inet_addr(string);
-#endif
-    if ((PRUint32) -1 == addr->inet.ip)
-    {
-        /*
-         * The string argument is a malformed address string.
-         */
-        PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-        status = PR_FAILURE;
-    }
-#endif /* _PR_HAVE_INET_NTOP */
-
-    return status;
-}
-
-PR_IMPLEMENT(PRStatus) PR_NetAddrToString(
-    const PRNetAddr *addr, char *string, PRUint32 size)
-{
-    if (PR_AF_INET6 == addr->raw.family)
-    {
-#if defined(_PR_HAVE_INET_NTOP)
-        if (NULL == inet_ntop(AF_INET6, &addr->ipv6.ip, string, size))
-#else
-        if (NULL == V6AddrToString(&addr->ipv6.ip, string, size))
-#endif
-        {
-            /* the size of the result buffer is inadequate */
-            PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0);
-            return PR_FAILURE;
-        }
-    }
-    else
-    {
-        if (size < 16) goto failed;
-        if (AF_INET != addr->raw.family) goto failed;
-        else
-        {
-            unsigned char *byte = (unsigned char*)&addr->inet.ip;
-            PR_snprintf(string, size, "%u.%u.%u.%u",
-                byte[0], byte[1], byte[2], byte[3]);
-        }
-    }
-
-    return PR_SUCCESS;
-
-failed:
-    PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
-    return PR_FAILURE;
-
-}  /* PR_NetAddrToString */
-
-/*
- * Convert an IPv4 addr to an (IPv4-mapped) IPv6 addr
- */
-PR_IMPLEMENT(void) PR_ConvertIPv4AddrToIPv6(PRUint32 v4addr, PRIPv6Addr *v6addr)
-{
-    PRUint8 *dstp;
-    dstp = v6addr->pr_s6_addr;
-    memset(dstp, 0, 10);
-    memset(dstp + 10, 0xff, 2);
-    memcpy(dstp + 12,(char *) &v4addr, 4);
-}
-
-PR_IMPLEMENT(PRUint16) PR_ntohs(PRUint16 n) { return ntohs(n); }
-PR_IMPLEMENT(PRUint32) PR_ntohl(PRUint32 n) { return ntohl(n); }
-PR_IMPLEMENT(PRUint16) PR_htons(PRUint16 n) { return htons(n); }
-PR_IMPLEMENT(PRUint32) PR_htonl(PRUint32 n) { return htonl(n); }
-PR_IMPLEMENT(PRUint64) PR_ntohll(PRUint64 n)
-{
-#ifdef IS_BIG_ENDIAN
-    return n;
-#else
-    PRUint64 tmp;
-    PRUint32 hi, lo;
-    LL_L2UI(lo, n);
-    LL_SHR(tmp, n, 32);
-    LL_L2UI(hi, tmp);
-    hi = PR_ntohl(hi);
-    lo = PR_ntohl(lo);
-    LL_UI2L(n, lo);
-    LL_SHL(n, n, 32);
-    LL_UI2L(tmp, hi);
-    LL_ADD(n, n, tmp);
-    return n;
-#endif
-}  /* ntohll */
-
-PR_IMPLEMENT(PRUint64) PR_htonll(PRUint64 n)
-{
-#ifdef IS_BIG_ENDIAN
-    return n;
-#else
-    PRUint64 tmp;
-    PRUint32 hi, lo;
-    LL_L2UI(lo, n);
-    LL_SHR(tmp, n, 32);
-    LL_L2UI(hi, tmp);
-    hi = htonl(hi);
-    lo = htonl(lo);
-    LL_UI2L(n, lo);
-    LL_SHL(n, n, 32);
-    LL_UI2L(tmp, hi);
-    LL_ADD(n, n, tmp);
-    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;
-    PRBool    has_cname;
-} 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;
-    }
-    ai->has_cname = !(flags & PR_AI_NOCANONNAME);
-
-    return (PRAddrInfo *) ai;
-}
-
-PR_IMPLEMENT(PRAddrInfo *) PR_GetAddrInfoByName(const char  *hostname,
-                                                PRUint16     af,
-                                                PRIntn       flags)
-{
-    /* restrict input to supported values */
-    if ((af != PR_AF_INET && af != PR_AF_UNSPEC) ||
-        (flags & ~ PR_AI_NOCANONNAME) != 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 = (flags & PR_AI_NOCANONNAME) ? 0: AI_CANONNAME;
-        hints.ai_family = (af == PR_AF_INET) ? AF_INET : AF_UNSPEC;
-
-        /*
-         * it is important to select a socket type in the hints, otherwise we
-         * will get back repetitive entries: one for each socket type.  since
-         * we do not expose ai_socktype through our API, it is okay to do this
-         * here.  the application may still choose to create a socket of some
-         * other type.
-         */
-        hints.ai_socktype = SOCK_STREAM;
-
-        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)(uintptr_t)iterPtr;
-        iter = PR_EnumerateHostEnt(iter, &((PRAddrInfoFB *) base)->hostent, port, result);
-        if (iter < 0)
-            iter = 0;
-        return (void *)(uintptr_t)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);
-        result->raw.family = ai->ai_addr->sa_family;
-        if (ai->ai_addrlen < sizeof(PRNetAddr))
-            memset(((char*)result)+ai->ai_addrlen, 0, sizeof(PRNetAddr) - ai->ai_addrlen);
-
-        if (result->raw.family == PR_AF_INET)
-            result->inet.port = htons(port);
-        else
-            result->ipv6.port = 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) {
-        const PRAddrInfoFB *fb = (const PRAddrInfoFB *) ai;
-        return fb->has_cname ? fb->hostent.h_name : NULL;
-    } 
-#endif
-    return ((const PRADDRINFO *) ai)->ai_canonname;
-#else
-    const PRAddrInfoFB *fb = (const PRAddrInfoFB *) ai;
-    return fb->has_cname ? fb->hostent.h_name : NULL;
-#endif
-}
Index: trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptio.c
===================================================================
--- trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptio.c	(revision 101792)
+++ trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptio.c	(revision 101793)
@@ -336,25 +336,7 @@
         PRSize amount;                      /* #3 - size of 'buffer', or */
         pt_SockLen *addr_len;                  /*    - length of address */
-#ifdef HPUX11
-        /*
-         * For sendfile()
-         */
-		struct file_spec {
-        	off_t offset;                       /* offset in file to send */
-        	size_t nbytes;                      /* length of file data to send */
-        	size_t st_size;                     /* file size */
-		} file_spec;
-#endif
     } arg3;
     union { PRIntn flags; } arg4;           /* #4 - read/write flags */
     union { PRNetAddr *addr; } arg5;        /* #5 - send/recv address */
-
-#ifdef HPUX11
-    /*
-     * For sendfile()
-     */
-    int filedesc;                           /* descriptor of file to send */
-    int nbytes_to_send;                     /* size of header and file */
-#endif  /* HPUX11 */
 
 #ifdef SOLARIS
@@ -970,107 +952,4 @@
 }  /* pt_recvfrom_cont */
 
-#ifdef AIX
-static PRBool pt_aix_sendfile_cont(pt_Continuation *op, PRInt16 revents)
-{
-    struct sf_parms *sf_struct = (struct sf_parms *) op->arg2.buffer;
-    ssize_t rv;
-	unsigned long long saved_file_offset;
-	long long saved_file_bytes;
-
-	saved_file_offset = sf_struct->file_offset;
-	saved_file_bytes = sf_struct->file_bytes;
-	sf_struct->bytes_sent = 0;
-
-	if ((sf_struct->file_bytes > 0) && (sf_struct->file_size > 0))
-	PR_ASSERT((sf_struct->file_bytes + sf_struct->file_offset) <=
-									sf_struct->file_size);
-    rv = AIX_SEND_FILE(&op->arg1.osfd, sf_struct, op->arg4.flags);
-    op->syserrno = errno;
-
-    if (rv != -1) {
-        op->result.code += sf_struct->bytes_sent;
-		/*
-		 * A bug in AIX 4.3.2 prevents the 'file_bytes' field from
-		 * being updated. So, 'file_bytes' is maintained by NSPR to
-		 * avoid conflict when this bug is fixed in AIX, in the future.
-		 */
-		if (saved_file_bytes != -1)
-			saved_file_bytes -= (sf_struct->file_offset - saved_file_offset);
-		sf_struct->file_bytes = saved_file_bytes;
-    } else if (op->syserrno != EWOULDBLOCK && op->syserrno != EAGAIN) {
-        op->result.code = -1;
-    } else {
-        return PR_FALSE;
-    }
-
-    if (rv == 1) {    /* more data to send */
-        return PR_FALSE;
-    }
-
-    return PR_TRUE;
-}
-#endif  /* AIX */
-
-#ifdef HPUX11
-static PRBool pt_hpux_sendfile_cont(pt_Continuation *op, PRInt16 revents)
-{
-    struct iovec *hdtrl = (struct iovec *) op->arg2.buffer;
-    int count;
-
-    count = sendfile(op->arg1.osfd, op->filedesc, op->arg3.file_spec.offset,
-			op->arg3.file_spec.nbytes, hdtrl, op->arg4.flags);
-    PR_ASSERT(count <= op->nbytes_to_send);
-    op->syserrno = errno;
-
-    if (count != -1) {
-        op->result.code += count;
-    } else if (op->syserrno != EWOULDBLOCK && op->syserrno != EAGAIN) {
-        op->result.code = -1;
-    } else {
-        return PR_FALSE;
-    }
-    if (count != -1 && count < op->nbytes_to_send) {
-        if (count < hdtrl[0].iov_len) {
-			/* header not sent */
-
-            hdtrl[0].iov_base = ((char *) hdtrl[0].iov_len) + count;
-            hdtrl[0].iov_len -= count;
-
-        } else if (count < (hdtrl[0].iov_len + op->arg3.file_spec.nbytes)) {
-			/* header sent, file not sent */
-            PRUint32 file_nbytes_sent = count - hdtrl[0].iov_len;
-
-            hdtrl[0].iov_base = NULL;
-            hdtrl[0].iov_len = 0;
-
-            op->arg3.file_spec.offset += file_nbytes_sent;
-            op->arg3.file_spec.nbytes -= file_nbytes_sent;
-        } else if (count < (hdtrl[0].iov_len + op->arg3.file_spec.nbytes +
-											hdtrl[1].iov_len)) {
-            PRUint32 trailer_nbytes_sent = count - (hdtrl[0].iov_len +
-                                         op->arg3.file_spec.nbytes);
-
-			/* header sent, file sent, trailer not sent */
-
-            hdtrl[0].iov_base = NULL;
-            hdtrl[0].iov_len = 0;
-			/*
-			 * set file offset and len so that no more file data is
-			 * sent
-			 */
-            op->arg3.file_spec.offset = op->arg3.file_spec.st_size;
-            op->arg3.file_spec.nbytes = 0;
-
-            hdtrl[1].iov_base =((char *) hdtrl[1].iov_base)+ trailer_nbytes_sent;
-            hdtrl[1].iov_len -= trailer_nbytes_sent;
-		}
-        op->nbytes_to_send -= count;
-        return PR_FALSE;
-    }
-
-    return PR_TRUE;
-}
-#endif  /* HPUX11 */
-
 #ifdef SOLARIS
 static PRBool pt_solaris_sendfile_cont(pt_Continuation *op, PRInt16 revents)
@@ -1567,5 +1446,5 @@
     pt_SockLen addr_len;
 	const PRNetAddr *addrp = addr;
-#if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)
+#if defined(_PR_HAVE_SOCKADDR_LEN)
 	PRUint16 md_af = addr->raw.family;
     PRNetAddr addrCopy;
@@ -1576,14 +1455,4 @@
     PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
     addr_len = PR_NETADDR_SIZE(addr);
-#if defined(_PR_INET6)
-	if (addr->raw.family == PR_AF_INET6) {
-		md_af = AF_INET6;
-#ifndef _PR_HAVE_SOCKADDR_LEN
-		addrCopy = *addr;
-		addrCopy.raw.family = AF_INET6;
-		addrp = &addrCopy;
-#endif
-	}
-#endif
 
 #ifdef _PR_HAVE_SOCKADDR_LEN
@@ -1721,8 +1590,4 @@
     }
 #endif /* _PR_HAVE_SOCKADDR_LEN */
-#ifdef _PR_INET6
-	if (addr && (AF_INET6 == addr->raw.family))
-        addr->raw.family = PR_AF_INET6;
-#endif
     newfd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP, PR_TRUE, PR_FALSE);
     if (newfd == NULL) close(osfd);  /* $$$ whoops! this doesn't work $$$ */
@@ -1752,5 +1617,5 @@
     pt_SockLen addr_len;
 	const PRNetAddr *addrp = addr;
-#if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)
+#if defined(_PR_HAVE_SOCKADDR_LEN)
 	PRUint16 md_af = addr->raw.family;
     PRNetAddr addrCopy;
@@ -1769,15 +1634,4 @@
         }
     }
-
-#if defined(_PR_INET6)
-	if (addr->raw.family == PR_AF_INET6) {
-		md_af = AF_INET6;
-#ifndef _PR_HAVE_SOCKADDR_LEN
-		addrCopy = *addr;
-		addrCopy.raw.family = AF_INET6;
-		addrp = &addrCopy;
-#endif
-	}
-#endif
 
     addr_len = PR_NETADDR_SIZE(addr);
@@ -1992,378 +1846,4 @@
     return pt_Send(fd, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT);
 }  /* pt_SocketWrite */
-
-static PRInt32 pt_SendTo(
-    PRFileDesc *fd, const void *buf,
-    PRInt32 amount, PRIntn flags, const PRNetAddr *addr,
-    PRIntervalTime timeout)
-{
-    PRInt32 syserrno, bytes = -1;
-    PRBool fNeedContinue = PR_FALSE;
-    pt_SockLen addr_len;
-	const PRNetAddr *addrp = addr;
-#if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)
-	PRUint16 md_af = addr->raw.family;
-    PRNetAddr addrCopy;
-#endif
-
-    if (pt_TestAbort()) return bytes;
-
-    PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
-#if defined(_PR_INET6)
-	if (addr->raw.family == PR_AF_INET6) {
-		md_af = AF_INET6;
-#ifndef _PR_HAVE_SOCKADDR_LEN
-		addrCopy = *addr;
-		addrCopy.raw.family = AF_INET6;
-		addrp = &addrCopy;
-#endif
-	}
-#endif
-
-    addr_len = PR_NETADDR_SIZE(addr);
-#ifdef _PR_HAVE_SOCKADDR_LEN
-    addrCopy = *addr;
-    ((struct sockaddr*)&addrCopy)->sa_len = addr_len;
-    ((struct sockaddr*)&addrCopy)->sa_family = md_af;
-    bytes = sendto(
-        fd->secret->md.osfd, buf, amount, flags,
-        (struct sockaddr*)&addrCopy, addr_len);
-#else
-    bytes = sendto(
-        fd->secret->md.osfd, buf, amount, flags,
-        (struct sockaddr*)addrp, addr_len);
-#endif
-    syserrno = errno;
-    if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)
-        && (!fd->secret->nonblocking) )
-    {
-        if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
-        else fNeedContinue = PR_TRUE;
-    }
-    if (fNeedContinue == PR_TRUE)
-    {
-        pt_Continuation op;
-        op.arg1.osfd = fd->secret->md.osfd;
-        op.arg2.buffer = (void*)buf;
-        op.arg3.amount = amount;
-        op.arg4.flags = flags;
-#ifdef _PR_HAVE_SOCKADDR_LEN
-        op.arg5.addr = (PRNetAddr*)&addrCopy;
-#else
-        op.arg5.addr = (PRNetAddr*)addr;
-#endif
-        op.timeout = timeout;
-        op.result.code = 0;  /* initialize the number sent */
-        op.function = pt_sendto_cont;
-        op.event = POLLOUT | POLLPRI;
-        bytes = pt_Continue(&op);
-        syserrno = op.syserrno;
-    }
-    if (bytes < 0)
-        pt_MapError(_PR_MD_MAP_SENDTO_ERROR, syserrno);
-    return bytes;
-}  /* pt_SendTo */
-
-static PRInt32 pt_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount,
-    PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
-{
-    PRBool fNeedContinue = PR_FALSE;
-    PRInt32 syserrno, bytes = -1;
-    pt_SockLen addr_len = sizeof(PRNetAddr);
-
-    if (pt_TestAbort()) return bytes;
-
-    bytes = recvfrom(
-        fd->secret->md.osfd, buf, amount, flags,
-        (struct sockaddr*)addr, &addr_len);
-    syserrno = errno;
-
-    if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)
-        && (!fd->secret->nonblocking) )
-    {
-        if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
-        else fNeedContinue = PR_TRUE;
-    }
-
-    if (fNeedContinue == PR_TRUE)
-    {
-        pt_Continuation op;
-        op.arg1.osfd = fd->secret->md.osfd;
-        op.arg2.buffer = buf;
-        op.arg3.amount = amount;
-        op.arg4.flags = flags;
-        op.arg5.addr = addr;
-        op.timeout = timeout;
-        op.function = pt_recvfrom_cont;
-        op.event = POLLIN | POLLPRI;
-        bytes = pt_Continue(&op);
-        syserrno = op.syserrno;
-    }
-#ifdef _PR_HAVE_SOCKADDR_LEN
-    if (bytes >= 0)
-    {
-        /* ignore the sa_len field of struct sockaddr */
-        if (addr)
-        {
-            addr->raw.family = ((struct sockaddr*)addr)->sa_family;
-        }
-    }
-#endif /* _PR_HAVE_SOCKADDR_LEN */
-#ifdef _PR_INET6
-	if (addr && (AF_INET6 == addr->raw.family))
-        addr->raw.family = PR_AF_INET6;
-#endif
-    if (bytes < 0)
-        pt_MapError(_PR_MD_MAP_RECVFROM_ERROR, syserrno);
-    return bytes;
-}  /* pt_RecvFrom */
-
-#ifdef AIX
-#ifndef HAVE_SEND_FILE
-static pthread_once_t pt_aix_sendfile_once_block = PTHREAD_ONCE_INIT;
-
-static void pt_aix_sendfile_init_routine(void)
-{
-    void *handle = dlopen(NULL, RTLD_NOW | RTLD_GLOBAL);
-    pt_aix_sendfile_fptr = (ssize_t (*)()) dlsym(handle, "send_file");
-    dlclose(handle);
-}
-
-/*
- * pt_AIXDispatchSendFile
- */
-static PRInt32 pt_AIXDispatchSendFile(PRFileDesc *sd, PRSendFileData *sfd,
-	  PRTransmitFileFlags flags, PRIntervalTime timeout)
-{
-    int rv;
-
-    rv = pthread_once(&pt_aix_sendfile_once_block,
-            pt_aix_sendfile_init_routine);
-    PR_ASSERT(0 == rv);
-    if (pt_aix_sendfile_fptr) {
-        return pt_AIXSendFile(sd, sfd, flags, timeout);
-    } else {
-        return PR_EmulateSendFile(sd, sfd, flags, timeout);
-    }
-}
-#endif /* !HAVE_SEND_FILE */
-
-
-/*
- * pt_AIXSendFile
- *
- *    Send file sfd->fd across socket sd. If specified, header and trailer
- *    buffers are sent before and after the file, respectively.
- *
- *    PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file
- *
- *    return number of bytes sent or -1 on error
- *
- *      This implementation takes advantage of the send_file() system
- *      call available in AIX 4.3.2.
- */
-
-static PRInt32 pt_AIXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
-		PRTransmitFileFlags flags, PRIntervalTime timeout)
-{
-    struct sf_parms sf_struct;
-    uint_t send_flags;
-    ssize_t rv;
-    int syserrno;
-    PRInt32 count;
-	unsigned long long saved_file_offset;
-	long long saved_file_bytes;
-
-    sf_struct.header_data = (void *) sfd->header;  /* cast away the 'const' */
-    sf_struct.header_length = sfd->hlen;
-    sf_struct.file_descriptor = sfd->fd->secret->md.osfd;
-    sf_struct.file_size = 0;
-    sf_struct.file_offset = sfd->file_offset;
-    if (sfd->file_nbytes == 0)
-    	sf_struct.file_bytes = -1;
-	else
-    	sf_struct.file_bytes = sfd->file_nbytes;
-    sf_struct.trailer_data = (void *) sfd->trailer;
-    sf_struct.trailer_length = sfd->tlen;
-    sf_struct.bytes_sent = 0;
-
-	saved_file_offset = sf_struct.file_offset;
-    saved_file_bytes = sf_struct.file_bytes;
-
-    send_flags = 0;			/* flags processed at the end */
-
-    /* The first argument to send_file() is int*. */
-    PR_ASSERT(sizeof(int) == sizeof(sd->secret->md.osfd));
-    do {
-        rv = AIX_SEND_FILE(&sd->secret->md.osfd, &sf_struct, send_flags);
-    } while (rv == -1 && (syserrno = errno) == EINTR);
-
-    if (rv == -1) {
-        if (syserrno == EAGAIN || syserrno == EWOULDBLOCK) {
-            count = 0; /* Not a real error.  Need to continue. */
-        } else {
-            count = -1;
-        }
-    } else {
-        count = sf_struct.bytes_sent;
-		/*
-		 * A bug in AIX 4.3.2 prevents the 'file_bytes' field from
-		 * being updated. So, 'file_bytes' is maintained by NSPR to
-		 * avoid conflict when this bug is fixed in AIX, in the future.
-		 */
-		if (saved_file_bytes != -1)
-			saved_file_bytes -= (sf_struct.file_offset - saved_file_offset);
-		sf_struct.file_bytes = saved_file_bytes;
-    }
-
-    if ((rv == 1) || ((rv == -1) && (count == 0))) {
-        pt_Continuation op;
-
-        op.arg1.osfd = sd->secret->md.osfd;
-        op.arg2.buffer = &sf_struct;
-        op.arg4.flags = send_flags;
-        op.result.code = count;
-        op.timeout = timeout;
-        op.function = pt_aix_sendfile_cont;
-        op.event = POLLOUT | POLLPRI;
-        count = pt_Continue(&op);
-        syserrno = op.syserrno;
-    }
-
-    if (count == -1) {
-        pt_MapError(_MD_aix_map_sendfile_error, syserrno);
-        return -1;
-    }
-    if (flags & PR_TRANSMITFILE_CLOSE_SOCKET) {
-        PR_Close(sd);
-    }
-	PR_ASSERT(count == (sfd->hlen + sfd->tlen +
-						((sfd->file_nbytes ==  0) ?
-						sf_struct.file_size - sfd->file_offset :
-						sfd->file_nbytes)));
-    return count;
-}
-#endif /* AIX */
-
-#ifdef HPUX11
-/*
- * pt_HPUXSendFile
- *
- *    Send file sfd->fd across socket sd. If specified, header and trailer
- *    buffers are sent before and after the file, respectively.
- *
- *    PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file
- *
- *    return number of bytes sent or -1 on error
- *
- *      This implementation takes advantage of the sendfile() system
- *      call available in HP-UX B.11.00.
- */
-
-static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
-		PRTransmitFileFlags flags, PRIntervalTime timeout)
-{
-    struct stat statbuf;
-    size_t nbytes_to_send, file_nbytes_to_send;
-    struct iovec hdtrl[2];  /* optional header and trailer buffers */
-    int send_flags;
-    PRInt32 count;
-    int syserrno;
-
-    if (sfd->file_nbytes == 0) {
-        /* Get file size */
-        if (fstat(sfd->fd->secret->md.osfd, &statbuf) == -1) {
-            _PR_MD_MAP_FSTAT_ERROR(errno);
-            return -1;
-        }
-        file_nbytes_to_send = statbuf.st_size - sfd->file_offset;
-    } else {
-        file_nbytes_to_send = sfd->file_nbytes;
-    }
-    nbytes_to_send = sfd->hlen + sfd->tlen + file_nbytes_to_send;
-
-    hdtrl[0].iov_base = (void *) sfd->header;  /* cast away the 'const' */
-    hdtrl[0].iov_len = sfd->hlen;
-    hdtrl[1].iov_base = (void *) sfd->trailer;
-    hdtrl[1].iov_len = sfd->tlen;
-    /*
-     * SF_DISCONNECT seems to close the socket even if sendfile()
-     * only does a partial send on a nonblocking socket.  This
-     * would prevent the subsequent sendfile() calls on that socket
-     * from working.  So we don't use the SD_DISCONNECT flag.
-     */
-    send_flags = 0;
-
-    do {
-        count = sendfile(sd->secret->md.osfd, sfd->fd->secret->md.osfd,
-                sfd->file_offset, file_nbytes_to_send, hdtrl, send_flags);
-    } while (count == -1 && (syserrno = errno) == EINTR);
-
-    if (count == -1 && (syserrno == EAGAIN || syserrno == EWOULDBLOCK)) {
-        count = 0;
-    }
-    if (count != -1 && count < nbytes_to_send) {
-        pt_Continuation op;
-
-        if (count < sfd->hlen) {
-			/* header not sent */
-
-            hdtrl[0].iov_base = ((char *) sfd->header) + count;
-            hdtrl[0].iov_len = sfd->hlen - count;
-            op.arg3.file_spec.offset = sfd->file_offset;
-            op.arg3.file_spec.nbytes = file_nbytes_to_send;
-        } else if (count < (sfd->hlen + file_nbytes_to_send)) {
-			/* header sent, file not sent */
-
-            hdtrl[0].iov_base = NULL;
-            hdtrl[0].iov_len = 0;
-
-            op.arg3.file_spec.offset = sfd->file_offset + count - sfd->hlen;
-            op.arg3.file_spec.nbytes = file_nbytes_to_send - (count - sfd->hlen);
-        } else if (count < (sfd->hlen + file_nbytes_to_send + sfd->tlen)) {
-			PRUint32 trailer_nbytes_sent;
-
-			/* header sent, file sent, trailer not sent */
-
-            hdtrl[0].iov_base = NULL;
-            hdtrl[0].iov_len = 0;
-			/*
-			 * set file offset and len so that no more file data is
-			 * sent
-			 */
-            op.arg3.file_spec.offset = statbuf.st_size;
-            op.arg3.file_spec.nbytes = 0;
-
-			trailer_nbytes_sent = count - sfd->hlen - file_nbytes_to_send;
-            hdtrl[1].iov_base = ((char *) sfd->trailer) + trailer_nbytes_sent;
-            hdtrl[1].iov_len = sfd->tlen - trailer_nbytes_sent;
-		}
-
-        op.arg1.osfd = sd->secret->md.osfd;
-        op.filedesc = sfd->fd->secret->md.osfd;
-        op.arg2.buffer = hdtrl;
-        op.arg3.file_spec.st_size = statbuf.st_size;
-        op.arg4.flags = send_flags;
-        op.nbytes_to_send = nbytes_to_send - count;
-        op.result.code = count;
-        op.timeout = timeout;
-        op.function = pt_hpux_sendfile_cont;
-        op.event = POLLOUT | POLLPRI;
-        count = pt_Continue(&op);
-        syserrno = op.syserrno;
-    }
-
-    if (count == -1) {
-        pt_MapError(_MD_hpux_map_sendfile_error, syserrno);
-        return -1;
-    }
-    if (flags & PR_TRANSMITFILE_CLOSE_SOCKET) {
-        PR_Close(sd);
-    }
-    PR_ASSERT(count == nbytes_to_send);
-    return count;
-}
-
-#endif  /* HPUX11 */
 
 #ifdef SOLARIS
@@ -2686,8 +2166,4 @@
 #endif  /* LINUX */
 
-#ifdef AIX
-extern	int _pr_aix_send_file_use_disabled;
-#endif
-
 static PRInt32 pt_SendFile(
     PRFileDesc *sd, PRSendFileData *sfd,
@@ -2701,24 +2177,5 @@
         return -1;
     }
-#ifdef HPUX11
-    return(pt_HPUXSendFile(sd, sfd, flags, timeout));
-#elif defined(AIX)
-#ifdef HAVE_SEND_FILE
-	/*
-	 * A bug in AIX 4.3.2 results in corruption of data transferred by
-	 * send_file(); AIX patch PTF U463956 contains the fix.  A user can
-	 * disable the use of send_file function in NSPR, when this patch is
-	 * not installed on the system, by setting the envionment variable
-	 * NSPR_AIX_SEND_FILE_USE_DISABLED to 1.
-	 */
-	if (_pr_aix_send_file_use_disabled)
-		return(PR_EmulateSendFile(sd, sfd, flags, timeout));
-	else
-    	return(pt_AIXSendFile(sd, sfd, flags, timeout));
-#else
-	return(PR_EmulateSendFile(sd, sfd, flags, timeout));
-    /* return(pt_AIXDispatchSendFile(sd, sfd, flags, timeout));*/
-#endif /* HAVE_SEND_FILE */
-#elif defined(SOLARIS)
+#if defined(SOLARIS)
 #ifdef HAVE_SENDFILEV
     	return(pt_SolarisSendFile(sd, sfd, flags, timeout));
@@ -2788,8 +2245,5 @@
         }
 #endif /* _PR_HAVE_SOCKADDR_LEN */
-#ifdef _PR_INET6
-		if (AF_INET6 == addr->raw.family)
-			addr->raw.family = PR_AF_INET6;
-#endif
+
         PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
         PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE);
@@ -2819,8 +2273,5 @@
         }
 #endif /* _PR_HAVE_SOCKADDR_LEN */
-#ifdef _PR_INET6
-		if (AF_INET6 == addr->raw.family)
-        	addr->raw.family = PR_AF_INET6;
-#endif
+
         PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
         PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE);
@@ -3184,43 +2635,4 @@
 };
 
-static PRIOMethods _pr_udp_methods = {
-    PR_DESC_SOCKET_UDP,
-    pt_Close,
-    pt_SocketRead,
-    pt_SocketWrite,
-    pt_Available_s,
-    pt_Available64_s,
-    pt_Synch,
-    (PRSeekFN)_PR_InvalidInt,
-    (PRSeek64FN)_PR_InvalidInt64,
-    (PRFileInfoFN)_PR_InvalidStatus,
-    (PRFileInfo64FN)_PR_InvalidStatus,
-    pt_Writev,
-    pt_Connect,
-    (PRAcceptFN)_PR_InvalidDesc,
-    pt_Bind,
-    pt_Listen,
-    pt_Shutdown,
-    pt_Recv,
-    pt_Send,
-    pt_RecvFrom,
-    pt_SendTo,
-    pt_Poll,
-    (PRAcceptreadFN)_PR_InvalidInt,
-    (PRTransmitfileFN)_PR_InvalidInt,
-    pt_GetSockName,
-    pt_GetPeerName,
-    (PRReservedFN)_PR_InvalidInt,
-    (PRReservedFN)_PR_InvalidInt,
-    pt_GetSocketOption,
-    pt_SetSocketOption,
-    (PRSendfileFN)_PR_InvalidInt,
-    (PRConnectcontinueFN)_PR_InvalidStatus,
-    (PRReservedFN)_PR_InvalidInt,
-    (PRReservedFN)_PR_InvalidInt,
-    (PRReservedFN)_PR_InvalidInt,
-    (PRReservedFN)_PR_InvalidInt
-};
-
 static PRIOMethods _pr_socketpollfd_methods = {
     (PRDescType) 0,
@@ -3337,8 +2749,4 @@
 #endif
                 break;
-            case PR_DESC_SOCKET_UDP:
-                fd->methods = PR_GetUDPMethods();
-                pt_MakeFdNonblock(osfd);
-                break;
             case PR_DESC_PIPE:
                 fd->methods = PR_GetPipeMethods();
@@ -3367,9 +2775,4 @@
 }  /* PR_GetTCPMethods */
 
-PR_IMPLEMENT(const PRIOMethods*) PR_GetUDPMethods(void)
-{
-    return &_pr_udp_methods;
-}  /* PR_GetUDPMethods */
-
 static const PRIOMethods* PR_GetSocketPollFdMethods(void)
 {
@@ -3402,38 +2805,17 @@
 }  /* PR_AllocFileDesc */
 
-#if !defined(_PR_INET6) || defined(_PR_INET6_PROBE)
-PR_EXTERN(PRStatus) _pr_push_ipv6toipv4_layer(PRFileDesc *fd);
-#if defined(_PR_INET6_PROBE)
-PR_EXTERN(PRBool) _pr_ipv6_is_present;
-PR_IMPLEMENT(PRBool) _pr_test_ipv6_socket()
-{
-PRInt32 osfd;
-
-#if defined(DARWIN)
-    /*
-     * Disable IPv6 if Darwin version is less than 7.0.0 (OS X 10.3).  IPv6 on
-     * lesser versions is not ready for general use (see bug 222031).
-     */
-    {
-        struct utsname u;
-        if (uname(&u) != 0 || atoi(u.release) < 7)
-            return PR_FALSE;
-    }
-#endif
-
-    /*
-     * HP-UX only: HP-UX IPv6 Porting Guide (dated February 2001)
-     * suggests that we call open("/dev/ip6", O_RDWR) to determine
-     * whether IPv6 APIs and the IPv6 stack are on the system.
-     * Our portable test below seems to work fine, so I am using it.
-     */
-    osfd = socket(AF_INET6, SOCK_STREAM, 0);
-    if (osfd != -1) {
-        close(osfd);
-        return PR_TRUE;
-    }
-    return PR_FALSE;
-}
-#endif	/* _PR_INET6_PROBE */
+#ifdef VBOX
+PRUintn _PR_NetAddrSize(const PRNetAddr* addr)
+{
+    PRUintn addrsize;
+
+#if defined(XP_UNIX) || defined(XP_OS2_EMX)
+    if (AF_UNIX == addr->raw.family)
+        addrsize = sizeof(addr->local);
+#endif
+    else addrsize = 0;
+
+    return addrsize;
+}  /* _PR_NetAddrSize */
 #endif
 
@@ -3449,7 +2831,5 @@
     if (pt_TestAbort()) return NULL;
 
-    if (PF_INET != domain
-        && PR_AF_INET6 != domain
-        && PF_UNIX != domain)
+    if (PF_UNIX != domain)
     {
         PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
@@ -3463,18 +2843,4 @@
 		return fd;
 	}
-#if defined(_PR_INET6_PROBE)
-	if (PR_AF_INET6 == domain) {
-		if (_pr_ipv6_is_present == PR_FALSE)
-			domain = AF_INET;
-		else
-			domain = AF_INET6;
-	}
-#elif defined(_PR_INET6)
-	if (PR_AF_INET6 == domain)
-		domain = AF_INET6;
-#else
-	if (PR_AF_INET6 == domain)
-		domain = AF_INET;
-#endif
 
     osfd = socket(domain, type, proto);
@@ -3482,12 +2848,4 @@
     else
     {
-#ifdef DARWIN
-        if ((domain == AF_INET6) && _pr_ipv6_v6only_on_by_default)
-        {
-            int on = 0;
-            (void)setsockopt(osfd, IPPROTO_IPV6, IPV6_V6ONLY,
-                    &on, sizeof(on));
-        }
-#endif
         fd = pt_SetMethods(osfd, ftype, PR_FALSE, PR_FALSE);
         if (fd == NULL) close(osfd);
@@ -3495,18 +2853,4 @@
 #ifdef _PR_STRICT_ADDR_LEN
     if (fd != NULL) fd->secret->af = domain;
-#endif
-#if defined(_PR_INET6_PROBE) || !defined(_PR_INET6)
-	if (fd != NULL) {
-		/*
-		 * For platforms with no support for IPv6
-		 * create layered socket for IPv4-mapped IPv6 addresses
-		 */
-		if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) {
-			if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) {
-				PR_Close(fd);
-				fd = NULL;
-			}
-		}
-	}
 #endif
     return fd;
@@ -4335,53 +3679,8 @@
 }  /* PR_ReadDir */
 
-PR_IMPLEMENT(PRFileDesc*) PR_NewUDPSocket(void)
-{
-    PRIntn domain = PF_INET;
-
-    return PR_Socket(domain, SOCK_DGRAM, 0);
-}  /* PR_NewUDPSocket */
-
-PR_IMPLEMENT(PRFileDesc*) PR_NewTCPSocket(void)
-{
-    PRIntn domain = PF_INET;
-
-    return PR_Socket(domain, SOCK_STREAM, 0);
-}  /* PR_NewTCPSocket */
-
-PR_IMPLEMENT(PRFileDesc*) PR_OpenUDPSocket(PRIntn af)
-{
-    return PR_Socket(af, SOCK_DGRAM, 0);
-}  /* PR_NewUDPSocket */
-
 PR_IMPLEMENT(PRFileDesc*) PR_OpenTCPSocket(PRIntn af)
 {
     return PR_Socket(af, SOCK_STREAM, 0);
 }  /* PR_NewTCPSocket */
-
-PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2])
-{
-    PRInt32 osfd[2];
-
-    if (pt_TestAbort()) return PR_FAILURE;
-
-    if (socketpair(AF_UNIX, SOCK_STREAM, 0, osfd) == -1) {
-    pt_MapError(_PR_MD_MAP_SOCKETPAIR_ERROR, errno);
-    return PR_FAILURE;
-    }
-
-    fds[0] = pt_SetMethods(osfd[0], PR_DESC_SOCKET_TCP, PR_FALSE, PR_FALSE);
-    if (fds[0] == NULL) {
-        close(osfd[0]);
-        close(osfd[1]);
-        return PR_FAILURE;
-    }
-    fds[1] = pt_SetMethods(osfd[1], PR_DESC_SOCKET_TCP, PR_FALSE, PR_FALSE);
-    if (fds[1] == NULL) {
-        PR_Close(fds[0]);
-        close(osfd[1]);
-        return PR_FAILURE;
-    }
-    return PR_SUCCESS;
-}  /* PR_NewTCPSocketPair */
 
 PR_IMPLEMENT(PRStatus) PR_CreatePipe(
Index: trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptthread.c
===================================================================
--- trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptthread.c	(revision 101792)
+++ trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptthread.c	(revision 101793)
@@ -966,5 +966,4 @@
         _PR_ShutdownLinker();
         _PR_LogCleanup();
-        _PR_CleanupNet();
         /* Close all the fd's before calling _PR_CleanupIO */
         _PR_CleanupIO();
