Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: webrtc/base/ipaddress.cc

Issue 1516163003: Add "x"s in the end of a stripped IPv6 address string. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed typo. Rebase. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/base/ipaddress_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/ipaddress.cc
diff --git a/webrtc/base/ipaddress.cc b/webrtc/base/ipaddress.cc
index 3b74d60036565463886e94258e0a93570a6fae5e..c85624d24a7729d28c2f6efe2c0eb1d7243fdcaa 100644
--- a/webrtc/base/ipaddress.cc
+++ b/webrtc/base/ipaddress.cc
@@ -27,6 +27,7 @@
#include "webrtc/base/ipaddress.h"
#include "webrtc/base/byteorder.h"
+#include "webrtc/base/checks.h"
#include "webrtc/base/nethelpers.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/win32.h"
@@ -157,9 +158,19 @@ std::string IPAddress::ToSensitiveString() const {
return address;
}
case AF_INET6: {
- // TODO(grunell): Return a string of format 1:2:3:x:x:x:x:x or such
- // instead of zeroing out.
- return TruncateIP(*this, 128 - 80).ToString();
+ // Remove the last 5 groups (80 bits).
+ std::string address = TruncateIP(*this, 128 - 80).ToString();
+
+ // If all three remaining groups are written out explicitly in the string,
+ // remove one of the two trailing colons before appending the stripped
+ // groups as "x"s. There should be max 4 colons (2 between the 3 groups +
+ // 2 trailing) in the truncated address string.
+ size_t number_of_colons = std::count(address.begin(), address.end(), ':');
+ RTC_CHECK_LE(number_of_colons, 4u);
+ if (number_of_colons > 3)
+ address.resize(address.length() - 1);
+
+ return address + "x:x:x:x:x";
}
}
return std::string();
« no previous file with comments | « no previous file | webrtc/base/ipaddress_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698