| 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 |
| 11 #if defined(WEBRTC_POSIX) | 11 #if defined(WEBRTC_POSIX) |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 #include <sys/socket.h> | 13 #include <sys/socket.h> |
| 14 #include <netinet/in.h> | 14 #include <netinet/in.h> |
| 15 #ifdef OPENBSD | 15 #ifdef OPENBSD |
| 16 #include <netinet/in_systm.h> | 16 #include <netinet/in_systm.h> |
| 17 #endif | 17 #endif |
| 18 #ifndef __native_client__ | 18 #ifndef __native_client__ |
| 19 #include <netinet/ip.h> | 19 #include <netinet/ip.h> |
| 20 #endif | 20 #endif |
| 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/nethelpers.h" | 31 #include "webrtc/base/nethelpers.h" |
| 31 #include "webrtc/base/logging.h" | 32 #include "webrtc/base/logging.h" |
| 32 #include "webrtc/base/win32.h" | 33 #include "webrtc/base/win32.h" |
| 33 | 34 |
| 34 namespace rtc { | 35 namespace rtc { |
| 35 | 36 |
| 36 // Prefixes used for categorizing IPv6 addresses. | 37 // Prefixes used for categorizing IPv6 addresses. |
| 37 static const in6_addr kV4MappedPrefix = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 38 static const in6_addr kV4MappedPrefix = {{{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 38 0xFF, 0xFF, 0}}}; | 39 0xFF, 0xFF, 0}}}; |
| 39 static const in6_addr k6To4Prefix = {{{0x20, 0x02, 0}}}; | 40 static const in6_addr k6To4Prefix = {{{0x20, 0x02, 0}}}; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 case AF_INET: { | 151 case AF_INET: { |
| 151 std::string address = ToString(); | 152 std::string address = ToString(); |
| 152 size_t find_pos = address.rfind('.'); | 153 size_t find_pos = address.rfind('.'); |
| 153 if (find_pos == std::string::npos) | 154 if (find_pos == std::string::npos) |
| 154 return std::string(); | 155 return std::string(); |
| 155 address.resize(find_pos); | 156 address.resize(find_pos); |
| 156 address += ".x"; | 157 address += ".x"; |
| 157 return address; | 158 return address; |
| 158 } | 159 } |
| 159 case AF_INET6: { | 160 case AF_INET6: { |
| 160 // TODO(grunell): Return a string of format 1:2:3:x:x:x:x:x or such | 161 // Remove the last 5 groups (80 bits). |
| 161 // instead of zeroing out. | 162 std::string address = TruncateIP(*this, 128 - 80).ToString(); |
| 162 return TruncateIP(*this, 128 - 80).ToString(); | 163 |
| 164 // If all three remaining groups are written out explicitly in the string, |
| 165 // remove one of the two trailing colons before appending the stripped |
| 166 // groups as "x"s. There should be max 4 colons (2 between the 3 groups + |
| 167 // 2 trailing) in the truncated address string. |
| 168 size_t number_of_colons = std::count(address.begin(), address.end(), ':'); |
| 169 RTC_CHECK_LE(number_of_colons, 4u); |
| 170 if (number_of_colons > 3) |
| 171 address.resize(address.length() - 1); |
| 172 |
| 173 return address + "x:x:x:x:x"; |
| 163 } | 174 } |
| 164 } | 175 } |
| 165 return std::string(); | 176 return std::string(); |
| 166 #endif | 177 #endif |
| 167 } | 178 } |
| 168 | 179 |
| 169 IPAddress IPAddress::Normalized() const { | 180 IPAddress IPAddress::Normalized() const { |
| 170 if (family_ != AF_INET6) { | 181 if (family_ != AF_INET6) { |
| 171 return *this; | 182 return *this; |
| 172 } | 183 } |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 if (family == AF_INET) { | 518 if (family == AF_INET) { |
| 508 return rtc::IPAddress(INADDR_ANY); | 519 return rtc::IPAddress(INADDR_ANY); |
| 509 } | 520 } |
| 510 if (family == AF_INET6) { | 521 if (family == AF_INET6) { |
| 511 return rtc::IPAddress(in6addr_any); | 522 return rtc::IPAddress(in6addr_any); |
| 512 } | 523 } |
| 513 return rtc::IPAddress(); | 524 return rtc::IPAddress(); |
| 514 } | 525 } |
| 515 | 526 |
| 516 } // Namespace rtc | 527 } // Namespace rtc |
| OLD | NEW |