Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/platform/impl/quic_ip_address_impl.h" | 5 #include "net/quic/platform/impl/quic_ip_address_impl.h" |
| 6 | 6 |
| 7 #include "base/containers/stack_container.h" | |
| 7 #include "net/base/address_family.h" | 8 #include "net/base/address_family.h" |
| 8 #include "net/quic/platform/api/quic_bug_tracker.h" | 9 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 9 | 10 |
| 10 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 11 #include <winsock2.h> | 12 #include <winsock2.h> |
| 12 #include <ws2bth.h> | 13 #include <ws2bth.h> |
| 13 #elif defined(OS_POSIX) | 14 #elif defined(OS_POSIX) |
| 14 #include <netinet/in.h> | 15 #include <netinet/in.h> |
| 15 #endif | 16 #endif |
| 16 | 17 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 } | 101 } |
| 101 return QuicIpAddressImpl(ip_address_); | 102 return QuicIpAddressImpl(ip_address_); |
| 102 } | 103 } |
| 103 | 104 |
| 104 bool QuicIpAddressImpl::FromPackedString(const char* data, size_t length) { | 105 bool QuicIpAddressImpl::FromPackedString(const char* data, size_t length) { |
| 105 if (length != IPAddress::kIPv4AddressSize && | 106 if (length != IPAddress::kIPv4AddressSize && |
| 106 length != IPAddress::kIPv6AddressSize) { | 107 length != IPAddress::kIPv6AddressSize) { |
| 107 QUIC_BUG << "Invalid packed IP address of length " << length; | 108 QUIC_BUG << "Invalid packed IP address of length " << length; |
| 108 return false; | 109 return false; |
| 109 } | 110 } |
| 110 std::vector<uint8_t> ip(length); | 111 base::StackVector<uint8_t, 16> ip; |
| 112 ip->resize(length); | |
| 111 memcpy(&ip[0], data, length); | 113 memcpy(&ip[0], data, length); |
| 112 ip_address_ = IPAddress(ip); | 114 ip_address_ = IPAddress(ip->data(), ip->size()); |
|
eroman
2017/05/19 22:00:07
Delete the three lines above, and change this one
Ryan Hamilton
2017/05/20 03:21:44
Done. (needs a reinterpret_cast though. Thanks, C+
| |
| 113 return true; | 115 return true; |
| 114 } | 116 } |
| 115 | 117 |
| 116 bool QuicIpAddressImpl::FromString(string str) { | 118 bool QuicIpAddressImpl::FromString(string str) { |
| 117 return ip_address_.AssignFromIPLiteral(str); | 119 return ip_address_.AssignFromIPLiteral(str); |
| 118 } | 120 } |
| 119 | 121 |
| 120 bool QuicIpAddressImpl::IsIPv4() const { | 122 bool QuicIpAddressImpl::IsIPv4() const { |
| 121 return ip_address_.IsIPv4(); | 123 return ip_address_.IsIPv4(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 bool QuicIpAddressImpl::IsIPv6() const { | 126 bool QuicIpAddressImpl::IsIPv6() const { |
| 125 return ip_address_.IsIPv6(); | 127 return ip_address_.IsIPv6(); |
| 126 } | 128 } |
| 127 | 129 |
| 128 bool QuicIpAddressImpl::InSameSubnet(const QuicIpAddressImpl& other, | 130 bool QuicIpAddressImpl::InSameSubnet(const QuicIpAddressImpl& other, |
| 129 int subnet_length) { | 131 int subnet_length) { |
| 130 return IPAddressMatchesPrefix(ip_address_, other.ip_address(), subnet_length); | 132 return IPAddressMatchesPrefix(ip_address_, other.ip_address(), subnet_length); |
| 131 } | 133 } |
| 132 | 134 |
| 133 } // namespace net | 135 } // namespace net |
| OLD | NEW |