QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_QUIC_PLATFORM_API_QUIC_SOCKET_ADDRESS_H_ |
| 6 | #define QUICHE_QUIC_PLATFORM_API_QUIC_SOCKET_ADDRESS_H_ |
| 7 | |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
| 11 | #include "net/third_party/quiche/src/quic/platform/api/quic_ip_address.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | |
| 13 | namespace quic { |
| 14 | |
vasilvv | 64144fb | 2019-06-13 16:05:17 -0700 | [diff] [blame] | 15 | // A class representing a socket endpoint address (i.e., IP address plus a |
| 16 | // port) in QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | class QUIC_EXPORT_PRIVATE QuicSocketAddress { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 18 | public: |
vasilvv | 64144fb | 2019-06-13 16:05:17 -0700 | [diff] [blame] | 19 | QuicSocketAddress() {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 20 | QuicSocketAddress(QuicIpAddress address, uint16_t port); |
| 21 | explicit QuicSocketAddress(const struct sockaddr_storage& saddr); |
vasilvv | 91f97e6 | 2019-06-10 14:17:15 -0700 | [diff] [blame] | 22 | explicit QuicSocketAddress(const sockaddr* saddr, socklen_t len); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 23 | QuicSocketAddress(const QuicSocketAddress& other) = default; |
| 24 | QuicSocketAddress& operator=(const QuicSocketAddress& other) = default; |
| 25 | QuicSocketAddress& operator=(QuicSocketAddress&& other) = default; |
| 26 | QUIC_EXPORT_PRIVATE friend bool operator==(const QuicSocketAddress& lhs, |
| 27 | const QuicSocketAddress& rhs); |
| 28 | QUIC_EXPORT_PRIVATE friend bool operator!=(const QuicSocketAddress& lhs, |
| 29 | const QuicSocketAddress& rhs); |
| 30 | |
| 31 | bool IsInitialized() const; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 32 | std::string ToString() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 33 | int FromSocket(int fd); |
| 34 | QuicSocketAddress Normalized() const; |
| 35 | |
| 36 | QuicIpAddress host() const; |
| 37 | uint16_t port() const; |
| 38 | sockaddr_storage generic_address() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 39 | |
| 40 | private: |
vasilvv | 64144fb | 2019-06-13 16:05:17 -0700 | [diff] [blame] | 41 | QuicIpAddress host_; |
| 42 | uint16_t port_ = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 43 | }; |
| 44 | |
vasilvv | 01010ca | 2019-07-08 15:12:21 -0700 | [diff] [blame] | 45 | inline std::ostream& operator<<(std::ostream& os, |
| 46 | const QuicSocketAddress address) { |
| 47 | os << address.ToString(); |
| 48 | return os; |
| 49 | } |
| 50 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 51 | } // namespace quic |
| 52 | |
| 53 | #endif // QUICHE_QUIC_PLATFORM_API_QUIC_SOCKET_ADDRESS_H_ |