OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/ip_endpoint.h" | 5 #include "net/base/ip_endpoint.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/sys_byteorder.h" | 9 #include "base/sys_byteorder.h" |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
(...skipping 17 matching lines...) Expand all Loading... |
28 IPEndPoint::IPEndPoint(const IPAddressNumber& address, int port) | 28 IPEndPoint::IPEndPoint(const IPAddressNumber& address, int port) |
29 : address_(address), | 29 : address_(address), |
30 port_(port) {} | 30 port_(port) {} |
31 | 31 |
32 IPEndPoint::IPEndPoint(const IPEndPoint& endpoint) { | 32 IPEndPoint::IPEndPoint(const IPEndPoint& endpoint) { |
33 address_ = endpoint.address_; | 33 address_ = endpoint.address_; |
34 port_ = endpoint.port_; | 34 port_ = endpoint.port_; |
35 } | 35 } |
36 | 36 |
37 AddressFamily IPEndPoint::GetFamily() const { | 37 AddressFamily IPEndPoint::GetFamily() const { |
38 switch (address_.size()) { | 38 return GetAddressFamily(address_); |
39 case kIPv4AddressSize: | |
40 return ADDRESS_FAMILY_IPV4; | |
41 case kIPv6AddressSize: | |
42 return ADDRESS_FAMILY_IPV6; | |
43 default: | |
44 NOTREACHED() << "Bad IP address"; | |
45 return ADDRESS_FAMILY_UNSPECIFIED; | |
46 } | |
47 } | 39 } |
48 | 40 |
49 int IPEndPoint::GetSockAddrFamily() const { | 41 int IPEndPoint::GetSockAddrFamily() const { |
50 switch (address_.size()) { | 42 switch (address_.size()) { |
51 case kIPv4AddressSize: | 43 case kIPv4AddressSize: |
52 return AF_INET; | 44 return AF_INET; |
53 case kIPv6AddressSize: | 45 case kIPv6AddressSize: |
54 return AF_INET6; | 46 return AF_INET6; |
55 default: | 47 default: |
56 NOTREACHED() << "Bad IP address"; | 48 NOTREACHED() << "Bad IP address"; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 return address_ < that.address_; | 118 return address_ < that.address_; |
127 } | 119 } |
128 return port_ < that.port_; | 120 return port_ < that.port_; |
129 } | 121 } |
130 | 122 |
131 bool IPEndPoint::operator==(const IPEndPoint& that) const { | 123 bool IPEndPoint::operator==(const IPEndPoint& that) const { |
132 return address_ == that.address_ && port_ == that.port_; | 124 return address_ == that.address_ && port_ == that.port_; |
133 } | 125 } |
134 | 126 |
135 } // namespace net | 127 } // namespace net |
OLD | NEW |