зеркало из https://github.com/mozilla/gecko-dev.git
Bug 807678: Don't proliferate NSPR DNS types beyond the host resolver itself. Make it possible to easily hook up other host resolvers. r=sworkman
This commit is contained in:
Родитель
694274b38b
Коммит
42f2ca6fe6
|
@ -6,12 +6,10 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
native PRNetAddr(union PRNetAddr);
|
||||
|
||||
/**
|
||||
* nsINetAddr
|
||||
*
|
||||
* This interface represents a (native) PRNetAddr struct in a readonly
|
||||
* This interface represents a native NetAddr struct in a readonly
|
||||
* interface.
|
||||
*/
|
||||
[scriptable, uuid(c407ab6c-c3ca-4cb2-a99b-a7dfbb88af33)]
|
||||
|
@ -26,7 +24,7 @@ interface nsINetAddr : nsISupports
|
|||
/**
|
||||
* @return Either the IP address (FAMILY_INET, FAMILY_INET6) or the path
|
||||
* (FAMILY_LOCAL) in string form. IP addresses are in the format produced by
|
||||
* PR_NetAddrToString.
|
||||
* mozilla::net::NetAddrToString.
|
||||
*
|
||||
* Note: Paths for FAMILY_LOCAL may have length limitations which are
|
||||
* implementation dependent and not documented as part of this interface.
|
||||
|
@ -61,7 +59,7 @@ interface nsINetAddr : nsISupports
|
|||
|
||||
/**
|
||||
* Network address families. These correspond to all the network address
|
||||
* families supported by the PRNetAddr struct.
|
||||
* families supported by the NetAddr struct.
|
||||
*/
|
||||
const unsigned long FAMILY_INET = 1;
|
||||
const unsigned long FAMILY_INET6 = 2;
|
||||
|
|
|
@ -8,7 +8,10 @@
|
|||
|
||||
interface nsIInterfaceRequestor;
|
||||
|
||||
native PRNetAddr(union PRNetAddr);
|
||||
%{ C++
|
||||
#include "mozilla/net/DNS.h"
|
||||
%}
|
||||
native NetAddr(mozilla::net::NetAddr);
|
||||
|
||||
/**
|
||||
* nsISocketTransport
|
||||
|
@ -20,7 +23,7 @@ native PRNetAddr(union PRNetAddr);
|
|||
* NOTE: This is a free-threaded interface, meaning that the methods on
|
||||
* this interface may be called from any thread.
|
||||
*/
|
||||
[scriptable, uuid(91ca3523-fc52-4dea-b167-ef8f56473dde)]
|
||||
[scriptable, uuid(A8318027-0DDC-4E60-A89B-D81AFE3B5020)]
|
||||
interface nsISocketTransport : nsITransport
|
||||
{
|
||||
/**
|
||||
|
@ -37,13 +40,13 @@ interface nsISocketTransport : nsITransport
|
|||
* Returns the IP address of the socket connection peer. This
|
||||
* attribute is defined only once a connection has been established.
|
||||
*/
|
||||
[noscript] PRNetAddr getPeerAddr();
|
||||
[noscript] NetAddr getPeerAddr();
|
||||
|
||||
/**
|
||||
* Returns the IP address of the initiating end. This attribute
|
||||
* is defined only once a connection has been established.
|
||||
*/
|
||||
[noscript] PRNetAddr getSelfAddr();
|
||||
[noscript] NetAddr getSelfAddr();
|
||||
|
||||
/**
|
||||
* Returns a scriptable version of getPeerAddr. This attribute is defined
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "nsJSUtils.h"
|
||||
#include "prnetdb.h"
|
||||
#include "nsITimer.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
@ -313,7 +314,7 @@ PACErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
|
|||
// timeout of 0 means the normal necko timeout strategy, otherwise the dns request
|
||||
// will be canceled after aTimeout milliseconds
|
||||
static
|
||||
JSBool PACResolve(const nsCString &aHostName, PRNetAddr *aNetAddr,
|
||||
JSBool PACResolve(const nsCString &aHostName, NetAddr *aNetAddr,
|
||||
unsigned int aTimeout)
|
||||
{
|
||||
if (!sRunning) {
|
||||
|
@ -326,7 +327,7 @@ JSBool PACResolve(const nsCString &aHostName, PRNetAddr *aNetAddr,
|
|||
|
||||
bool
|
||||
ProxyAutoConfig::ResolveAddress(const nsCString &aHostName,
|
||||
PRNetAddr *aNetAddr,
|
||||
NetAddr *aNetAddr,
|
||||
unsigned int aTimeout)
|
||||
{
|
||||
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
|
||||
|
@ -366,12 +367,12 @@ bool PACResolveToString(const nsCString &aHostName,
|
|||
nsCString &aDottedDecimal,
|
||||
unsigned int aTimeout)
|
||||
{
|
||||
PRNetAddr netAddr;
|
||||
NetAddr netAddr;
|
||||
if (!PACResolve(aHostName, &netAddr, aTimeout))
|
||||
return false;
|
||||
|
||||
char dottedDecimal[128];
|
||||
if (PR_NetAddrToString(&netAddr, dottedDecimal, sizeof(dottedDecimal)) != PR_SUCCESS)
|
||||
if (!NetAddrToString(&netAddr, dottedDecimal, sizeof(dottedDecimal)))
|
||||
return false;
|
||||
|
||||
aDottedDecimal.Assign(dottedDecimal);
|
||||
|
@ -686,14 +687,16 @@ ProxyAutoConfig::Shutdown()
|
|||
}
|
||||
|
||||
bool
|
||||
ProxyAutoConfig::SrcAddress(const PRNetAddr *remoteAddress, nsCString &localAddress)
|
||||
ProxyAutoConfig::SrcAddress(const NetAddr *remoteAddress, nsCString &localAddress)
|
||||
{
|
||||
PRFileDesc *fd;
|
||||
fd = PR_OpenUDPSocket(remoteAddress->raw.family);
|
||||
if (!fd)
|
||||
return false;
|
||||
|
||||
if (PR_Connect(fd, remoteAddress, 0) != PR_SUCCESS) {
|
||||
PRNetAddr prRemoteAddress;
|
||||
NetAddrToPRNetAddr(remoteAddress, &prRemoteAddress);
|
||||
if (PR_Connect(fd, &prRemoteAddress, 0) != PR_SUCCESS) {
|
||||
PR_Close(fd);
|
||||
return false;
|
||||
}
|
||||
|
@ -724,7 +727,7 @@ ProxyAutoConfig::MyIPAddressTryHost(const nsCString &hostName,
|
|||
unsigned int timeout,
|
||||
jsval *vp)
|
||||
{
|
||||
PRNetAddr remoteAddress;
|
||||
NetAddr remoteAddress;
|
||||
nsAutoCString localDottedDecimal;
|
||||
JSContext *cx = mJSRuntime->Context();
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "prio.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
namespace mozilla { namespace net {
|
||||
|
||||
|
@ -38,7 +39,7 @@ public:
|
|||
void GC();
|
||||
bool MyIPAddress(jsval *vp);
|
||||
bool ResolveAddress(const nsCString &aHostName,
|
||||
PRNetAddr *aNetAddr, unsigned int aTimeout);
|
||||
NetAddr *aNetAddr, unsigned int aTimeout);
|
||||
|
||||
/**
|
||||
* Get the proxy string for the specified URI. The proxy string is
|
||||
|
@ -84,7 +85,7 @@ private:
|
|||
// used to compile the PAC file and setup the execution context
|
||||
nsresult SetupJS();
|
||||
|
||||
bool SrcAddress(const PRNetAddr *remoteAddress, nsCString &localAddress);
|
||||
bool SrcAddress(const NetAddr *remoteAddress, nsCString &localAddress);
|
||||
bool MyIPAddressTryHost(const nsCString &hostName, unsigned int timeout,
|
||||
jsval *vp);
|
||||
|
||||
|
|
|
@ -6,13 +6,14 @@
|
|||
|
||||
#include "nsNetAddr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "prnetdb.h"
|
||||
|
||||
using namespace mozilla::net;
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsNetAddr, nsINetAddr)
|
||||
|
||||
/* Makes a copy of |addr| */
|
||||
nsNetAddr::nsNetAddr(PRNetAddr* addr)
|
||||
nsNetAddr::nsNetAddr(NetAddr* addr)
|
||||
{
|
||||
NS_ASSERTION(addr, "null addr");
|
||||
mAddr = *addr;
|
||||
|
@ -22,15 +23,17 @@ nsNetAddr::nsNetAddr(PRNetAddr* addr)
|
|||
NS_IMETHODIMP nsNetAddr::GetFamily(uint16_t *aFamily)
|
||||
{
|
||||
switch(mAddr.raw.family) {
|
||||
case PR_AF_INET:
|
||||
case AF_INET:
|
||||
*aFamily = nsINetAddr::FAMILY_INET;
|
||||
break;
|
||||
case PR_AF_INET6:
|
||||
case AF_INET6:
|
||||
*aFamily = nsINetAddr::FAMILY_INET6;
|
||||
break;
|
||||
case PR_AF_LOCAL:
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
case AF_LOCAL:
|
||||
*aFamily = nsINetAddr::FAMILY_LOCAL;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
@ -43,18 +46,18 @@ NS_IMETHODIMP nsNetAddr::GetAddress(nsACString & aAddress)
|
|||
{
|
||||
switch(mAddr.raw.family) {
|
||||
/* PR_NetAddrToString can handle INET and INET6, but not LOCAL. */
|
||||
case PR_AF_INET:
|
||||
aAddress.SetCapacity(16);
|
||||
PR_NetAddrToString(&mAddr, aAddress.BeginWriting(), 16);
|
||||
case AF_INET:
|
||||
aAddress.SetCapacity(kIPv4CStrBufSize);
|
||||
NetAddrToString(&mAddr, aAddress.BeginWriting(), kIPv4CStrBufSize);
|
||||
aAddress.SetLength(strlen(aAddress.BeginReading()));
|
||||
break;
|
||||
case PR_AF_INET6:
|
||||
aAddress.SetCapacity(46);
|
||||
PR_NetAddrToString(&mAddr, aAddress.BeginWriting(), 46);
|
||||
case AF_INET6:
|
||||
aAddress.SetCapacity(kIPv6CStrBufSize);
|
||||
NetAddrToString(&mAddr, aAddress.BeginWriting(), kIPv6CStrBufSize);
|
||||
aAddress.SetLength(strlen(aAddress.BeginReading()));
|
||||
break;
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
case PR_AF_LOCAL:
|
||||
case AF_LOCAL:
|
||||
aAddress.Assign(mAddr.local.path);
|
||||
break;
|
||||
#endif
|
||||
|
@ -70,15 +73,17 @@ NS_IMETHODIMP nsNetAddr::GetAddress(nsACString & aAddress)
|
|||
NS_IMETHODIMP nsNetAddr::GetPort(uint16_t *aPort)
|
||||
{
|
||||
switch(mAddr.raw.family) {
|
||||
case PR_AF_INET:
|
||||
*aPort = PR_ntohs(mAddr.inet.port);
|
||||
case AF_INET:
|
||||
*aPort = ntohs(mAddr.inet.port);
|
||||
break;
|
||||
case PR_AF_INET6:
|
||||
*aPort = PR_ntohs(mAddr.ipv6.port);
|
||||
case AF_INET6:
|
||||
*aPort = ntohs(mAddr.inet6.port);
|
||||
break;
|
||||
case PR_AF_LOCAL:
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
case AF_LOCAL:
|
||||
// There is no port number for local / connections.
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
#endif
|
||||
default:
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
@ -90,11 +95,13 @@ NS_IMETHODIMP nsNetAddr::GetPort(uint16_t *aPort)
|
|||
NS_IMETHODIMP nsNetAddr::GetFlow(uint32_t *aFlow)
|
||||
{
|
||||
switch(mAddr.raw.family) {
|
||||
case PR_AF_INET6:
|
||||
*aFlow = PR_ntohl(mAddr.ipv6.flowinfo);
|
||||
case AF_INET6:
|
||||
*aFlow = ntohl(mAddr.inet6.flowinfo);
|
||||
break;
|
||||
case PR_AF_INET:
|
||||
case PR_AF_LOCAL:
|
||||
case AF_INET:
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
case AF_LOCAL:
|
||||
#endif
|
||||
// only for IPv6
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
default:
|
||||
|
@ -108,11 +115,13 @@ NS_IMETHODIMP nsNetAddr::GetFlow(uint32_t *aFlow)
|
|||
NS_IMETHODIMP nsNetAddr::GetScope(uint32_t *aScope)
|
||||
{
|
||||
switch(mAddr.raw.family) {
|
||||
case PR_AF_INET6:
|
||||
*aScope = PR_ntohl(mAddr.ipv6.scope_id);
|
||||
case AF_INET6:
|
||||
*aScope = ntohl(mAddr.inet6.scope_id);
|
||||
break;
|
||||
case PR_AF_INET:
|
||||
case PR_AF_LOCAL:
|
||||
case AF_INET:
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
case AF_LOCAL:
|
||||
#endif
|
||||
// only for IPv6
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
default:
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#define nsNetAddr_h__
|
||||
|
||||
#include "nsINetAddr.h"
|
||||
#include "prio.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
|
||||
class nsNetAddr MOZ_FINAL : public nsINetAddr
|
||||
|
@ -17,10 +17,10 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSINETADDR
|
||||
|
||||
nsNetAddr(PRNetAddr* addr);
|
||||
nsNetAddr(mozilla::net::NetAddr* addr);
|
||||
|
||||
private:
|
||||
PRNetAddr mAddr;
|
||||
mozilla::net::NetAddr mAddr;
|
||||
|
||||
protected:
|
||||
/* additional members */
|
||||
|
|
|
@ -13,8 +13,10 @@
|
|||
#include "prnetdb.h"
|
||||
#include "prio.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::net;
|
||||
|
||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
|
||||
|
@ -167,9 +169,11 @@ nsServerSocket::OnSocketReady(PRFileDesc *fd, int16_t outFlags)
|
|||
}
|
||||
|
||||
PRFileDesc *clientFD;
|
||||
PRNetAddr clientAddr;
|
||||
PRNetAddr prClientAddr;
|
||||
NetAddr clientAddr;
|
||||
|
||||
clientFD = PR_Accept(mFD, &clientAddr, PR_INTERVAL_NO_WAIT);
|
||||
clientFD = PR_Accept(mFD, &prClientAddr, PR_INTERVAL_NO_WAIT);
|
||||
PRNetAddrToNetAddr(&prClientAddr, &clientAddr);
|
||||
if (!clientFD)
|
||||
{
|
||||
NS_WARNING("PR_Accept failed");
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#endif
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::net;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
@ -806,22 +807,22 @@ nsSocketTransport::Init(const char **types, uint32_t typeCount,
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const PRNetAddr *addr)
|
||||
nsSocketTransport::InitWithConnectedSocket(PRFileDesc *fd, const NetAddr *addr)
|
||||
{
|
||||
NS_ASSERTION(!mFD, "already initialized");
|
||||
|
||||
char buf[64];
|
||||
PR_NetAddrToString(addr, buf, sizeof(buf));
|
||||
char buf[kIPv6CStrBufSize];
|
||||
NetAddrToString(addr, buf, sizeof(buf));
|
||||
mHost.Assign(buf);
|
||||
|
||||
uint16_t port;
|
||||
if (addr->raw.family == PR_AF_INET)
|
||||
if (addr->raw.family == AF_INET)
|
||||
port = addr->inet.port;
|
||||
else
|
||||
port = addr->ipv6.port;
|
||||
mPort = PR_ntohs(port);
|
||||
port = addr->inet6.port;
|
||||
mPort = ntohs(port);
|
||||
|
||||
memcpy(&mNetAddr, addr, sizeof(PRNetAddr));
|
||||
memcpy(&mNetAddr, addr, sizeof(NetAddr));
|
||||
|
||||
mPollFlags = (PR_POLL_READ | PR_POLL_WRITE | PR_POLL_EXCEPT);
|
||||
mPollTimeout = mTimeouts[TIMEOUT_READ_WRITE];
|
||||
|
@ -907,7 +908,9 @@ nsSocketTransport::ResolveHost()
|
|||
// we send it when it's created, rather than the empty address
|
||||
// we send with the connect call.
|
||||
mState = STATE_RESOLVING;
|
||||
PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET, SocketPort(), &mNetAddr);
|
||||
mNetAddr.raw.family = AF_INET;
|
||||
mNetAddr.inet.port = htons(SocketPort());
|
||||
mNetAddr.inet.ip = htonl(INADDR_ANY);
|
||||
return PostEvent(MSG_DNS_LOOKUP_COMPLETE, NS_OK, nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -1052,7 +1055,7 @@ nsSocketTransport::InitiateSocket()
|
|||
nsresult rv;
|
||||
|
||||
if (gIOService->IsOffline() &&
|
||||
!PR_IsNetAddrType(&mNetAddr, PR_IpAddrLoopback))
|
||||
!IsLoopBackAddress(&mNetAddr))
|
||||
return NS_ERROR_OFFLINE;
|
||||
|
||||
//
|
||||
|
@ -1158,8 +1161,8 @@ nsSocketTransport::InitiateSocket()
|
|||
|
||||
#if defined(PR_LOGGING)
|
||||
if (SOCKET_LOG_ENABLED()) {
|
||||
char buf[64];
|
||||
PR_NetAddrToString(&mNetAddr, buf, sizeof(buf));
|
||||
char buf[kIPv6CStrBufSize];
|
||||
NetAddrToString(&mNetAddr, buf, sizeof(buf));
|
||||
SOCKET_LOG((" trying address: %s\n", buf));
|
||||
}
|
||||
#endif
|
||||
|
@ -1167,7 +1170,9 @@ nsSocketTransport::InitiateSocket()
|
|||
//
|
||||
// Initiate the connect() to the host...
|
||||
//
|
||||
status = PR_Connect(fd, &mNetAddr, NS_SOCKET_CONNECT_TIMEOUT);
|
||||
PRNetAddr prAddr;
|
||||
NetAddrToPRNetAddr(&mNetAddr, &prAddr);
|
||||
status = PR_Connect(fd, &prAddr, NS_SOCKET_CONNECT_TIMEOUT);
|
||||
if (status == PR_SUCCESS) {
|
||||
//
|
||||
// we are connected!
|
||||
|
@ -1679,7 +1684,7 @@ nsSocketTransport::IsLocal(bool *aIsLocal)
|
|||
{
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
*aIsLocal = PR_IsNetAddrType(&mNetAddr, PR_IpAddrLoopback);
|
||||
*aIsLocal = IsLoopBackAddress(&mNetAddr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1900,7 +1905,7 @@ nsSocketTransport::GetPort(int32_t *port)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSocketTransport::GetPeerAddr(PRNetAddr *addr)
|
||||
nsSocketTransport::GetPeerAddr(NetAddr *addr)
|
||||
{
|
||||
// once we are in the connected state, mNetAddr will not change.
|
||||
// so if we can verify that we are in the connected state, then
|
||||
|
@ -1913,12 +1918,12 @@ nsSocketTransport::GetPeerAddr(PRNetAddr *addr)
|
|||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
memcpy(addr, &mNetAddr, sizeof(mNetAddr));
|
||||
memcpy(addr, &mNetAddr, sizeof(NetAddr));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSocketTransport::GetSelfAddr(PRNetAddr *addr)
|
||||
nsSocketTransport::GetSelfAddr(NetAddr *addr)
|
||||
{
|
||||
// we must not call any PR methods on our file descriptor
|
||||
// while holding mLock since those methods might re-enter
|
||||
|
@ -1930,11 +1935,14 @@ nsSocketTransport::GetSelfAddr(PRNetAddr *addr)
|
|||
fd = GetFD_Locked();
|
||||
}
|
||||
|
||||
if (!fd)
|
||||
if (!fd) {
|
||||
return NS_ERROR_NOT_CONNECTED;
|
||||
}
|
||||
|
||||
PRNetAddr prAddr;
|
||||
nsresult rv =
|
||||
(PR_GetSockName(fd, addr) == PR_SUCCESS) ? NS_OK : NS_ERROR_FAILURE;
|
||||
(PR_GetSockName(fd, &prAddr) == PR_SUCCESS) ? NS_OK : NS_ERROR_FAILURE;
|
||||
PRNetAddrToNetAddr(&prAddr, addr);
|
||||
|
||||
{
|
||||
MutexAutoLock lock(mLock);
|
||||
|
@ -1948,7 +1956,7 @@ nsSocketTransport::GetSelfAddr(PRNetAddr *addr)
|
|||
NS_IMETHODIMP
|
||||
nsSocketTransport::GetScriptablePeerAddr(nsINetAddr * *addr)
|
||||
{
|
||||
PRNetAddr rawAddr;
|
||||
NetAddr rawAddr;
|
||||
|
||||
nsresult rv;
|
||||
rv = GetPeerAddr(&rawAddr);
|
||||
|
@ -1964,7 +1972,7 @@ nsSocketTransport::GetScriptablePeerAddr(nsINetAddr * *addr)
|
|||
NS_IMETHODIMP
|
||||
nsSocketTransport::GetScriptableSelfAddr(nsINetAddr * *addr)
|
||||
{
|
||||
PRNetAddr rawAddr;
|
||||
NetAddr rawAddr;
|
||||
|
||||
nsresult rv;
|
||||
rv = GetSelfAddr(&rawAddr);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "nsIDNSRecord.h"
|
||||
#include "nsICancelable.h"
|
||||
#include "nsIClassInfo.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
class nsSocketTransport;
|
||||
|
||||
|
@ -121,7 +122,7 @@ public:
|
|||
// this method instructs the socket transport to use an already connected
|
||||
// socket with the given address.
|
||||
nsresult InitWithConnectedSocket(PRFileDesc *socketFD,
|
||||
const PRNetAddr *addr);
|
||||
const mozilla::net::NetAddr *addr);
|
||||
|
||||
// nsASocketHandler methods:
|
||||
void OnSocketReady(PRFileDesc *, int16_t outFlags);
|
||||
|
@ -199,7 +200,7 @@ private:
|
|||
|
||||
// mNetAddr is valid from GetPeerAddr() once we have
|
||||
// reached STATE_TRANSFERRING. It must not change after that.
|
||||
PRNetAddr mNetAddr;
|
||||
mozilla::net::NetAddr mNetAddr;
|
||||
bool mNetAddrIsSet;
|
||||
|
||||
// socket methods (these can only be called on the socket thread):
|
||||
|
|
|
@ -0,0 +1,205 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/mozalloc.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include "Ws2tcpip.h"
|
||||
#endif
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
const char *inet_ntop_internal(int af, const void *src, char *dst, socklen_t size)
|
||||
{
|
||||
#ifdef XP_WIN
|
||||
if (af == AF_INET) {
|
||||
struct sockaddr_in s;
|
||||
memset(&s, 0, sizeof(s));
|
||||
s.sin_family = AF_INET;
|
||||
memcpy(&s.sin_addr, src, sizeof(struct in_addr));
|
||||
int result = getnameinfo((struct sockaddr *)&s, sizeof(struct sockaddr_in),
|
||||
dst, size, nullptr, 0, NI_NUMERICHOST);
|
||||
if (result == 0) {
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
else if (af == AF_INET6) {
|
||||
struct sockaddr_in6 s;
|
||||
memset(&s, 0, sizeof(s));
|
||||
s.sin6_family = AF_INET6;
|
||||
memcpy(&s.sin6_addr, src, sizeof(struct in_addr6));
|
||||
int result = getnameinfo((struct sockaddr *)&s, sizeof(struct sockaddr_in6),
|
||||
dst, size, nullptr, 0, NI_NUMERICHOST);
|
||||
if (result == 0) {
|
||||
return dst;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
#else
|
||||
return inet_ntop(af, src, dst, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Copies the contents of a PRNetAddr to a NetAddr.
|
||||
// Does not do a ptr safety check!
|
||||
void PRNetAddrToNetAddr(const PRNetAddr *prAddr, NetAddr *addr)
|
||||
{
|
||||
if (prAddr->raw.family == PR_AF_INET) {
|
||||
addr->inet.family = AF_INET;
|
||||
addr->inet.port = prAddr->inet.port;
|
||||
addr->inet.ip = prAddr->inet.ip;
|
||||
}
|
||||
else if (prAddr->raw.family == PR_AF_INET6) {
|
||||
addr->inet6.family = AF_INET6;
|
||||
addr->inet6.port = prAddr->ipv6.port;
|
||||
addr->inet6.flowinfo = prAddr->ipv6.flowinfo;
|
||||
memcpy(&addr->inet6.ip, &prAddr->ipv6.ip, sizeof(addr->inet6.ip.u8));
|
||||
addr->inet6.scope_id = prAddr->ipv6.scope_id;
|
||||
}
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
else if (prAddr->raw.family == PR_AF_LOCAL) {
|
||||
addr->local.family = AF_LOCAL;
|
||||
memcpy(addr->local.path, prAddr->local.path, sizeof(addr->local.path));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Copies the contents of a NetAddr to a PRNetAddr.
|
||||
// Does not do a ptr safety check!
|
||||
void NetAddrToPRNetAddr(const NetAddr *addr, PRNetAddr *prAddr)
|
||||
{
|
||||
if (addr->raw.family == AF_INET) {
|
||||
prAddr->inet.family = PR_AF_INET;
|
||||
prAddr->inet.port = addr->inet.port;
|
||||
prAddr->inet.ip = addr->inet.ip;
|
||||
}
|
||||
else if (addr->raw.family == AF_INET6) {
|
||||
prAddr->ipv6.family = PR_AF_INET6;
|
||||
prAddr->ipv6.port = addr->inet6.port;
|
||||
prAddr->ipv6.flowinfo = addr->inet6.flowinfo;
|
||||
memcpy(&prAddr->ipv6.ip, &addr->inet6.ip, sizeof(addr->inet6.ip.u8));
|
||||
prAddr->ipv6.scope_id = addr->inet6.scope_id;
|
||||
}
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
else if (addr->raw.family == AF_LOCAL) {
|
||||
prAddr->local.family = PR_AF_LOCAL;
|
||||
memcpy(prAddr->local.path, addr->local.path, sizeof(addr->local.path));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool NetAddrToString(const NetAddr *addr, char *buf, uint32_t bufSize)
|
||||
{
|
||||
if (addr->raw.family == AF_INET) {
|
||||
if (bufSize < INET_ADDRSTRLEN) {
|
||||
return false;
|
||||
}
|
||||
struct in_addr nativeAddr = {};
|
||||
nativeAddr.s_addr = addr->inet.ip;
|
||||
return !!inet_ntop_internal(AF_INET, &nativeAddr, buf, bufSize);
|
||||
}
|
||||
else if (addr->raw.family == AF_INET6) {
|
||||
if (bufSize < INET6_ADDRSTRLEN) {
|
||||
return false;
|
||||
}
|
||||
struct in6_addr nativeAddr = {};
|
||||
memcpy(&nativeAddr.s6_addr, &addr->inet6.ip, sizeof(addr->inet6.ip.u8));
|
||||
return !!inet_ntop_internal(AF_INET6, &nativeAddr, buf, bufSize);
|
||||
}
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
else if (addr->raw.family == AF_LOCAL) {
|
||||
if (bufSize < sizeof(addr->local.path)) {
|
||||
return false;
|
||||
}
|
||||
memcpy(buf, addr->local.path, bufSize);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsLoopBackAddress(const NetAddr *addr)
|
||||
{
|
||||
if (addr->raw.family == AF_INET) {
|
||||
return (addr->inet.ip == htonl(INADDR_LOOPBACK));
|
||||
}
|
||||
else if (addr->raw.family == AF_INET6) {
|
||||
if (IPv6ADDR_IS_LOOPBACK(&addr->inet6.ip)) {
|
||||
return true;
|
||||
} else if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) &&
|
||||
IPv6ADDR_V4MAPPED_TO_IPADDR(&addr->inet6.ip) == htonl(INADDR_LOOPBACK)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsIPAddrAny(const NetAddr *addr)
|
||||
{
|
||||
if (addr->raw.family == AF_INET) {
|
||||
if (addr->inet.ip == htonl(INADDR_ANY)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (addr->raw.family == AF_INET6) {
|
||||
if (IPv6ADDR_IS_UNSPECIFIED(&addr->inet6.ip)) {
|
||||
return true;
|
||||
} else if (IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip) &&
|
||||
IPv6ADDR_V4MAPPED_TO_IPADDR(&addr->inet6.ip) == htonl(INADDR_ANY)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsIPAddrV4Mapped(const NetAddr *addr)
|
||||
{
|
||||
if (addr->raw.family == AF_INET6) {
|
||||
return IPv6ADDR_IS_V4MAPPED(&addr->inet6.ip);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
NetAddrElement::NetAddrElement(const PRNetAddr *prNetAddr)
|
||||
{
|
||||
PRNetAddrToNetAddr(prNetAddr, &mAddress);
|
||||
}
|
||||
|
||||
NetAddrElement::~NetAddrElement()
|
||||
{
|
||||
}
|
||||
|
||||
AddrInfo::AddrInfo(const char *host, const PRAddrInfo *prAddrInfo)
|
||||
{
|
||||
size_t hostlen = strlen(host);
|
||||
mHostName = static_cast<char*>(moz_xmalloc(hostlen + 1));
|
||||
memcpy(mHostName, host, hostlen + 1);
|
||||
|
||||
PRNetAddr tmpAddr;
|
||||
void *iter = nullptr;
|
||||
do {
|
||||
iter = PR_EnumerateAddrInfo(iter, prAddrInfo, 0, &tmpAddr);
|
||||
if (iter) {
|
||||
NetAddrElement *addrElement = new NetAddrElement(&tmpAddr);
|
||||
mAddresses.insertBack(addrElement);
|
||||
}
|
||||
} while (iter);
|
||||
}
|
||||
|
||||
AddrInfo::~AddrInfo()
|
||||
{
|
||||
NetAddrElement *addrElement;
|
||||
while ((addrElement = mAddresses.popLast())) {
|
||||
delete addrElement;
|
||||
}
|
||||
free(mHostName);
|
||||
}
|
||||
|
||||
} // namespace dns
|
||||
} // namespace mozilla
|
|
@ -0,0 +1,141 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef DNS_h_
|
||||
#define DNS_h_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "prio.h"
|
||||
#include "prnetdb.h"
|
||||
#include "mozilla/LinkedList.h"
|
||||
|
||||
#if !defined(XP_WIN) && !defined(XP_OS2)
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
#include "Winsock2.h"
|
||||
#endif
|
||||
|
||||
#define IPv6ADDR_IS_LOOPBACK(a) \
|
||||
(((a)->u32[0] == 0) && \
|
||||
((a)->u32[1] == 0) && \
|
||||
((a)->u32[2] == 0) && \
|
||||
((a)->u8[12] == 0) && \
|
||||
((a)->u8[13] == 0) && \
|
||||
((a)->u8[14] == 0) && \
|
||||
((a)->u8[15] == 0x1U))
|
||||
|
||||
#define IPv6ADDR_IS_V4MAPPED(a) \
|
||||
(((a)->u32[0] == 0) && \
|
||||
((a)->u32[1] == 0) && \
|
||||
((a)->u8[8] == 0) && \
|
||||
((a)->u8[9] == 0) && \
|
||||
((a)->u8[10] == 0xff) && \
|
||||
((a)->u8[11] == 0xff))
|
||||
|
||||
#define IPv6ADDR_V4MAPPED_TO_IPADDR(a) ((a)->u32[3])
|
||||
|
||||
#define IPv6ADDR_IS_UNSPECIFIED(a) \
|
||||
(((a)->u32[0] == 0) && \
|
||||
((a)->u32[1] == 0) && \
|
||||
((a)->u32[2] == 0) && \
|
||||
((a)->u32[3] == 0))
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
// Required buffer size for text form of an IP address.
|
||||
// Includes space for null termination.
|
||||
const int kIPv4CStrBufSize = 16;
|
||||
const int kIPv6CStrBufSize = 46;
|
||||
|
||||
// This was all created at a time in which we were using NSPR for host
|
||||
// resolution and we were propagating NSPR types like "PRAddrInfo" and
|
||||
// "PRNetAddr" all over Gecko. This made it hard to use another host
|
||||
// resolver -- we were locked into NSPR. The goal here is to get away
|
||||
// from that. We'll translate what we get from NSPR or any other host
|
||||
// resolution library into the types below and use them in Gecko.
|
||||
|
||||
union IPv6Addr {
|
||||
uint8_t u8[16];
|
||||
uint16_t u16[8];
|
||||
uint32_t u32[4];
|
||||
uint64_t u64[2];
|
||||
};
|
||||
|
||||
// This struct is similar to operating system structs like "sockaddr", used for
|
||||
// things like "connect" and "getsockname". When tempted to cast or do dumb
|
||||
// copies of this struct to another struct, bear compiler-computed padding
|
||||
// in mind. The size of this struct, and the layout of the data in it, may
|
||||
// not be what you expect.
|
||||
union NetAddr {
|
||||
struct {
|
||||
uint16_t family; /* address family (0x00ff maskable) */
|
||||
char data[14]; /* raw address data */
|
||||
} raw;
|
||||
struct {
|
||||
uint16_t family; /* address family (AF_INET) */
|
||||
uint16_t port; /* port number */
|
||||
uint32_t ip; /* The actual 32 bits of address */
|
||||
} inet;
|
||||
struct {
|
||||
uint16_t family; /* address family (AF_INET6) */
|
||||
uint16_t port; /* port number */
|
||||
uint32_t flowinfo; /* routing information */
|
||||
IPv6Addr ip; /* the actual 128 bits of address */
|
||||
uint32_t scope_id; /* set of interfaces for a scope */
|
||||
} inet6;
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
struct { /* Unix domain socket address */
|
||||
uint16_t family; /* address family (AF_UNIX) */
|
||||
#ifdef XP_OS2
|
||||
char path[108]; /* null-terminated pathname */
|
||||
#else
|
||||
char path[104]; /* null-terminated pathname */
|
||||
#endif
|
||||
} local;
|
||||
#endif
|
||||
};
|
||||
|
||||
// This class wraps a NetAddr union to provide C++ linked list
|
||||
// capabilities and other methods. It is created from a PRNetAddr,
|
||||
// which is converted to a mozilla::dns::NetAddr.
|
||||
class NetAddrElement : public LinkedListElement<NetAddrElement> {
|
||||
public:
|
||||
NetAddrElement(const PRNetAddr *prNetAddr);
|
||||
~NetAddrElement();
|
||||
|
||||
NetAddr mAddress;
|
||||
};
|
||||
|
||||
class AddrInfo {
|
||||
public:
|
||||
AddrInfo(const char *host, const PRAddrInfo *prAddrInfo);
|
||||
~AddrInfo();
|
||||
|
||||
char *mHostName;
|
||||
LinkedList<NetAddrElement> mAddresses;
|
||||
};
|
||||
|
||||
// Copies the contents of a PRNetAddr to a NetAddr.
|
||||
// Does not do a ptr safety check!
|
||||
void PRNetAddrToNetAddr(const PRNetAddr *prAddr, NetAddr *addr);
|
||||
|
||||
// Copies the contents of a NetAddr to a PRNetAddr.
|
||||
// Does not do a ptr safety check!
|
||||
void NetAddrToPRNetAddr(const NetAddr *addr, PRNetAddr *prAddr);
|
||||
|
||||
bool NetAddrToString(const NetAddr *addr, char *buf, uint32_t bufSize);
|
||||
|
||||
bool IsLoopBackAddress(const NetAddr *addr);
|
||||
|
||||
bool IsIPAddrAny(const NetAddr *addr);
|
||||
|
||||
bool IsIPAddrV4Mapped(const NetAddr *addr);
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // DNS_h_
|
|
@ -27,9 +27,10 @@ XPIDLSRCS = \
|
|||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
DNS.cpp \
|
||||
nsIDNService.cpp \
|
||||
nsDNSService2.cpp \
|
||||
nsHostResolver.cpp \
|
||||
nsDNSService2.cpp \
|
||||
nsEffectiveTLDService.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
@ -39,6 +40,12 @@ CSRCS = \
|
|||
punycode.c \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS_NAMESPACES = mozilla/net
|
||||
|
||||
EXPORTS_mozilla/net = \
|
||||
DNS.h \
|
||||
$(null)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a
|
||||
# static lib.
|
||||
FORCE_STATIC_LIB = 1
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "mozilla/Attributes.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::net;
|
||||
|
||||
static const char kPrefDnsCacheEntries[] = "network.dnsCacheEntries";
|
||||
static const char kPrefDnsCacheExpiration[] = "network.dnsCacheExpiration";
|
||||
|
@ -51,7 +52,6 @@ public:
|
|||
nsDNSRecord(nsHostRecord *hostRecord)
|
||||
: mHostRecord(hostRecord)
|
||||
, mIter(nullptr)
|
||||
, mLastIter(nullptr)
|
||||
, mIterGenCnt(-1)
|
||||
, mDone(false) {}
|
||||
|
||||
|
@ -59,9 +59,7 @@ private:
|
|||
virtual ~nsDNSRecord() {}
|
||||
|
||||
nsRefPtr<nsHostRecord> mHostRecord;
|
||||
void *mIter; // enum ptr for PR_EnumerateAddrInfo
|
||||
void *mLastIter; // previous enum ptr, for use in
|
||||
// getting addrinfo in ReportUnusable
|
||||
NetAddrElement *mIter;
|
||||
int mIterGenCnt; // the generation count of
|
||||
// mHostRecord->addr_info when we
|
||||
// start iterating
|
||||
|
@ -83,7 +81,7 @@ nsDNSRecord::GetCanonicalName(nsACString &result)
|
|||
{
|
||||
MutexAutoLock lock(mHostRecord->addr_info_lock);
|
||||
if (mHostRecord->addr_info)
|
||||
cname = PR_GetCanonNameFromAddrInfo(mHostRecord->addr_info);
|
||||
cname = mHostRecord->addr_info->mHostName;
|
||||
else
|
||||
cname = mHostRecord->host;
|
||||
result.Assign(cname);
|
||||
|
@ -92,46 +90,45 @@ nsDNSRecord::GetCanonicalName(nsACString &result)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSRecord::GetNextAddr(uint16_t port, PRNetAddr *addr)
|
||||
nsDNSRecord::GetNextAddr(uint16_t port, NetAddr *addr)
|
||||
{
|
||||
// not a programming error to poke the DNS record when it has no more
|
||||
// entries. just fail without any debug warnings. this enables consumers
|
||||
// to enumerate the DNS record without calling HasMore.
|
||||
if (mDone)
|
||||
if (mDone) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
mHostRecord->addr_info_lock.Lock();
|
||||
bool startedFresh = !mIter;
|
||||
|
||||
if (mHostRecord->addr_info) {
|
||||
if (!mIter)
|
||||
mIterGenCnt = mHostRecord->addr_info_gencnt;
|
||||
else if (mIterGenCnt != mHostRecord->addr_info_gencnt) {
|
||||
// mHostRecord->addr_info has changed, so mIter is invalid.
|
||||
// Restart the iteration. Alternatively, we could just fail.
|
||||
if (mIterGenCnt != mHostRecord->addr_info_gencnt) {
|
||||
// mHostRecord->addr_info has changed, restart the iteration.
|
||||
mIter = nullptr;
|
||||
mIterGenCnt = mHostRecord->addr_info_gencnt;
|
||||
startedFresh = true;
|
||||
}
|
||||
|
||||
bool startedFresh = !mIter;
|
||||
|
||||
do {
|
||||
mLastIter = mIter;
|
||||
mIter = PR_EnumerateAddrInfo(mIter, mHostRecord->addr_info,
|
||||
port, addr);
|
||||
if (!mIter) {
|
||||
mIter = mHostRecord->addr_info->mAddresses.getFirst();
|
||||
} else {
|
||||
mIter = mIter->getNext();
|
||||
}
|
||||
}
|
||||
while (mIter && mHostRecord->Blacklisted(addr));
|
||||
while (mIter && mHostRecord->Blacklisted(&mIter->mAddress));
|
||||
|
||||
if (startedFresh && !mIter) {
|
||||
// if everything was blacklisted we want to reset the blacklist (and
|
||||
if (!mIter && startedFresh) {
|
||||
// If everything was blacklisted we want to reset the blacklist (and
|
||||
// likely relearn it) and return the first address. That is better
|
||||
// than nothing
|
||||
// than nothing.
|
||||
mHostRecord->ResetBlacklist();
|
||||
mLastIter = nullptr;
|
||||
mIter = PR_EnumerateAddrInfo(nullptr, mHostRecord->addr_info,
|
||||
port, addr);
|
||||
mIter = mHostRecord->addr_info->mAddresses.getFirst();
|
||||
}
|
||||
|
||||
|
||||
if (mIter) {
|
||||
memcpy(addr, &mIter->mAddress, sizeof(NetAddr));
|
||||
}
|
||||
|
||||
mHostRecord->addr_info_lock.Unlock();
|
||||
|
||||
if (!mIter) {
|
||||
mDone = true;
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
@ -139,57 +136,61 @@ nsDNSRecord::GetNextAddr(uint16_t port, PRNetAddr *addr)
|
|||
}
|
||||
else {
|
||||
mHostRecord->addr_info_lock.Unlock();
|
||||
|
||||
if (!mHostRecord->addr) {
|
||||
// Both mHostRecord->addr_info and mHostRecord->addr are null.
|
||||
// This can happen if mHostRecord->addr_info expired and the
|
||||
// attempt to reresolve it failed.
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
memcpy(addr, mHostRecord->addr, sizeof(PRNetAddr));
|
||||
// set given port
|
||||
port = PR_htons(port);
|
||||
if (addr->raw.family == PR_AF_INET)
|
||||
addr->inet.port = port;
|
||||
else
|
||||
addr->ipv6.port = port;
|
||||
mDone = true; // no iterations
|
||||
memcpy(addr, mHostRecord->addr, sizeof(NetAddr));
|
||||
mDone = true;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
// set given port
|
||||
port = htons(port);
|
||||
if (addr->raw.family == AF_INET) {
|
||||
addr->inet.port = port;
|
||||
}
|
||||
else if (addr->raw.family == AF_INET6) {
|
||||
addr->inet6.port = port;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSRecord::GetNextAddrAsString(nsACString &result)
|
||||
{
|
||||
PRNetAddr addr;
|
||||
NetAddr addr;
|
||||
nsresult rv = GetNextAddr(0, &addr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char buf[64];
|
||||
if (PR_NetAddrToString(&addr, buf, sizeof(buf)) == PR_SUCCESS) {
|
||||
char buf[kIPv6CStrBufSize];
|
||||
if (NetAddrToString(&addr, buf, sizeof(buf))) {
|
||||
result.Assign(buf);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_ERROR("PR_NetAddrToString failed unexpectedly");
|
||||
NS_ERROR("NetAddrToString failed unexpectedly");
|
||||
return NS_ERROR_FAILURE; // conversion failed for some reason
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDNSRecord::HasMore(bool *result)
|
||||
{
|
||||
if (mDone)
|
||||
if (mDone) {
|
||||
*result = false;
|
||||
else {
|
||||
// unfortunately, NSPR does not provide a way for us to determine if
|
||||
// there is another address other than to simply get the next address.
|
||||
void *iterCopy = mIter;
|
||||
void *iterLastCopy = mLastIter;
|
||||
PRNetAddr addr;
|
||||
*result = NS_SUCCEEDED(GetNextAddr(0, &addr));
|
||||
mIter = iterCopy; // backup iterator
|
||||
mLastIter = iterLastCopy; // backup iterator
|
||||
mDone = false;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NetAddrElement *iterCopy = mIter;
|
||||
|
||||
NetAddr addr;
|
||||
*result = NS_SUCCEEDED(GetNextAddr(0, &addr));
|
||||
|
||||
mIter = iterCopy;
|
||||
mDone = false;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -197,7 +198,6 @@ NS_IMETHODIMP
|
|||
nsDNSRecord::Rewind()
|
||||
{
|
||||
mIter = nullptr;
|
||||
mLastIter = nullptr;
|
||||
mIterGenCnt = -1;
|
||||
mDone = false;
|
||||
return NS_OK;
|
||||
|
@ -208,7 +208,7 @@ nsDNSRecord::ReportUnusable(uint16_t aPort)
|
|||
{
|
||||
// right now we don't use the port in the blacklist
|
||||
|
||||
mHostRecord->addr_info_lock.Lock();
|
||||
MutexAutoLock lock(mHostRecord->addr_info_lock);
|
||||
|
||||
// Check that we are using a real addr_info (as opposed to a single
|
||||
// constant address), and that the generation count is valid. Otherwise,
|
||||
|
@ -216,14 +216,9 @@ nsDNSRecord::ReportUnusable(uint16_t aPort)
|
|||
|
||||
if (mHostRecord->addr_info &&
|
||||
mIterGenCnt == mHostRecord->addr_info_gencnt) {
|
||||
PRNetAddr addr;
|
||||
void *id = PR_EnumerateAddrInfo(mLastIter, mHostRecord->addr_info,
|
||||
aPort, &addr);
|
||||
if (id)
|
||||
mHostRecord->ReportUnusable(&addr);
|
||||
mHostRecord->ReportUnusable(&mIter->mAddress);
|
||||
}
|
||||
|
||||
mHostRecord->addr_info_lock.Unlock();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ nsHostRecord::~nsHostRecord()
|
|||
}
|
||||
|
||||
bool
|
||||
nsHostRecord::Blacklisted(PRNetAddr *aQuery)
|
||||
nsHostRecord::Blacklisted(NetAddr *aQuery)
|
||||
{
|
||||
// must call locked
|
||||
LOG(("Checking blacklist for host [%s], host record [%p].\n", host, this));
|
||||
|
@ -195,8 +195,8 @@ nsHostRecord::Blacklisted(PRNetAddr *aQuery)
|
|||
return false;
|
||||
}
|
||||
|
||||
char buf[64];
|
||||
if (PR_NetAddrToString(aQuery, buf, sizeof(buf)) != PR_SUCCESS) {
|
||||
char buf[kIPv6CStrBufSize];
|
||||
if (!NetAddrToString(aQuery, buf, sizeof(buf))) {
|
||||
return false;
|
||||
}
|
||||
nsDependentCString strQuery(buf);
|
||||
|
@ -212,13 +212,13 @@ nsHostRecord::Blacklisted(PRNetAddr *aQuery)
|
|||
}
|
||||
|
||||
void
|
||||
nsHostRecord::ReportUnusable(PRNetAddr *aAddress)
|
||||
nsHostRecord::ReportUnusable(NetAddr *aAddress)
|
||||
{
|
||||
// must call locked
|
||||
LOG(("Adding address to blacklist for host [%s], host record [%p].\n", host, this));
|
||||
|
||||
char buf[64];
|
||||
if (PR_NetAddrToString(aAddress, buf, sizeof(buf)) == PR_SUCCESS) {
|
||||
char buf[kIPv6CStrBufSize];
|
||||
if (NetAddrToString(aAddress, buf, sizeof(buf))) {
|
||||
LOG(("Successfully adding address [%s] to blacklist for host [%s].\n", buf, host));
|
||||
mBlacklistedItems.AppendElement(nsCString(buf));
|
||||
}
|
||||
|
@ -275,21 +275,20 @@ HostDB_ClearEntry(PLDHashTable *table,
|
|||
nsHostDBEnt *he = static_cast<nsHostDBEnt *>(entry);
|
||||
LOG(("Clearing cache db entry for host [%s].\n", he->rec->host));
|
||||
#if defined(DEBUG) && defined(PR_LOGGING)
|
||||
if (!he->rec->addr_info) {
|
||||
LOG(("No address info for host [%s].\n", he->rec->host));
|
||||
} else {
|
||||
int32_t now = (int32_t) NowInMinutes();
|
||||
int32_t diff = (int32_t) he->rec->expiration - now;
|
||||
LOG(("Record for [%s] expires in %d minute(s).\n", he->rec->host, diff));
|
||||
void *iter = nullptr;
|
||||
PRNetAddr addr;
|
||||
char buf[64];
|
||||
for (;;) {
|
||||
iter = PR_EnumerateAddrInfo(iter, he->rec->addr_info, 0, &addr);
|
||||
if (!iter)
|
||||
break;
|
||||
PR_NetAddrToString(&addr, buf, sizeof(buf));
|
||||
LOG((" [%s]\n", buf));
|
||||
{
|
||||
MutexAutoLock lock(he->rec->addr_info_lock);
|
||||
if (!he->rec->addr_info) {
|
||||
LOG(("No address info for host [%s].\n", he->rec->host));
|
||||
} else {
|
||||
int32_t now = (int32_t) NowInMinutes();
|
||||
int32_t diff = (int32_t) he->rec->expiration - now;
|
||||
LOG(("Record for [%s] expires in %d minute(s).\n", he->rec->host, diff));
|
||||
NetAddrElement *addrElement;
|
||||
char buf[kIPv6CStrBufSize];
|
||||
while ((addrElement = he->rec->addr_info->mAddresses.popLast())) {
|
||||
NetAddrToString(&addrElement->mAddress, buf, sizeof(buf));
|
||||
LOG((" [%s]\n", buf));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -506,10 +505,10 @@ nsHostResolver::ResolveHost(const char *host,
|
|||
if (mShutdown)
|
||||
rv = NS_ERROR_NOT_INITIALIZED;
|
||||
else {
|
||||
// Used to try to parse to an IP address literal.
|
||||
PRNetAddr tempAddr;
|
||||
|
||||
// unfortunately, PR_StringToNetAddr does not properly initialize
|
||||
// the output buffer in the case of IPv6 input. see bug 223145.
|
||||
// Unfortunately, PR_StringToNetAddr does not properly initialize
|
||||
// the output buffer in the case of IPv6 input. See bug 223145.
|
||||
memset(&tempAddr, 0, sizeof(PRNetAddr));
|
||||
|
||||
// check to see if there is already an entry for this |host|
|
||||
|
@ -572,11 +571,8 @@ nsHostResolver::ResolveHost(const char *host,
|
|||
else if (PR_StringToNetAddr(host, &tempAddr) == PR_SUCCESS) {
|
||||
// ok, just copy the result into the host record, and be done
|
||||
// with it! ;-)
|
||||
he->rec->addr = (PRNetAddr *) malloc(sizeof(PRNetAddr));
|
||||
if (!he->rec->addr)
|
||||
status = NS_ERROR_OUT_OF_MEMORY;
|
||||
else
|
||||
memcpy(he->rec->addr, &tempAddr, sizeof(PRNetAddr));
|
||||
he->rec->addr = new NetAddr();
|
||||
PRNetAddrToNetAddr(&tempAddr, he->rec->addr);
|
||||
// put reference to host record on stack...
|
||||
Telemetry::Accumulate(Telemetry::DNS_LOOKUP_METHOD2,
|
||||
METHOD_LITERAL);
|
||||
|
@ -820,7 +816,7 @@ nsHostResolver::GetHostToLookup(nsHostRecord **result)
|
|||
}
|
||||
|
||||
void
|
||||
nsHostResolver::OnLookupComplete(nsHostRecord *rec, nsresult status, PRAddrInfo *result)
|
||||
nsHostResolver::OnLookupComplete(nsHostRecord *rec, nsresult status, AddrInfo *result)
|
||||
{
|
||||
// get the list of pending callbacks for this lookup, and notify
|
||||
// them that the lookup is complete.
|
||||
|
@ -834,15 +830,15 @@ nsHostResolver::OnLookupComplete(nsHostRecord *rec, nsresult status, PRAddrInfo
|
|||
|
||||
// update record fields. We might have a rec->addr_info already if a
|
||||
// previous lookup result expired and we're reresolving it..
|
||||
PRAddrInfo *old_addr_info;
|
||||
AddrInfo *old_addr_info;
|
||||
{
|
||||
MutexAutoLock lock(rec->addr_info_lock);
|
||||
old_addr_info = rec->addr_info;
|
||||
rec->addr_info = result;
|
||||
rec->addr_info_gencnt++;
|
||||
}
|
||||
if (old_addr_info)
|
||||
PR_FreeAddrInfo(old_addr_info);
|
||||
delete old_addr_info;
|
||||
|
||||
rec->expiration = NowInMinutes();
|
||||
if (result) {
|
||||
rec->expiration += mMaxCacheLifetime;
|
||||
|
@ -958,7 +954,7 @@ nsHostResolver::ThreadFunc(void *arg)
|
|||
#endif
|
||||
nsHostResolver *resolver = (nsHostResolver *)arg;
|
||||
nsHostRecord *rec;
|
||||
PRAddrInfo *ai;
|
||||
PRAddrInfo *prai = nullptr;
|
||||
while (resolver->GetHostToLookup(&rec)) {
|
||||
LOG(("Calling getaddrinfo for host [%s].\n", rec->host));
|
||||
|
||||
|
@ -968,18 +964,21 @@ nsHostResolver::ThreadFunc(void *arg)
|
|||
|
||||
TimeStamp startTime = TimeStamp::Now();
|
||||
|
||||
ai = PR_GetAddrInfoByName(rec->host, rec->af, flags);
|
||||
prai = PR_GetAddrInfoByName(rec->host, rec->af, flags);
|
||||
#if defined(RES_RETRY_ON_FAILURE)
|
||||
if (!ai && rs.Reset())
|
||||
ai = PR_GetAddrInfoByName(rec->host, rec->af, flags);
|
||||
if (!prai && rs.Reset())
|
||||
prai = PR_GetAddrInfoByName(rec->host, rec->af, flags);
|
||||
#endif
|
||||
|
||||
TimeDuration elapsed = TimeStamp::Now() - startTime;
|
||||
uint32_t millis = static_cast<uint32_t>(elapsed.ToMilliseconds());
|
||||
|
||||
// convert error code to nsresult.
|
||||
// convert error code to nsresult
|
||||
nsresult status;
|
||||
if (ai) {
|
||||
AddrInfo *ai = nullptr;
|
||||
if (prai) {
|
||||
ai = new AddrInfo(rec->host, prai);
|
||||
|
||||
status = NS_OK;
|
||||
|
||||
Telemetry::Accumulate(!rec->addr_info_gencnt ?
|
||||
|
@ -1032,45 +1031,45 @@ PLDHashOperator
|
|||
CacheEntryEnumerator(PLDHashTable *table, PLDHashEntryHdr *entry,
|
||||
uint32_t number, void *arg)
|
||||
{
|
||||
nsHostDBEnt *ent = static_cast<nsHostDBEnt *> (entry);
|
||||
nsTArray<DNSCacheEntries> *args =
|
||||
static_cast<nsTArray<DNSCacheEntries> *> (arg);
|
||||
nsHostRecord *rec = ent->rec;
|
||||
// Without addr_info, there is no meaning of adding this entry
|
||||
if (rec->addr_info) {
|
||||
DNSCacheEntries info;
|
||||
const char *hostname;
|
||||
PRNetAddr addr;
|
||||
|
||||
if (rec->host)
|
||||
hostname = rec->host;
|
||||
else // No need to add this entry if no host name is there
|
||||
return PL_DHASH_NEXT;
|
||||
|
||||
uint32_t now = NowInMinutes();
|
||||
info.expiration = ((int64_t) rec->expiration - now) * 60;
|
||||
// We don't pay attention to address literals, only resolved domains.
|
||||
// Also require a host.
|
||||
nsHostRecord *rec = static_cast<nsHostDBEnt*>(entry)->rec;
|
||||
if (!rec->addr_info || !rec->host) {
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
DNSCacheEntries info;
|
||||
info.hostname = rec->host;
|
||||
info.family = rec->af;
|
||||
info.expiration = ((int64_t)rec->expiration - NowInMinutes()) * 60;
|
||||
if (info.expiration <= 0) {
|
||||
// We only need valid DNS cache entries
|
||||
if (info.expiration <= 0)
|
||||
return PL_DHASH_NEXT;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
info.family = rec->af;
|
||||
info.hostname = hostname;
|
||||
{
|
||||
MutexAutoLock lock(rec->addr_info_lock);
|
||||
|
||||
{
|
||||
MutexAutoLock lock(rec->addr_info_lock);
|
||||
void *ptr = PR_EnumerateAddrInfo(nullptr, rec->addr_info, 0, &addr);
|
||||
while (ptr) {
|
||||
char buf[64];
|
||||
if (PR_NetAddrToString(&addr, buf, sizeof(buf)) == PR_SUCCESS)
|
||||
info.hostaddr.AppendElement(buf);
|
||||
ptr = PR_EnumerateAddrInfo(ptr, rec->addr_info, 0, &addr);
|
||||
NetAddr *addr = nullptr;
|
||||
NetAddrElement *addrElement = rec->addr_info->mAddresses.getFirst();
|
||||
if (addrElement) {
|
||||
addr = &addrElement->mAddress;
|
||||
}
|
||||
while (addr) {
|
||||
char buf[kIPv6CStrBufSize];
|
||||
if (NetAddrToString(addr, buf, sizeof(buf))) {
|
||||
info.hostaddr.AppendElement(buf);
|
||||
}
|
||||
addrElement = addrElement->getNext();
|
||||
if (addrElement) {
|
||||
addr = &addrElement->mAddress;
|
||||
}
|
||||
}
|
||||
|
||||
args->AppendElement(info);
|
||||
}
|
||||
|
||||
nsTArray<DNSCacheEntries> *args = static_cast<nsTArray<DNSCacheEntries> *>(arg);
|
||||
args->AppendElement(info);
|
||||
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "nsIDNSListener.h"
|
||||
#include "nsString.h"
|
||||
#include "nsTArray.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
#include "mozilla/net/DashboardTypes.h"
|
||||
|
||||
class nsHostResolver;
|
||||
|
@ -69,8 +70,8 @@ public:
|
|||
*/
|
||||
Mutex addr_info_lock;
|
||||
int addr_info_gencnt; /* generation count of |addr_info| */
|
||||
PRAddrInfo *addr_info;
|
||||
PRNetAddr *addr;
|
||||
mozilla::net::AddrInfo *addr_info;
|
||||
mozilla::net::NetAddr *addr;
|
||||
bool negative; /* True if this record is a cache of a failed lookup.
|
||||
Negative cache entries are valid just like any other
|
||||
(though never for more than 60 seconds), but a use
|
||||
|
@ -81,9 +82,9 @@ public:
|
|||
bool HasResult() const { return addr_info || addr || negative; }
|
||||
|
||||
// hold addr_info_lock when calling the blacklist functions
|
||||
bool Blacklisted(PRNetAddr *query);
|
||||
bool Blacklisted(mozilla::net::NetAddr *query);
|
||||
void ResetBlacklist();
|
||||
void ReportUnusable(PRNetAddr *addr);
|
||||
void ReportUnusable(mozilla::net::NetAddr *addr);
|
||||
|
||||
private:
|
||||
friend class nsHostResolver;
|
||||
|
@ -238,7 +239,7 @@ private:
|
|||
nsresult Init();
|
||||
nsresult IssueLookup(nsHostRecord *);
|
||||
bool GetHostToLookup(nsHostRecord **m);
|
||||
void OnLookupComplete(nsHostRecord *, nsresult, PRAddrInfo *);
|
||||
void OnLookupComplete(nsHostRecord *, nsresult, mozilla::net::AddrInfo *);
|
||||
void DeQueue(PRCList &aQ, nsHostRecord **aResult);
|
||||
void ClearPendingQueue(PRCList *aPendingQueue);
|
||||
nsresult ConditionallyCreateThread(nsHostRecord *rec);
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
native PRNetAddr(union PRNetAddr);
|
||||
%{ C++
|
||||
#include "mozilla/net/DNS.h"
|
||||
%}
|
||||
native NetAddr(mozilla::net::NetAddr);
|
||||
|
||||
/**
|
||||
* nsIDNSRecord
|
||||
|
@ -14,7 +17,7 @@ native PRNetAddr(union PRNetAddr);
|
|||
* like an enumerator, allowing the caller to easily step through the
|
||||
* list of IP addresses.
|
||||
*/
|
||||
[scriptable, uuid(ead9e9d8-7eef-4dae-a7f0-a1edcfb20478)]
|
||||
[scriptable, uuid(67E6CF03-12C7-4AF4-AE5F-AE362C7AF8FF)]
|
||||
interface nsIDNSRecord : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -27,15 +30,15 @@ interface nsIDNSRecord : nsISupports
|
|||
|
||||
/**
|
||||
* this function copies the value of the next IP address into the
|
||||
* given PRNetAddr struct and increments the internal address iterator.
|
||||
* given NetAddr struct and increments the internal address iterator.
|
||||
*
|
||||
* @param aPort
|
||||
* A port number to initialize the PRNetAddr with.
|
||||
* A port number to initialize the NetAddr with.
|
||||
*
|
||||
* @throws NS_ERROR_NOT_AVAILABLE if there is not another IP address in
|
||||
* the record.
|
||||
*/
|
||||
[noscript] PRNetAddr getNextAddr(in uint16_t aPort);
|
||||
[noscript] NetAddr getNextAddr(in uint16_t aPort);
|
||||
|
||||
/**
|
||||
* this function returns the value of the next IP address as a
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "ipc/IPCMessageUtils.h"
|
||||
#include "nsStringGlue.h"
|
||||
#include "prio.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
namespace IPC {
|
||||
|
||||
|
@ -85,24 +86,24 @@ struct ParamTraits<Permission>
|
|||
};
|
||||
|
||||
template<>
|
||||
struct ParamTraits<PRNetAddr>
|
||||
struct ParamTraits<mozilla::net::NetAddr>
|
||||
{
|
||||
static void Write(Message* aMsg, const PRNetAddr &aParam)
|
||||
static void Write(Message* aMsg, const mozilla::net::NetAddr &aParam)
|
||||
{
|
||||
WriteParam(aMsg, aParam.raw.family);
|
||||
if (aParam.raw.family == PR_AF_UNSPEC) {
|
||||
if (aParam.raw.family == AF_UNSPEC) {
|
||||
aMsg->WriteBytes(aParam.raw.data, sizeof(aParam.raw.data));
|
||||
} else if (aParam.raw.family == PR_AF_INET) {
|
||||
} else if (aParam.raw.family == AF_INET) {
|
||||
WriteParam(aMsg, aParam.inet.port);
|
||||
WriteParam(aMsg, aParam.inet.ip);
|
||||
} else if (aParam.raw.family == PR_AF_INET6) {
|
||||
WriteParam(aMsg, aParam.ipv6.port);
|
||||
WriteParam(aMsg, aParam.ipv6.flowinfo);
|
||||
WriteParam(aMsg, aParam.ipv6.ip.pr_s6_addr64[0]);
|
||||
WriteParam(aMsg, aParam.ipv6.ip.pr_s6_addr64[1]);
|
||||
WriteParam(aMsg, aParam.ipv6.scope_id);
|
||||
} else if (aParam.raw.family == AF_INET6) {
|
||||
WriteParam(aMsg, aParam.inet6.port);
|
||||
WriteParam(aMsg, aParam.inet6.flowinfo);
|
||||
WriteParam(aMsg, aParam.inet6.ip.u64[0]);
|
||||
WriteParam(aMsg, aParam.inet6.ip.u64[1]);
|
||||
WriteParam(aMsg, aParam.inet6.scope_id);
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
} else if (aParam.raw.family == PR_AF_LOCAL) {
|
||||
} else if (aParam.raw.family == AF_LOCAL) {
|
||||
// Train's already off the rails: let's get a stack trace at least...
|
||||
NS_RUNTIMEABORT("Error: please post stack trace to "
|
||||
"https://bugzilla.mozilla.org/show_bug.cgi?id=661158");
|
||||
|
@ -114,26 +115,26 @@ struct ParamTraits<PRNetAddr>
|
|||
* we can do but let the deserializer fail when it gets this message */
|
||||
}
|
||||
|
||||
static bool Read(const Message* aMsg, void** aIter, PRNetAddr* aResult)
|
||||
static bool Read(const Message* aMsg, void** aIter, mozilla::net::NetAddr* aResult)
|
||||
{
|
||||
if (!ReadParam(aMsg, aIter, &aResult->raw.family))
|
||||
return false;
|
||||
|
||||
if (aResult->raw.family == PR_AF_UNSPEC) {
|
||||
if (aResult->raw.family == AF_UNSPEC) {
|
||||
return aMsg->ReadBytes(aIter,
|
||||
reinterpret_cast<const char**>(&aResult->raw.data),
|
||||
sizeof(aResult->raw.data));
|
||||
} else if (aResult->raw.family == PR_AF_INET) {
|
||||
} else if (aResult->raw.family == AF_INET) {
|
||||
return ReadParam(aMsg, aIter, &aResult->inet.port) &&
|
||||
ReadParam(aMsg, aIter, &aResult->inet.ip);
|
||||
} else if (aResult->raw.family == PR_AF_INET6) {
|
||||
return ReadParam(aMsg, aIter, &aResult->ipv6.port) &&
|
||||
ReadParam(aMsg, aIter, &aResult->ipv6.flowinfo) &&
|
||||
ReadParam(aMsg, aIter, &aResult->ipv6.ip.pr_s6_addr64[0]) &&
|
||||
ReadParam(aMsg, aIter, &aResult->ipv6.ip.pr_s6_addr64[1]) &&
|
||||
ReadParam(aMsg, aIter, &aResult->ipv6.scope_id);
|
||||
} else if (aResult->raw.family == AF_INET6) {
|
||||
return ReadParam(aMsg, aIter, &aResult->inet6.port) &&
|
||||
ReadParam(aMsg, aIter, &aResult->inet6.flowinfo) &&
|
||||
ReadParam(aMsg, aIter, &aResult->inet6.ip.u64[0]) &&
|
||||
ReadParam(aMsg, aIter, &aResult->inet6.ip.u64[1]) &&
|
||||
ReadParam(aMsg, aIter, &aResult->inet6.scope_id);
|
||||
#if defined(XP_UNIX) || defined(XP_OS2)
|
||||
} else if (aResult->raw.family == PR_AF_LOCAL) {
|
||||
} else if (aResult->raw.family == AF_LOCAL) {
|
||||
return aMsg->ReadBytes(aIter,
|
||||
reinterpret_cast<const char**>(&aResult->local.path),
|
||||
sizeof(aResult->local.path));
|
||||
|
|
|
@ -42,6 +42,8 @@ extern PRLogModuleInfo* gFTPLog;
|
|||
#define LOG(args) PR_LOG(gFTPLog, PR_LOG_DEBUG, args)
|
||||
#define LOG_ALWAYS(args) PR_LOG(gFTPLog, PR_LOG_ALWAYS, args)
|
||||
|
||||
using namespace mozilla::net;
|
||||
|
||||
// remove FTP parameters (starting with ";") from the path
|
||||
static void
|
||||
removeParamsFromPath(nsCString& path)
|
||||
|
@ -1292,7 +1294,9 @@ nsFtpState::S_pasv() {
|
|||
if (!mAddressChecked) {
|
||||
// Find socket address
|
||||
mAddressChecked = true;
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, 0, &mServerAddress);
|
||||
mServerAddress.raw.family = AF_INET;
|
||||
mServerAddress.inet.ip = htonl(INADDR_ANY);
|
||||
mServerAddress.inet.port = htons(0);
|
||||
|
||||
nsITransport *controlSocket = mControlConnection->Transport();
|
||||
if (!controlSocket)
|
||||
|
@ -1304,9 +1308,9 @@ nsFtpState::S_pasv() {
|
|||
if (sTrans) {
|
||||
nsresult rv = sTrans->GetPeerAddr(&mServerAddress);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (!PR_IsNetAddrType(&mServerAddress, PR_IpAddrAny))
|
||||
mServerIsIPv6 = mServerAddress.raw.family == PR_AF_INET6 &&
|
||||
!PR_IsNetAddrType(&mServerAddress, PR_IpAddrV4Mapped);
|
||||
if (!IsIPAddrAny(&mServerAddress))
|
||||
mServerIsIPv6 = (mServerAddress.raw.family == AF_INET6) &&
|
||||
!IsIPAddrV4Mapped(&mServerAddress);
|
||||
else {
|
||||
/*
|
||||
* In case of SOCKS5 remote DNS resolution, we do
|
||||
|
@ -1315,12 +1319,11 @@ nsFtpState::S_pasv() {
|
|||
* socks server should also be IPv6, and this is the
|
||||
* self address of the transport.
|
||||
*/
|
||||
PRNetAddr selfAddress;
|
||||
NetAddr selfAddress;
|
||||
rv = sTrans->GetSelfAddr(&selfAddress);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mServerIsIPv6 = selfAddress.raw.family == PR_AF_INET6
|
||||
&& !PR_IsNetAddrType(&selfAddress,
|
||||
PR_IpAddrV4Mapped);
|
||||
mServerIsIPv6 = (selfAddress.raw.family == AF_INET6) &&
|
||||
!IsIPAddrV4Mapped(&selfAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1446,9 +1449,9 @@ nsFtpState::R_pasv() {
|
|||
nsCOMPtr<nsISocketTransport> strans;
|
||||
|
||||
nsAutoCString host;
|
||||
if (!PR_IsNetAddrType(&mServerAddress, PR_IpAddrAny)) {
|
||||
char buf[64];
|
||||
PR_NetAddrToString(&mServerAddress, buf, sizeof(buf));
|
||||
if (!IsIPAddrAny(&mServerAddress)) {
|
||||
char buf[kIPv6CStrBufSize];
|
||||
NetAddrToString(&mServerAddress, buf, sizeof(buf));
|
||||
host.Assign(buf);
|
||||
} else {
|
||||
/*
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "nsIPrompt.h"
|
||||
#include "nsITransport.h"
|
||||
#include "nsIProxyInfo.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
#include "nsFtpControlConnection.h"
|
||||
|
||||
|
@ -258,7 +259,7 @@ private:
|
|||
|
||||
static uint32_t mSessionStartTime;
|
||||
|
||||
PRNetAddr mServerAddress;
|
||||
mozilla::net::NetAddr mServerAddress;
|
||||
|
||||
// ***** control read gvars
|
||||
nsresult mControlStatus;
|
||||
|
|
|
@ -1274,8 +1274,8 @@ HttpBaseChannel::GetLocalAddress(nsACString& addr)
|
|||
if (mSelfAddr.raw.family == PR_AF_UNSPEC)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
addr.SetCapacity(64);
|
||||
PR_NetAddrToString(&mSelfAddr, addr.BeginWriting(), 64);
|
||||
addr.SetCapacity(kIPv6CStrBufSize);
|
||||
NetAddrToString(&mSelfAddr, addr.BeginWriting(), kIPv6CStrBufSize);
|
||||
addr.SetLength(strlen(addr.BeginReading()));
|
||||
|
||||
return NS_OK;
|
||||
|
@ -1287,10 +1287,10 @@ HttpBaseChannel::GetLocalPort(int32_t* port)
|
|||
NS_ENSURE_ARG_POINTER(port);
|
||||
|
||||
if (mSelfAddr.raw.family == PR_AF_INET) {
|
||||
*port = (int32_t)PR_ntohs(mSelfAddr.inet.port);
|
||||
*port = (int32_t)ntohs(mSelfAddr.inet.port);
|
||||
}
|
||||
else if (mSelfAddr.raw.family == PR_AF_INET6) {
|
||||
*port = (int32_t)PR_ntohs(mSelfAddr.ipv6.port);
|
||||
*port = (int32_t)ntohs(mSelfAddr.inet6.port);
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
@ -1304,8 +1304,8 @@ HttpBaseChannel::GetRemoteAddress(nsACString& addr)
|
|||
if (mPeerAddr.raw.family == PR_AF_UNSPEC)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
addr.SetCapacity(64);
|
||||
PR_NetAddrToString(&mPeerAddr, addr.BeginWriting(), 64);
|
||||
addr.SetCapacity(kIPv6CStrBufSize);
|
||||
NetAddrToString(&mPeerAddr, addr.BeginWriting(), kIPv6CStrBufSize);
|
||||
addr.SetLength(strlen(addr.BeginReading()));
|
||||
|
||||
return NS_OK;
|
||||
|
@ -1317,10 +1317,10 @@ HttpBaseChannel::GetRemotePort(int32_t* port)
|
|||
NS_ENSURE_ARG_POINTER(port);
|
||||
|
||||
if (mPeerAddr.raw.family == PR_AF_INET) {
|
||||
*port = (int32_t)PR_ntohs(mPeerAddr.inet.port);
|
||||
*port = (int32_t)ntohs(mPeerAddr.inet.port);
|
||||
}
|
||||
else if (mPeerAddr.raw.family == PR_AF_INET6) {
|
||||
*port = (int32_t)PR_ntohs(mPeerAddr.ipv6.port);
|
||||
*port = (int32_t)ntohs(mPeerAddr.inet6.port);
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "mozilla/net/NeckoCommon.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "PrivateBrowsingChannel.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
@ -188,8 +189,8 @@ public:
|
|||
nsHttpResponseHead * GetResponseHead() const { return mResponseHead; }
|
||||
nsHttpRequestHead * GetRequestHead() { return &mRequestHead; }
|
||||
|
||||
const PRNetAddr& GetSelfAddr() { return mSelfAddr; }
|
||||
const PRNetAddr& GetPeerAddr() { return mPeerAddr; }
|
||||
const NetAddr& GetSelfAddr() { return mSelfAddr; }
|
||||
const NetAddr& GetPeerAddr() { return mPeerAddr; }
|
||||
|
||||
public: /* Necko internal use only... */
|
||||
|
||||
|
@ -243,8 +244,8 @@ protected:
|
|||
nsCString mContentCharsetHint;
|
||||
nsCString mUserSetCookieHeader;
|
||||
|
||||
PRNetAddr mSelfAddr;
|
||||
PRNetAddr mPeerAddr;
|
||||
NetAddr mSelfAddr;
|
||||
NetAddr mPeerAddr;
|
||||
|
||||
// HTTP Upgrade Data
|
||||
nsCString mUpgradeProtocol;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "base/compiler_specific.h"
|
||||
#include "mozilla/ipc/InputStreamUtils.h"
|
||||
#include "mozilla/ipc/URIUtils.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
using namespace mozilla::ipc;
|
||||
|
@ -173,8 +174,8 @@ class StartRequestEvent : public ChannelEvent
|
|||
const uint32_t& cacheExpirationTime,
|
||||
const nsCString& cachedCharset,
|
||||
const nsCString& securityInfoSerialization,
|
||||
const PRNetAddr& selfAddr,
|
||||
const PRNetAddr& peerAddr)
|
||||
const NetAddr& selfAddr,
|
||||
const NetAddr& peerAddr)
|
||||
: mChild(child)
|
||||
, mResponseHead(responseHead)
|
||||
, mRequestHeaders(requestHeaders)
|
||||
|
@ -205,8 +206,8 @@ class StartRequestEvent : public ChannelEvent
|
|||
uint32_t mCacheExpirationTime;
|
||||
nsCString mCachedCharset;
|
||||
nsCString mSecurityInfoSerialization;
|
||||
PRNetAddr mSelfAddr;
|
||||
PRNetAddr mPeerAddr;
|
||||
NetAddr mSelfAddr;
|
||||
NetAddr mPeerAddr;
|
||||
};
|
||||
|
||||
bool
|
||||
|
@ -218,8 +219,8 @@ HttpChannelChild::RecvOnStartRequest(const nsHttpResponseHead& responseHead,
|
|||
const uint32_t& cacheExpirationTime,
|
||||
const nsCString& cachedCharset,
|
||||
const nsCString& securityInfoSerialization,
|
||||
const PRNetAddr& selfAddr,
|
||||
const PRNetAddr& peerAddr)
|
||||
const NetAddr& selfAddr,
|
||||
const NetAddr& peerAddr)
|
||||
{
|
||||
if (mEventQ.ShouldEnqueue()) {
|
||||
mEventQ.Enqueue(new StartRequestEvent(this, responseHead, useResponseHead,
|
||||
|
@ -245,8 +246,8 @@ HttpChannelChild::OnStartRequest(const nsHttpResponseHead& responseHead,
|
|||
const uint32_t& cacheExpirationTime,
|
||||
const nsCString& cachedCharset,
|
||||
const nsCString& securityInfoSerialization,
|
||||
const PRNetAddr& selfAddr,
|
||||
const PRNetAddr& peerAddr)
|
||||
const NetAddr& selfAddr,
|
||||
const NetAddr& peerAddr)
|
||||
{
|
||||
LOG(("HttpChannelChild::RecvOnStartRequest [this=%x]\n", this));
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsIAssociatedContentSecurity.h"
|
||||
#include "nsIChildChannel.h"
|
||||
#include "nsIHttpChannelChild.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
@ -97,8 +98,8 @@ protected:
|
|||
const uint32_t& cacheExpirationTime,
|
||||
const nsCString& cachedCharset,
|
||||
const nsCString& securityInfoSerialization,
|
||||
const PRNetAddr& selfAddr,
|
||||
const PRNetAddr& peerAddr);
|
||||
const mozilla::net::NetAddr& selfAddr,
|
||||
const mozilla::net::NetAddr& peerAddr);
|
||||
bool RecvOnTransportAndData(const nsresult& status,
|
||||
const uint64_t& progress,
|
||||
const uint64_t& progressMax,
|
||||
|
@ -151,8 +152,8 @@ private:
|
|||
const uint32_t& cacheExpirationTime,
|
||||
const nsCString& cachedCharset,
|
||||
const nsCString& securityInfoSerialization,
|
||||
const PRNetAddr& selfAddr,
|
||||
const PRNetAddr& peerAddr);
|
||||
const mozilla::net::NetAddr& selfAddr,
|
||||
const mozilla::net::NetAddr& peerAddr);
|
||||
void OnTransportAndData(const nsresult& status,
|
||||
const uint64_t progress,
|
||||
const uint64_t& progressMax,
|
||||
|
|
|
@ -13,13 +13,14 @@ include protocol PBlob; //FIXME: bug #792908
|
|||
|
||||
include "mozilla/net/PHttpChannelParams.h";
|
||||
include "mozilla/net/NeckoMessageUtils.h";
|
||||
include "mozilla/net/DNS.h";
|
||||
include "prio.h";
|
||||
|
||||
using RequestHeaderTuples;
|
||||
using nsHttpHeaderArray;
|
||||
using nsHttpResponseHead;
|
||||
using nsHttpAtom;
|
||||
using PRNetAddr;
|
||||
using mozilla::net::NetAddr;
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
@ -102,8 +103,8 @@ child:
|
|||
uint32_t cacheExpirationTime,
|
||||
nsCString cachedCharset,
|
||||
nsCString securityInfoSerialization,
|
||||
PRNetAddr selfAddr,
|
||||
PRNetAddr peerAddr);
|
||||
NetAddr selfAddr,
|
||||
NetAddr peerAddr);
|
||||
|
||||
// Combines a single OnDataAvailable and its associated OnProgress &
|
||||
// OnStatus calls into one IPDL message
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "nsNetCID.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
|
@ -2838,11 +2839,11 @@ nsHttpConnectionMgr::nsHalfOpenSocket::OnTransportStatus(nsITransport *trans,
|
|||
!mEnt->mConnInfo->UsingProxy() &&
|
||||
mEnt->mCoalescingKey.IsEmpty()) {
|
||||
|
||||
PRNetAddr addr;
|
||||
NetAddr addr;
|
||||
nsresult rv = mSocketTransport->GetPeerAddr(&addr);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mEnt->mCoalescingKey.SetCapacity(72);
|
||||
PR_NetAddrToString(&addr, mEnt->mCoalescingKey.BeginWriting(), 64);
|
||||
mEnt->mCoalescingKey.SetCapacity(kIPv6CStrBufSize + 26);
|
||||
NetAddrToString(&addr, mEnt->mCoalescingKey.BeginWriting(), kIPv6CStrBufSize);
|
||||
mEnt->mCoalescingKey.SetLength(
|
||||
strlen(mEnt->mCoalescingKey.BeginReading()));
|
||||
|
||||
|
|
|
@ -6,12 +6,15 @@
|
|||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[ptr] native PRNetAddrPtr(union PRNetAddr);
|
||||
%{ C++
|
||||
#include "mozilla/net/DNS.h"
|
||||
%}
|
||||
[ptr] native NetAddrPtr(mozilla::net::NetAddr);
|
||||
|
||||
[scriptable, uuid(8f755c44-1dd2-11b2-a613-91117453fa95)]
|
||||
[scriptable, uuid(D5C0D1F9-22D7-47DC-BF91-D9AC6E1251A6)]
|
||||
interface nsISOCKSSocketInfo : nsISupports
|
||||
{
|
||||
[noscript] attribute PRNetAddrPtr destinationAddr;
|
||||
[noscript] attribute PRNetAddrPtr externalProxyAddr;
|
||||
[noscript] attribute PRNetAddrPtr internalProxyAddr;
|
||||
[noscript] attribute NetAddrPtr destinationAddr;
|
||||
[noscript] attribute NetAddrPtr externalProxyAddr;
|
||||
[noscript] attribute NetAddrPtr internalProxyAddr;
|
||||
};
|
||||
|
|
|
@ -19,9 +19,12 @@
|
|||
#include "nsIDNSListener.h"
|
||||
#include "nsICancelable.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/net/DNS.h"
|
||||
|
||||
static PRDescIdentity nsSOCKSIOLayerIdentity;
|
||||
static PRIOMethods nsSOCKSIOLayerMethods;
|
||||
using namespace mozilla::net;
|
||||
|
||||
static PRDescIdentity nsSOCKSIOLayerIdentity;
|
||||
static PRIOMethods nsSOCKSIOLayerMethods;
|
||||
static bool firstTime = true;
|
||||
static bool ipv6Supported = true;
|
||||
|
||||
|
@ -84,7 +87,7 @@ private:
|
|||
void HandshakeFinished(PRErrorCode err = 0);
|
||||
PRStatus StartDNS(PRFileDesc *fd);
|
||||
PRStatus ConnectToProxy(PRFileDesc *fd);
|
||||
void FixupAddressFamily(PRFileDesc *fd, PRNetAddr *proxy);
|
||||
void FixupAddressFamily(PRFileDesc *fd, NetAddr *proxy);
|
||||
PRStatus ContinueConnectingToProxy(PRFileDesc *fd, int16_t oflags);
|
||||
PRStatus WriteV4ConnectRequest();
|
||||
PRStatus ReadV4ConnectResponse();
|
||||
|
@ -98,15 +101,15 @@ private:
|
|||
void WriteUint8(uint8_t d);
|
||||
void WriteUint16(uint16_t d);
|
||||
void WriteUint32(uint32_t d);
|
||||
void WriteNetAddr(const PRNetAddr *addr);
|
||||
void WriteNetPort(const PRNetAddr *addr);
|
||||
void WriteNetAddr(const NetAddr *addr);
|
||||
void WriteNetPort(const NetAddr *addr);
|
||||
void WriteString(const nsACString &str);
|
||||
|
||||
uint8_t ReadUint8();
|
||||
uint16_t ReadUint16();
|
||||
uint32_t ReadUint32();
|
||||
void ReadNetAddr(PRNetAddr *addr, uint16_t fam);
|
||||
void ReadNetPort(PRNetAddr *addr);
|
||||
void ReadNetAddr(NetAddr *addr, uint16_t fam);
|
||||
void ReadNetPort(NetAddr *addr);
|
||||
|
||||
void WantRead(uint32_t sz);
|
||||
PRStatus ReadFromSocket(PRFileDesc *fd);
|
||||
|
@ -130,9 +133,9 @@ private:
|
|||
int32_t mVersion; // SOCKS version 4 or 5
|
||||
int32_t mDestinationFamily;
|
||||
uint32_t mFlags;
|
||||
PRNetAddr mInternalProxyAddr;
|
||||
PRNetAddr mExternalProxyAddr;
|
||||
PRNetAddr mDestinationAddr;
|
||||
NetAddr mInternalProxyAddr;
|
||||
NetAddr mExternalProxyAddr;
|
||||
NetAddr mDestinationAddr;
|
||||
PRIntervalTime mTimeout;
|
||||
};
|
||||
|
||||
|
@ -144,14 +147,23 @@ nsSOCKSSocketInfo::nsSOCKSSocketInfo()
|
|||
, mAmountToRead(0)
|
||||
, mProxyPort(-1)
|
||||
, mVersion(-1)
|
||||
, mDestinationFamily(PR_AF_INET)
|
||||
, mDestinationFamily(AF_INET)
|
||||
, mFlags(0)
|
||||
, mTimeout(PR_INTERVAL_NO_TIMEOUT)
|
||||
{
|
||||
mData = new uint8_t[BUFFER_SIZE];
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, 0, &mInternalProxyAddr);
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, 0, &mExternalProxyAddr);
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, 0, &mDestinationAddr);
|
||||
|
||||
mInternalProxyAddr.raw.family = AF_INET;
|
||||
mInternalProxyAddr.inet.ip = htonl(INADDR_ANY);
|
||||
mInternalProxyAddr.inet.port = htons(0);
|
||||
|
||||
mExternalProxyAddr.raw.family = AF_INET;
|
||||
mExternalProxyAddr.inet.ip = htonl(INADDR_ANY);
|
||||
mExternalProxyAddr.inet.port = htons(0);
|
||||
|
||||
mDestinationAddr.raw.family = AF_INET;
|
||||
mDestinationAddr.inet.ip = htonl(INADDR_ANY);
|
||||
mDestinationAddr.inet.port = htons(0);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -168,44 +180,44 @@ nsSOCKSSocketInfo::Init(int32_t version, int32_t family, const char *proxyHost,
|
|||
NS_IMPL_THREADSAFE_ISUPPORTS2(nsSOCKSSocketInfo, nsISOCKSSocketInfo, nsIDNSListener)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSOCKSSocketInfo::GetExternalProxyAddr(PRNetAddr * *aExternalProxyAddr)
|
||||
nsSOCKSSocketInfo::GetExternalProxyAddr(NetAddr * *aExternalProxyAddr)
|
||||
{
|
||||
memcpy(*aExternalProxyAddr, &mExternalProxyAddr, sizeof(PRNetAddr));
|
||||
memcpy(*aExternalProxyAddr, &mExternalProxyAddr, sizeof(NetAddr));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSOCKSSocketInfo::SetExternalProxyAddr(PRNetAddr *aExternalProxyAddr)
|
||||
nsSOCKSSocketInfo::SetExternalProxyAddr(NetAddr *aExternalProxyAddr)
|
||||
{
|
||||
memcpy(&mExternalProxyAddr, aExternalProxyAddr, sizeof(PRNetAddr));
|
||||
memcpy(&mExternalProxyAddr, aExternalProxyAddr, sizeof(NetAddr));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSOCKSSocketInfo::GetDestinationAddr(PRNetAddr * *aDestinationAddr)
|
||||
nsSOCKSSocketInfo::GetDestinationAddr(NetAddr * *aDestinationAddr)
|
||||
{
|
||||
memcpy(*aDestinationAddr, &mDestinationAddr, sizeof(PRNetAddr));
|
||||
memcpy(*aDestinationAddr, &mDestinationAddr, sizeof(NetAddr));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSOCKSSocketInfo::SetDestinationAddr(PRNetAddr *aDestinationAddr)
|
||||
nsSOCKSSocketInfo::SetDestinationAddr(NetAddr *aDestinationAddr)
|
||||
{
|
||||
memcpy(&mDestinationAddr, aDestinationAddr, sizeof(PRNetAddr));
|
||||
memcpy(&mDestinationAddr, aDestinationAddr, sizeof(NetAddr));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSOCKSSocketInfo::GetInternalProxyAddr(PRNetAddr * *aInternalProxyAddr)
|
||||
nsSOCKSSocketInfo::GetInternalProxyAddr(NetAddr * *aInternalProxyAddr)
|
||||
{
|
||||
memcpy(*aInternalProxyAddr, &mInternalProxyAddr, sizeof(PRNetAddr));
|
||||
memcpy(*aInternalProxyAddr, &mInternalProxyAddr, sizeof(NetAddr));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSOCKSSocketInfo::SetInternalProxyAddr(PRNetAddr *aInternalProxyAddr)
|
||||
nsSOCKSSocketInfo::SetInternalProxyAddr(NetAddr *aInternalProxyAddr)
|
||||
{
|
||||
memcpy(&mInternalProxyAddr, aInternalProxyAddr, sizeof(PRNetAddr));
|
||||
memcpy(&mInternalProxyAddr, aInternalProxyAddr, sizeof(NetAddr));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -297,7 +309,7 @@ nsSOCKSSocketInfo::ConnectToProxy(PRFileDesc *fd)
|
|||
|
||||
// Try socks5 if the destination addrress is IPv6
|
||||
if (mVersion == 4 &&
|
||||
PR_NetAddrFamily(&mDestinationAddr) == PR_AF_INET6) {
|
||||
mDestinationAddr.raw.family == AF_INET6) {
|
||||
mVersion = 5;
|
||||
}
|
||||
|
||||
|
@ -315,14 +327,16 @@ nsSOCKSSocketInfo::ConnectToProxy(PRFileDesc *fd)
|
|||
}
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
char buf[64];
|
||||
PR_NetAddrToString(&mInternalProxyAddr, buf, sizeof(buf));
|
||||
char buf[kIPv6CStrBufSize];
|
||||
NetAddrToString(&mInternalProxyAddr, buf, sizeof(buf));
|
||||
LOGDEBUG(("socks: trying proxy server, %s:%hu",
|
||||
buf, PR_ntohs(PR_NetAddrInetPort(&mInternalProxyAddr))));
|
||||
buf, ntohs(mInternalProxyAddr.inet.port)));
|
||||
#endif
|
||||
PRNetAddr proxy = mInternalProxyAddr;
|
||||
NetAddr proxy = mInternalProxyAddr;
|
||||
FixupAddressFamily(fd, &proxy);
|
||||
status = fd->lower->methods->connect(fd->lower, &proxy, mTimeout);
|
||||
PRNetAddr prProxy;
|
||||
NetAddrToPRNetAddr(&proxy, &prProxy);
|
||||
status = fd->lower->methods->connect(fd->lower, &prProxy, mTimeout);
|
||||
if (status != PR_SUCCESS) {
|
||||
PRErrorCode c = PR_GetError();
|
||||
// If EINPROGRESS, return now and check back later after polling
|
||||
|
@ -340,25 +354,25 @@ nsSOCKSSocketInfo::ConnectToProxy(PRFileDesc *fd)
|
|||
}
|
||||
|
||||
void
|
||||
nsSOCKSSocketInfo::FixupAddressFamily(PRFileDesc *fd, PRNetAddr *proxy)
|
||||
nsSOCKSSocketInfo::FixupAddressFamily(PRFileDesc *fd, NetAddr *proxy)
|
||||
{
|
||||
int32_t proxyFamily = PR_NetAddrFamily(&mInternalProxyAddr);
|
||||
int32_t proxyFamily = mInternalProxyAddr.raw.family;
|
||||
// Do nothing if the address family is already matched
|
||||
if (proxyFamily == mDestinationFamily) {
|
||||
return;
|
||||
}
|
||||
// If the system does not support IPv6 and the proxy address is IPv6,
|
||||
// We can do nothing here.
|
||||
if (proxyFamily == PR_AF_INET6 && !ipv6Supported) {
|
||||
if (proxyFamily == AF_INET6 && !ipv6Supported) {
|
||||
return;
|
||||
}
|
||||
// If the system does not support IPv6 and the destination address is
|
||||
// IPv6, convert IPv4 address to IPv4-mapped IPv6 address to satisfy
|
||||
// the emulation layer
|
||||
if (mDestinationFamily == PR_AF_INET6 && !ipv6Supported) {
|
||||
proxy->ipv6.family = PR_AF_INET6;
|
||||
proxy->ipv6.port = mInternalProxyAddr.inet.port;
|
||||
uint8_t *proxyp = proxy->ipv6.ip.pr_s6_addr;
|
||||
if (mDestinationFamily == AF_INET6 && !ipv6Supported) {
|
||||
proxy->inet6.family = AF_INET6;
|
||||
proxy->inet6.port = mInternalProxyAddr.inet.port;
|
||||
uint8_t *proxyp = proxy->inet6.ip.u8;
|
||||
memset(proxyp, 0, 10);
|
||||
memset(proxyp + 10, 0xff, 2);
|
||||
memcpy(proxyp + 12,(char *) &mInternalProxyAddr.inet.ip, 4);
|
||||
|
@ -424,7 +438,7 @@ nsSOCKSSocketInfo::ContinueConnectingToProxy(PRFileDesc *fd, int16_t oflags)
|
|||
PRStatus
|
||||
nsSOCKSSocketInfo::WriteV4ConnectRequest()
|
||||
{
|
||||
PRNetAddr *addr = &mDestinationAddr;
|
||||
NetAddr *addr = &mDestinationAddr;
|
||||
int32_t proxy_resolve;
|
||||
|
||||
NS_ABORT_IF_FALSE(mState == SOCKS_CONNECTING_TO_PROXY,
|
||||
|
@ -448,7 +462,7 @@ nsSOCKSSocketInfo::WriteV4ConnectRequest()
|
|||
// four bytes set to 0 and the last byte set to something other
|
||||
// than 0, is used to notify the proxy that this is a SOCKS 4a
|
||||
// request. This request type works for Tor and perhaps others.
|
||||
WriteUint32(PR_htonl(0x00000001)); // Fake IP
|
||||
WriteUint32(htonl(0x00000001)); // Fake IP
|
||||
WriteUint8(0x00); // Send an emtpy username
|
||||
if (mDestinationHost.Length() > MAX_HOSTNAME_LEN) {
|
||||
LOGERROR(("socks4: destination host name is too long!"));
|
||||
|
@ -457,10 +471,10 @@ nsSOCKSSocketInfo::WriteV4ConnectRequest()
|
|||
}
|
||||
WriteString(mDestinationHost); // Hostname
|
||||
WriteUint8(0x00);
|
||||
} else if (PR_NetAddrFamily(addr) == PR_AF_INET) {
|
||||
} else if (addr->raw.family == AF_INET) {
|
||||
WriteNetAddr(addr); // Add the IPv4 address
|
||||
WriteUint8(0x00); // Send an emtpy username
|
||||
} else if (PR_NetAddrFamily(addr) == PR_AF_INET6) {
|
||||
} else if (addr->raw.family == AF_INET6) {
|
||||
LOGERROR(("socks: SOCKS 4 can't handle IPv6 addresses!"));
|
||||
HandshakeFinished(PR_BAD_ADDRESS_ERROR);
|
||||
return PR_FAILURE;
|
||||
|
@ -544,7 +558,7 @@ PRStatus
|
|||
nsSOCKSSocketInfo::WriteV5ConnectRequest()
|
||||
{
|
||||
// Send SOCKS 5 connect request
|
||||
PRNetAddr *addr = &mDestinationAddr;
|
||||
NetAddr *addr = &mDestinationAddr;
|
||||
int32_t proxy_resolve;
|
||||
proxy_resolve = mFlags & nsISocketProvider::PROXY_RESOLVES_HOST;
|
||||
|
||||
|
@ -571,10 +585,10 @@ nsSOCKSSocketInfo::WriteV5ConnectRequest()
|
|||
WriteUint8(0x03); // addr type -- domainname
|
||||
WriteUint8(mDestinationHost.Length()); // name length
|
||||
WriteString(mDestinationHost);
|
||||
} else if (PR_NetAddrFamily(addr) == PR_AF_INET) {
|
||||
} else if (addr->raw.family == AF_INET) {
|
||||
WriteUint8(0x01); // addr type -- IPv4
|
||||
WriteNetAddr(addr);
|
||||
} else if (PR_NetAddrFamily(addr) == PR_AF_INET6) {
|
||||
} else if (addr->raw.family == AF_INET6) {
|
||||
WriteUint8(0x04); // addr type -- IPv6
|
||||
WriteNetAddr(addr);
|
||||
} else {
|
||||
|
@ -718,14 +732,14 @@ nsSOCKSSocketInfo::ReadV5ConnectResponseBottom()
|
|||
// Read what the proxy says is our source address
|
||||
switch (type) {
|
||||
case 0x01: // ipv4
|
||||
ReadNetAddr(&mExternalProxyAddr, PR_AF_INET);
|
||||
ReadNetAddr(&mExternalProxyAddr, AF_INET);
|
||||
break;
|
||||
case 0x04: // ipv6
|
||||
ReadNetAddr(&mExternalProxyAddr, PR_AF_INET6);
|
||||
ReadNetAddr(&mExternalProxyAddr, AF_INET6);
|
||||
break;
|
||||
case 0x03: // fqdn (skip)
|
||||
mReadOffset += len;
|
||||
mExternalProxyAddr.raw.family = PR_AF_INET;
|
||||
mExternalProxyAddr.raw.family = AF_INET;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -865,17 +879,17 @@ nsSOCKSSocketInfo::WriteUint32(uint32_t v)
|
|||
}
|
||||
|
||||
void
|
||||
nsSOCKSSocketInfo::WriteNetAddr(const PRNetAddr *addr)
|
||||
nsSOCKSSocketInfo::WriteNetAddr(const NetAddr *addr)
|
||||
{
|
||||
const char *ip = NULL;
|
||||
uint32_t len = 0;
|
||||
|
||||
if (PR_NetAddrFamily(addr) == PR_AF_INET) {
|
||||
if (addr->raw.family == AF_INET) {
|
||||
ip = (const char*)&addr->inet.ip;
|
||||
len = sizeof(addr->inet.ip);
|
||||
} else if (PR_NetAddrFamily(addr) == PR_AF_INET6) {
|
||||
ip = (const char*)addr->ipv6.ip.pr_s6_addr;
|
||||
len = sizeof(addr->ipv6.ip.pr_s6_addr);
|
||||
} else if (addr->raw.family == AF_INET6) {
|
||||
ip = (const char*)addr->inet6.ip.u8;
|
||||
len = sizeof(addr->inet6.ip.u8);
|
||||
}
|
||||
|
||||
NS_ABORT_IF_FALSE(ip != NULL, "Unknown address");
|
||||
|
@ -887,9 +901,9 @@ nsSOCKSSocketInfo::WriteNetAddr(const PRNetAddr *addr)
|
|||
}
|
||||
|
||||
void
|
||||
nsSOCKSSocketInfo::WriteNetPort(const PRNetAddr *addr)
|
||||
nsSOCKSSocketInfo::WriteNetPort(const NetAddr *addr)
|
||||
{
|
||||
WriteUint16(PR_NetAddrInetPort(addr));
|
||||
WriteUint16(addr->inet.port);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -935,29 +949,29 @@ nsSOCKSSocketInfo::ReadUint32()
|
|||
}
|
||||
|
||||
void
|
||||
nsSOCKSSocketInfo::ReadNetAddr(PRNetAddr *addr, uint16_t fam)
|
||||
nsSOCKSSocketInfo::ReadNetAddr(NetAddr *addr, uint16_t fam)
|
||||
{
|
||||
uint32_t amt = 0;
|
||||
const uint8_t *ip = mData + mReadOffset;
|
||||
|
||||
addr->raw.family = fam;
|
||||
if (fam == PR_AF_INET) {
|
||||
if (fam == AF_INET) {
|
||||
amt = sizeof(addr->inet.ip);
|
||||
NS_ABORT_IF_FALSE(mReadOffset + amt <= mDataLength,
|
||||
"Not enough space to pop an ipv4 addr!");
|
||||
memcpy(&addr->inet.ip, ip, amt);
|
||||
} else if (fam == PR_AF_INET6) {
|
||||
amt = sizeof(addr->ipv6.ip.pr_s6_addr);
|
||||
} else if (fam == AF_INET6) {
|
||||
amt = sizeof(addr->inet6.ip.u8);
|
||||
NS_ABORT_IF_FALSE(mReadOffset + amt <= mDataLength,
|
||||
"Not enough space to pop an ipv6 addr!");
|
||||
memcpy(addr->ipv6.ip.pr_s6_addr, ip, amt);
|
||||
memcpy(addr->inet6.ip.u8, ip, amt);
|
||||
}
|
||||
|
||||
mReadOffset += amt;
|
||||
}
|
||||
|
||||
void
|
||||
nsSOCKSSocketInfo::ReadNetPort(PRNetAddr *addr)
|
||||
nsSOCKSSocketInfo::ReadNetPort(NetAddr *addr)
|
||||
{
|
||||
addr->inet.port = ReadUint16();
|
||||
}
|
||||
|
@ -1060,22 +1074,24 @@ static PRStatus
|
|||
nsSOCKSIOLayerConnect(PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime to)
|
||||
{
|
||||
PRStatus status;
|
||||
PRNetAddr dst;
|
||||
NetAddr dst;
|
||||
|
||||
nsSOCKSSocketInfo * info = (nsSOCKSSocketInfo*) fd->secret;
|
||||
if (info == NULL) return PR_FAILURE;
|
||||
|
||||
if (PR_NetAddrFamily(addr) == PR_AF_INET6 &&
|
||||
if (addr->raw.family == PR_AF_INET6 &&
|
||||
PR_IsNetAddrType(addr, PR_IpAddrV4Mapped)) {
|
||||
const uint8_t *srcp;
|
||||
|
||||
LOGDEBUG(("socks: converting ipv4-mapped ipv6 address to ipv4"));
|
||||
|
||||
// copied from _PR_ConvertToIpv4NetAddr()
|
||||
PR_InitializeNetAddr(PR_IpAddrAny, 0, &dst);
|
||||
dst.raw.family = AF_INET;
|
||||
dst.inet.ip = htonl(INADDR_ANY);
|
||||
dst.inet.port = htons(0);
|
||||
srcp = addr->ipv6.ip.pr_s6_addr;
|
||||
memcpy(&dst.inet.ip, srcp + 12, 4);
|
||||
dst.inet.family = PR_AF_INET;
|
||||
dst.inet.family = AF_INET;
|
||||
dst.inet.port = addr->ipv6.port;
|
||||
} else {
|
||||
memcpy(&dst, addr, sizeof(dst));
|
||||
|
@ -1163,8 +1179,12 @@ nsSOCKSIOLayerGetName(PRFileDesc *fd, PRNetAddr *addr)
|
|||
nsSOCKSSocketInfo * info = (nsSOCKSSocketInfo*) fd->secret;
|
||||
|
||||
if (info != NULL && addr != NULL) {
|
||||
if (info->GetExternalProxyAddr(&addr) == NS_OK)
|
||||
NetAddr temp;
|
||||
NetAddr *tempPtr = &temp;
|
||||
if (info->GetExternalProxyAddr(&tempPtr) == NS_OK) {
|
||||
NetAddrToPRNetAddr(tempPtr, addr);
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_FAILURE;
|
||||
|
@ -1176,8 +1196,12 @@ nsSOCKSIOLayerGetPeerName(PRFileDesc *fd, PRNetAddr *addr)
|
|||
nsSOCKSSocketInfo * info = (nsSOCKSSocketInfo*) fd->secret;
|
||||
|
||||
if (info != NULL && addr != NULL) {
|
||||
if (info->GetDestinationAddr(&addr) == NS_OK)
|
||||
NetAddr temp;
|
||||
NetAddr *tempPtr = &temp;
|
||||
if (info->GetDestinationAddr(&tempPtr) == NS_OK) {
|
||||
NetAddrToPRNetAddr(tempPtr, addr);
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_FAILURE;
|
||||
|
@ -1219,21 +1243,21 @@ nsSOCKSIOLayerAddToSocket(int32_t family,
|
|||
PR_Close(tmpfd);
|
||||
}
|
||||
|
||||
nsSOCKSIOLayerIdentity = PR_GetUniqueIdentity("SOCKS layer");
|
||||
nsSOCKSIOLayerMethods = *PR_GetDefaultIOMethods();
|
||||
nsSOCKSIOLayerIdentity = PR_GetUniqueIdentity("SOCKS layer");
|
||||
nsSOCKSIOLayerMethods = *PR_GetDefaultIOMethods();
|
||||
|
||||
nsSOCKSIOLayerMethods.connect = nsSOCKSIOLayerConnect;
|
||||
nsSOCKSIOLayerMethods.connectcontinue = nsSOCKSIOLayerConnectContinue;
|
||||
nsSOCKSIOLayerMethods.poll = nsSOCKSIOLayerPoll;
|
||||
nsSOCKSIOLayerMethods.bind = nsSOCKSIOLayerBind;
|
||||
nsSOCKSIOLayerMethods.connect = nsSOCKSIOLayerConnect;
|
||||
nsSOCKSIOLayerMethods.connectcontinue = nsSOCKSIOLayerConnectContinue;
|
||||
nsSOCKSIOLayerMethods.poll = nsSOCKSIOLayerPoll;
|
||||
nsSOCKSIOLayerMethods.bind = nsSOCKSIOLayerBind;
|
||||
nsSOCKSIOLayerMethods.acceptread = nsSOCKSIOLayerAcceptRead;
|
||||
nsSOCKSIOLayerMethods.getsockname = nsSOCKSIOLayerGetName;
|
||||
nsSOCKSIOLayerMethods.getpeername = nsSOCKSIOLayerGetPeerName;
|
||||
nsSOCKSIOLayerMethods.accept = nsSOCKSIOLayerAccept;
|
||||
nsSOCKSIOLayerMethods.listen = nsSOCKSIOLayerListen;
|
||||
nsSOCKSIOLayerMethods.close = nsSOCKSIOLayerClose;
|
||||
nsSOCKSIOLayerMethods.accept = nsSOCKSIOLayerAccept;
|
||||
nsSOCKSIOLayerMethods.listen = nsSOCKSIOLayerListen;
|
||||
nsSOCKSIOLayerMethods.close = nsSOCKSIOLayerClose;
|
||||
|
||||
firstTime = false;
|
||||
firstTime = false;
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
gSOCKSLog = PR_NewLogModule("SOCKS");
|
||||
|
@ -1243,8 +1267,8 @@ nsSOCKSIOLayerAddToSocket(int32_t family,
|
|||
|
||||
LOGDEBUG(("Entering nsSOCKSIOLayerAddToSocket()."));
|
||||
|
||||
PRFileDesc * layer;
|
||||
PRStatus rv;
|
||||
PRFileDesc *layer;
|
||||
PRStatus rv;
|
||||
|
||||
layer = PR_CreateIOLayerStub(nsSOCKSIOLayerIdentity, &nsSOCKSIOLayerMethods);
|
||||
if (! layer)
|
||||
|
|
Загрузка…
Ссылка в новой задаче