Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: net/base/ip_endpoint.cc

Issue 1540413002: net: add a ctor to IPEndPoint that takes an IPAddress (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/base/ip_endpoint.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "build/build_config.h"
8
9 #if defined(OS_WIN)
10 #include <winsock2.h>
11 #elif defined(OS_POSIX)
12 #include <netinet/in.h>
13 #endif
14
7 #include <tuple> 15 #include <tuple>
8 16
9 #include "base/logging.h" 17 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
11 #include "base/sys_byteorder.h" 19 #include "base/sys_byteorder.h"
12 #if defined(OS_WIN) 20 #include "net/base/ip_address.h"
13 #include <winsock2.h>
14 #elif defined(OS_POSIX)
15 #include <netinet/in.h>
16 #endif
17 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
18 22
19 namespace net { 23 namespace net {
20 24
21 namespace { 25 namespace {
26
22 // By definition, socklen_t is large enough to hold both sizes. 27 // By definition, socklen_t is large enough to hold both sizes.
23 const socklen_t kSockaddrInSize = sizeof(struct sockaddr_in); 28 const socklen_t kSockaddrInSize = sizeof(struct sockaddr_in);
24 const socklen_t kSockaddrIn6Size = sizeof(struct sockaddr_in6); 29 const socklen_t kSockaddrIn6Size = sizeof(struct sockaddr_in6);
25 } 30
31 } // namespace
26 32
27 IPEndPoint::IPEndPoint() : port_(0) {} 33 IPEndPoint::IPEndPoint() : port_(0) {}
28 34
29 IPEndPoint::~IPEndPoint() {} 35 IPEndPoint::~IPEndPoint() {}
30 36
31 IPEndPoint::IPEndPoint(const IPAddressNumber& address, uint16_t port) 37 IPEndPoint::IPEndPoint(const IPAddressNumber& address, uint16_t port)
32 : address_(address), port_(port) { 38 : address_(address), port_(port) {
33 } 39 }
34 40
41 IPEndPoint::IPEndPoint(const IPAddress& address, uint16_t port)
42 : address_(address.bytes()), port_(port) {
43 }
44
35 IPEndPoint::IPEndPoint(const IPEndPoint& endpoint) { 45 IPEndPoint::IPEndPoint(const IPEndPoint& endpoint) {
36 address_ = endpoint.address_; 46 address_ = endpoint.address_;
37 port_ = endpoint.port_; 47 port_ = endpoint.port_;
38 } 48 }
39 49
40 AddressFamily IPEndPoint::GetFamily() const { 50 AddressFamily IPEndPoint::GetFamily() const {
41 return GetAddressFamily(address_); 51 return GetAddressFamily(address_);
42 } 52 }
43 53
44 int IPEndPoint::GetSockAddrFamily() const { 54 int IPEndPoint::GetSockAddrFamily() const {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return address_.size() < other.address_.size(); 128 return address_.size() < other.address_.size();
119 } 129 }
120 return std::tie(address_, port_) < std::tie(other.address_, other.port_); 130 return std::tie(address_, port_) < std::tie(other.address_, other.port_);
121 } 131 }
122 132
123 bool IPEndPoint::operator==(const IPEndPoint& other) const { 133 bool IPEndPoint::operator==(const IPEndPoint& other) const {
124 return address_ == other.address_ && port_ == other.port_; 134 return address_ == other.address_ && port_ == other.port_;
125 } 135 }
126 136
127 } // namespace net 137 } // namespace net
OLDNEW
« no previous file with comments | « net/base/ip_endpoint.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698