Fix IPAddress::ToSensitiveString() to avoid dependency on inet_ntop().
Previosly ToSesnsetiveString() wasn't working witn some implementations of inet_ntop(). Rewrote it to avoid that dependency. BUG=chromium:577344 R=pthatcher@webrtc.org, tommi@webrtc.org Review URL: https://codereview.webrtc.org/1584793004 . Cr-Commit-Position: refs/heads/master@{#11242}
This commit is contained in:
@ -28,8 +28,9 @@
|
|||||||
#include "webrtc/base/ipaddress.h"
|
#include "webrtc/base/ipaddress.h"
|
||||||
#include "webrtc/base/byteorder.h"
|
#include "webrtc/base/byteorder.h"
|
||||||
#include "webrtc/base/checks.h"
|
#include "webrtc/base/checks.h"
|
||||||
#include "webrtc/base/nethelpers.h"
|
|
||||||
#include "webrtc/base/logging.h"
|
#include "webrtc/base/logging.h"
|
||||||
|
#include "webrtc/base/nethelpers.h"
|
||||||
|
#include "webrtc/base/stringutils.h"
|
||||||
#include "webrtc/base/win32.h"
|
#include "webrtc/base/win32.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
@ -158,19 +159,16 @@ std::string IPAddress::ToSensitiveString() const {
|
|||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
case AF_INET6: {
|
case AF_INET6: {
|
||||||
// Remove the last 5 groups (80 bits).
|
std::string result;
|
||||||
std::string address = TruncateIP(*this, 128 - 80).ToString();
|
result.resize(INET6_ADDRSTRLEN);
|
||||||
|
in6_addr addr = ipv6_address();
|
||||||
// If all three remaining groups are written out explicitly in the string,
|
size_t len =
|
||||||
// remove one of the two trailing colons before appending the stripped
|
rtc::sprintfn(&(result[0]), result.size(), "%x:%x:%x:x:x:x:x:x",
|
||||||
// groups as "x"s. There should be max 4 colons (2 between the 3 groups +
|
(addr.s6_addr[0] << 8) + addr.s6_addr[1],
|
||||||
// 2 trailing) in the truncated address string.
|
(addr.s6_addr[2] << 8) + addr.s6_addr[3],
|
||||||
size_t number_of_colons = std::count(address.begin(), address.end(), ':');
|
(addr.s6_addr[4] << 8) + addr.s6_addr[5]);
|
||||||
RTC_CHECK_LE(number_of_colons, 4u);
|
result.resize(len);
|
||||||
if (number_of_colons > 3)
|
return result;
|
||||||
address.resize(address.length() - 1);
|
|
||||||
|
|
||||||
return address + "x:x:x:x:x";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::string();
|
return std::string();
|
||||||
|
@ -61,7 +61,7 @@ static const std::string kIPv6PublicAddr2String =
|
|||||||
static const std::string kIPv6PublicAddrAnonymizedString =
|
static const std::string kIPv6PublicAddrAnonymizedString =
|
||||||
"2401:fa00:4:x:x:x:x:x";
|
"2401:fa00:4:x:x:x:x:x";
|
||||||
static const std::string kIPv6PublicAddr2AnonymizedString =
|
static const std::string kIPv6PublicAddr2AnonymizedString =
|
||||||
"2401::x:x:x:x:x";
|
"2401:0:0:x:x:x:x:x";
|
||||||
static const std::string kIPv4MappedAnyAddrString = "::ffff:0:0";
|
static const std::string kIPv4MappedAnyAddrString = "::ffff:0:0";
|
||||||
static const std::string kIPv4MappedRFC1918AddrString = "::ffff:c0a8:701";
|
static const std::string kIPv4MappedRFC1918AddrString = "::ffff:c0a8:701";
|
||||||
static const std::string kIPv4MappedLoopbackAddrString = "::ffff:7f00:1";
|
static const std::string kIPv4MappedLoopbackAddrString = "::ffff:7f00:1";
|
||||||
|
Reference in New Issue
Block a user