Roll src/third_party/skia 4cf9e7e:8ee06f2
[chromium-blink-merge.git] / net / base / ip_endpoint.h
blob784ee031ed149dc1a7861f22d80f16afba2195e1
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
3 // found in the LICENSE file.
5 #ifndef NET_BASE_IP_ENDPOINT_H_
6 #define NET_BASE_IP_ENDPOINT_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "net/base/address_family.h"
13 #include "net/base/ip_address_number.h"
14 #include "net/base/net_export.h"
15 #include "net/base/sys_addrinfo.h"
17 struct sockaddr;
19 namespace net {
21 // An IPEndPoint represents the address of a transport endpoint:
22 // * IP address (either v4 or v6)
23 // * Port
24 class NET_EXPORT IPEndPoint {
25 public:
26 IPEndPoint();
27 ~IPEndPoint();
28 IPEndPoint(const IPAddressNumber& address, uint16_t port);
29 IPEndPoint(const IPEndPoint& endpoint);
31 const IPAddressNumber& address() const { return address_; }
32 uint16_t port() const { return port_; }
34 // Returns AddressFamily of the address.
35 AddressFamily GetFamily() const;
37 // Returns the sockaddr family of the address, AF_INET or AF_INET6.
38 int GetSockAddrFamily() const;
40 // Convert to a provided sockaddr struct.
41 // |address| is the sockaddr to copy into. Should be at least
42 // sizeof(struct sockaddr_storage) bytes.
43 // |address_length| is an input/output parameter. On input, it is the
44 // size of data in |address| available. On output, it is the size of
45 // the address that was copied into |address|.
46 // Returns true on success, false on failure.
47 bool ToSockAddr(struct sockaddr* address, socklen_t* address_length) const
48 WARN_UNUSED_RESULT;
50 // Convert from a sockaddr struct.
51 // |address| is the address.
52 // |address_length| is the length of |address|.
53 // Returns true on success, false on failure.
54 bool FromSockAddr(const struct sockaddr* address, socklen_t address_length)
55 WARN_UNUSED_RESULT;
57 // Returns value as a string (e.g. "127.0.0.1:80"). The IP address must be
58 // valid.
59 std::string ToString() const;
61 // As above, but without port.
62 std::string ToStringWithoutPort() const;
64 bool operator<(const IPEndPoint& that) const;
65 bool operator==(const IPEndPoint& that) const;
67 private:
68 IPAddressNumber address_;
69 uint16_t port_;
72 } // namespace net
74 #endif // NET_BASE_IP_ENDPOINT_H_