| 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 10 matching lines...) Expand all Loading... |
| 21 #include <arpa/inet.h> | 21 #include <arpa/inet.h> |
| 22 #include <netdb.h> | 22 #include <netdb.h> |
| 23 #include <unistd.h> | 23 #include <unistd.h> |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #include <stdio.h> | 26 #include <stdio.h> |
| 27 | 27 |
| 28 #include "webrtc/base/ipaddress.h" | 28 #include "webrtc/base/ipaddress.h" |
| 29 #include "webrtc/base/byteorder.h" | 29 #include "webrtc/base/byteorder.h" |
| 30 #include "webrtc/base/checks.h" | 30 #include "webrtc/base/checks.h" |
| 31 #include "webrtc/base/logging.h" |
| 31 #include "webrtc/base/nethelpers.h" | 32 #include "webrtc/base/nethelpers.h" |
| 32 #include "webrtc/base/logging.h" | 33 #include "webrtc/base/stringutils.h" |
| 33 #include "webrtc/base/win32.h" | 34 #include "webrtc/base/win32.h" |
| 34 | 35 |
| 35 namespace rtc { | 36 namespace rtc { |
| 36 | 37 |
| 37 // Prefixes used for categorizing IPv6 addresses. | 38 // Prefixes used for categorizing IPv6 addresses. |
| 38 static const in6_addr kV4MappedPrefix = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 39 static const in6_addr kV4MappedPrefix = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 39 0xFF, 0xFF, 0}}}; | 40 0xFF, 0xFF, 0}}}; |
| 40 static const in6_addr k6To4Prefix = {{{0x20, 0x02, 0}}}; | 41 static const in6_addr k6To4Prefix = {{{0x20, 0x02, 0}}}; |
| 41 static const in6_addr kTeredoPrefix = {{{0x20, 0x01, 0x00, 0x00}}}; | 42 static const in6_addr kTeredoPrefix = {{{0x20, 0x01, 0x00, 0x00}}}; |
| 42 static const in6_addr kV4CompatibilityPrefix = {{{0}}}; | 43 static const in6_addr kV4CompatibilityPrefix = {{{0}}}; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 case AF_INET: { | 152 case AF_INET: { |
| 152 std::string address = ToString(); | 153 std::string address = ToString(); |
| 153 size_t find_pos = address.rfind('.'); | 154 size_t find_pos = address.rfind('.'); |
| 154 if (find_pos == std::string::npos) | 155 if (find_pos == std::string::npos) |
| 155 return std::string(); | 156 return std::string(); |
| 156 address.resize(find_pos); | 157 address.resize(find_pos); |
| 157 address += ".x"; | 158 address += ".x"; |
| 158 return address; | 159 return address; |
| 159 } | 160 } |
| 160 case AF_INET6: { | 161 case AF_INET6: { |
| 161 // Remove the last 5 groups (80 bits). | 162 std::string result; |
| 162 std::string address = TruncateIP(*this, 128 - 80).ToString(); | 163 result.resize(INET6_ADDRSTRLEN); |
| 163 | 164 in6_addr addr = ipv6_address(); |
| 164 // If all three remaining groups are written out explicitly in the string, | 165 size_t len = |
| 165 // remove one of the two trailing colons before appending the stripped | 166 rtc::sprintfn(&(result[0]), result.size(), "%x:%x:%x:x:x:x:x:x", |
| 166 // groups as "x"s. There should be max 4 colons (2 between the 3 groups + | 167 (addr.s6_addr[0] << 8) + addr.s6_addr[1], |
| 167 // 2 trailing) in the truncated address string. | 168 (addr.s6_addr[2] << 8) + addr.s6_addr[3], |
| 168 size_t number_of_colons = std::count(address.begin(), address.end(), ':'); | 169 (addr.s6_addr[4] << 8) + addr.s6_addr[5]); |
| 169 RTC_CHECK_LE(number_of_colons, 4u); | 170 result.resize(len); |
| 170 if (number_of_colons > 3) | 171 return result; |
| 171 address.resize(address.length() - 1); | |
| 172 | |
| 173 return address + "x:x:x:x:x"; | |
| 174 } | 172 } |
| 175 } | 173 } |
| 176 return std::string(); | 174 return std::string(); |
| 177 #endif | 175 #endif |
| 178 } | 176 } |
| 179 | 177 |
| 180 IPAddress IPAddress::Normalized() const { | 178 IPAddress IPAddress::Normalized() const { |
| 181 if (family_ != AF_INET6) { | 179 if (family_ != AF_INET6) { |
| 182 return *this; | 180 return *this; |
| 183 } | 181 } |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 if (family == AF_INET) { | 516 if (family == AF_INET) { |
| 519 return rtc::IPAddress(INADDR_ANY); | 517 return rtc::IPAddress(INADDR_ANY); |
| 520 } | 518 } |
| 521 if (family == AF_INET6) { | 519 if (family == AF_INET6) { |
| 522 return rtc::IPAddress(in6addr_any); | 520 return rtc::IPAddress(in6addr_any); |
| 523 } | 521 } |
| 524 return rtc::IPAddress(); | 522 return rtc::IPAddress(); |
| 525 } | 523 } |
| 526 | 524 |
| 527 } // Namespace rtc | 525 } // Namespace rtc |
| OLD | NEW |