OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 namespace rtc { | 34 namespace rtc { |
35 | 35 |
36 // Prefixes used for categorizing IPv6 addresses. | 36 // Prefixes used for categorizing IPv6 addresses. |
37 static const in6_addr kV4MappedPrefix = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 37 static const in6_addr kV4MappedPrefix = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
38 0xFF, 0xFF, 0}}}; | 38 0xFF, 0xFF, 0}}}; |
39 static const in6_addr k6To4Prefix = {{{0x20, 0x02, 0}}}; | 39 static const in6_addr k6To4Prefix = {{{0x20, 0x02, 0}}}; |
40 static const in6_addr kTeredoPrefix = {{{0x20, 0x01, 0x00, 0x00}}}; | 40 static const in6_addr kTeredoPrefix = {{{0x20, 0x01, 0x00, 0x00}}}; |
41 static const in6_addr kV4CompatibilityPrefix = {{{0}}}; | 41 static const in6_addr kV4CompatibilityPrefix = {{{0}}}; |
42 static const in6_addr k6BonePrefix = {{{0x3f, 0xfe, 0}}}; | 42 static const in6_addr k6BonePrefix = {{{0x3f, 0xfe, 0}}}; |
43 | 43 |
44 bool IPAddress::strip_sensitive_ = false; | |
45 | |
46 static bool IsPrivateV4(uint32_t ip); | 44 static bool IsPrivateV4(uint32_t ip); |
47 static in_addr ExtractMappedAddress(const in6_addr& addr); | 45 static in_addr ExtractMappedAddress(const in6_addr& addr); |
48 | 46 |
49 uint32_t IPAddress::v4AddressAsHostOrderInteger() const { | 47 uint32_t IPAddress::v4AddressAsHostOrderInteger() const { |
50 if (family_ == AF_INET) { | 48 if (family_ == AF_INET) { |
51 return NetworkToHost32(u_.ip4.s_addr); | 49 return NetworkToHost32(u_.ip4.s_addr); |
52 } else { | 50 } else { |
53 return 0; | 51 return 0; |
54 } | 52 } |
55 } | 53 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 if (family_ == AF_INET6) { | 135 if (family_ == AF_INET6) { |
138 src = &u_.ip6; | 136 src = &u_.ip6; |
139 } | 137 } |
140 if (!rtc::inet_ntop(family_, src, buf, sizeof(buf))) { | 138 if (!rtc::inet_ntop(family_, src, buf, sizeof(buf))) { |
141 return std::string(); | 139 return std::string(); |
142 } | 140 } |
143 return std::string(buf); | 141 return std::string(buf); |
144 } | 142 } |
145 | 143 |
146 std::string IPAddress::ToSensitiveString() const { | 144 std::string IPAddress::ToSensitiveString() const { |
147 if (!strip_sensitive_) | 145 #if !defined(NDEBUG) |
148 return ToString(); | 146 // Return non-stripped in debug. |
149 | 147 return ToString(); |
| 148 #else |
150 switch (family_) { | 149 switch (family_) { |
151 case AF_INET: { | 150 case AF_INET: { |
152 std::string address = ToString(); | 151 std::string address = ToString(); |
153 size_t find_pos = address.rfind('.'); | 152 size_t find_pos = address.rfind('.'); |
154 if (find_pos == std::string::npos) | 153 if (find_pos == std::string::npos) |
155 return std::string(); | 154 return std::string(); |
156 address.resize(find_pos); | 155 address.resize(find_pos); |
157 address += ".x"; | 156 address += ".x"; |
158 return address; | 157 return address; |
159 } | 158 } |
160 case AF_INET6: { | 159 case AF_INET6: { |
161 // TODO(grunell): Return a string of format 1:2:3:x:x:x:x:x or such | 160 // TODO(grunell): Return a string of format 1:2:3:x:x:x:x:x or such |
162 // instead of zeroing out. | 161 // instead of zeroing out. |
163 return TruncateIP(*this, 128 - 80).ToString(); | 162 return TruncateIP(*this, 128 - 80).ToString(); |
164 } | 163 } |
165 } | 164 } |
166 return std::string(); | 165 return std::string(); |
| 166 #endif |
167 } | 167 } |
168 | 168 |
169 IPAddress IPAddress::Normalized() const { | 169 IPAddress IPAddress::Normalized() const { |
170 if (family_ != AF_INET6) { | 170 if (family_ != AF_INET6) { |
171 return *this; | 171 return *this; |
172 } | 172 } |
173 if (!IPIsV4Mapped(*this)) { | 173 if (!IPIsV4Mapped(*this)) { |
174 return *this; | 174 return *this; |
175 } | 175 } |
176 in_addr addr = ExtractMappedAddress(u_.ip6); | 176 in_addr addr = ExtractMappedAddress(u_.ip6); |
177 return IPAddress(addr); | 177 return IPAddress(addr); |
178 } | 178 } |
179 | 179 |
180 IPAddress IPAddress::AsIPv6Address() const { | 180 IPAddress IPAddress::AsIPv6Address() const { |
181 if (family_ != AF_INET) { | 181 if (family_ != AF_INET) { |
182 return *this; | 182 return *this; |
183 } | 183 } |
184 in6_addr v6addr = kV4MappedPrefix; | 184 in6_addr v6addr = kV4MappedPrefix; |
185 ::memcpy(&v6addr.s6_addr[12], &u_.ip4.s_addr, sizeof(u_.ip4.s_addr)); | 185 ::memcpy(&v6addr.s6_addr[12], &u_.ip4.s_addr, sizeof(u_.ip4.s_addr)); |
186 return IPAddress(v6addr); | 186 return IPAddress(v6addr); |
187 } | 187 } |
188 | 188 |
189 void IPAddress::set_strip_sensitive(bool enable) { | |
190 strip_sensitive_ = enable; | |
191 } | |
192 | |
193 bool InterfaceAddress::operator==(const InterfaceAddress &other) const { | 189 bool InterfaceAddress::operator==(const InterfaceAddress &other) const { |
194 return ipv6_flags_ == other.ipv6_flags() && | 190 return ipv6_flags_ == other.ipv6_flags() && |
195 static_cast<const IPAddress&>(*this) == other; | 191 static_cast<const IPAddress&>(*this) == other; |
196 } | 192 } |
197 | 193 |
198 bool InterfaceAddress::operator!=(const InterfaceAddress &other) const { | 194 bool InterfaceAddress::operator!=(const InterfaceAddress &other) const { |
199 return !((*this) == other); | 195 return !((*this) == other); |
200 } | 196 } |
201 | 197 |
202 const InterfaceAddress& InterfaceAddress::operator=( | 198 const InterfaceAddress& InterfaceAddress::operator=( |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 if (family == AF_INET) { | 507 if (family == AF_INET) { |
512 return rtc::IPAddress(INADDR_ANY); | 508 return rtc::IPAddress(INADDR_ANY); |
513 } | 509 } |
514 if (family == AF_INET6) { | 510 if (family == AF_INET6) { |
515 return rtc::IPAddress(in6addr_any); | 511 return rtc::IPAddress(in6addr_any); |
516 } | 512 } |
517 return rtc::IPAddress(); | 513 return rtc::IPAddress(); |
518 } | 514 } |
519 | 515 |
520 } // Namespace rtc | 516 } // Namespace rtc |
OLD | NEW |