зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1708116 - Add NetAddr::InitFromString r=necko-reviewers,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D98952
This commit is contained in:
Родитель
583024121b
Коммит
2487615b47
|
@ -198,6 +198,24 @@ bool NetAddr::IsIPAddrAny() const {
|
|||
|
||||
NetAddr::NetAddr(const PRNetAddr* prAddr) { PRNetAddrToNetAddr(prAddr, this); }
|
||||
|
||||
nsresult NetAddr::InitFromString(const nsACString& aString, uint16_t aPort) {
|
||||
PRNetAddr prAddr{};
|
||||
memset(&prAddr, 0, sizeof(PRNetAddr));
|
||||
if (PR_StringToNetAddr(PromiseFlatCString(aString).get(), &prAddr) !=
|
||||
PR_SUCCESS) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRNetAddrToNetAddr(&prAddr, this);
|
||||
|
||||
if (this->raw.family == PR_AF_INET) {
|
||||
this->inet.port = PR_htons(aPort);
|
||||
} else if (this->raw.family == PR_AF_INET6) {
|
||||
this->inet6.port = PR_htons(aPort);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool NetAddr::IsIPAddrV4() const { return this->raw.family == AF_INET; }
|
||||
|
||||
bool NetAddr::IsIPAddrV4Mapped() const {
|
||||
|
|
|
@ -140,6 +140,12 @@ union NetAddr {
|
|||
NetAddr() { memset(this, 0, sizeof(NetAddr)); }
|
||||
explicit NetAddr(const PRNetAddr* prAddr);
|
||||
|
||||
// Will parse aString into a NetAddr using PR_StringToNetAddr.
|
||||
// Returns an error code if parsing fails.
|
||||
// If aPort is non-0 will set the NetAddr's port to (the network endian
|
||||
// value of) that.
|
||||
nsresult InitFromString(const nsACString& aString, uint16_t aPort = 0);
|
||||
|
||||
bool IsIPAddrAny() const;
|
||||
bool IsLoopbackAddr() const;
|
||||
bool IsLoopBackAddressWithoutIPv6Mapping() const;
|
||||
|
|
Загрузка…
Ссылка в новой задаче