Bug 1296464 - Part 1 - Add init2 method to nsIUDPSocket to allow opening sockets on specific IPs. r=hurley

This commit is contained in:
Kannan Vijayan 2016-09-13 11:16:22 -04:00
Родитель 200e76f295
Коммит e40b66af93
2 изменённых файлов: 30 добавлений и 0 удалений

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

@ -57,6 +57,11 @@ interface nsIUDPSocket : nsISupports
in nsIPrincipal aPrincipal,
[optional] in boolean aAddressReuse);
[optional_argc] void init2(in AUTF8String aAddr,
in long aPort,
in nsIPrincipal aPrincipal,
[optional] in boolean aAddressReuse);
/**
* initWithAddress
*

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

@ -572,6 +572,31 @@ nsUDPSocket::Init(int32_t aPort, bool aLoopbackOnly, nsIPrincipal *aPrincipal,
return InitWithAddress(&addr, aPrincipal, aAddressReuse, aOptionalArgc);
}
NS_IMETHODIMP
nsUDPSocket::Init2(const nsACString& aAddr, int32_t aPort, nsIPrincipal *aPrincipal,
bool aAddressReuse, uint8_t aOptionalArgc)
{
if (NS_WARN_IF(aAddr.IsEmpty())) {
return NS_ERROR_INVALID_ARG;
}
PRNetAddr prAddr;
if (PR_StringToNetAddr(aAddr.BeginReading(), &prAddr) != PR_SUCCESS) {
return NS_ERROR_FAILURE;
}
NetAddr addr;
if (aPort < 0)
aPort = 0;
addr.raw.family = AF_INET;
addr.inet.port = htons(aPort);
addr.inet.ip = prAddr.inet.ip;
return InitWithAddress(&addr, aPrincipal, aAddressReuse, aOptionalArgc);
}
NS_IMETHODIMP
nsUDPSocket::InitWithAddress(const NetAddr *aAddr, nsIPrincipal *aPrincipal,
bool aAddressReuse, uint8_t aOptionalArgc)