blob: 0831985e6a44b7ee642fd1cbd319ca1764de79e4 [file] [log] [blame]
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "quic/platform/api/quic_export.h"
#include "quic/platform/api/quic_ip_address.h"
namespace quic {
// A class representing a socket endpoint address (i.e., IP address plus a
// port) in QUIC.
class QUIC_EXPORT_PRIVATE QuicSocketAddress {
QuicSocketAddress() {}
QuicSocketAddress(QuicIpAddress address, uint16_t port);
explicit QuicSocketAddress(const struct sockaddr_storage& saddr);
explicit QuicSocketAddress(const sockaddr* saddr, socklen_t len);
QuicSocketAddress(const QuicSocketAddress& other) = default;
QuicSocketAddress& operator=(const QuicSocketAddress& other) = default;
QuicSocketAddress& operator=(QuicSocketAddress&& other) = default;
QUIC_EXPORT_PRIVATE friend bool operator==(const QuicSocketAddress& lhs,
const QuicSocketAddress& rhs);
QUIC_EXPORT_PRIVATE friend bool operator!=(const QuicSocketAddress& lhs,
const QuicSocketAddress& rhs);
bool IsInitialized() const;
std::string ToString() const;
int FromSocket(int fd);
QuicSocketAddress Normalized() const;
QuicIpAddress host() const;
uint16_t port() const;
sockaddr_storage generic_address() const;
QuicIpAddress host_;
uint16_t port_ = 0;
inline std::ostream& operator<<(std::ostream& os,
const QuicSocketAddress address) {
os << address.ToString();
return os;
} // namespace quic