24#include <sys/socket.h>
26#include <netinet/ip.h>
31#include <fmt/ostream.h>
33#include <seastar/net/byteorder.hh>
34#include <seastar/net/unix_address.hh>
38SEASTAR_MODULE_EXPORT_BEGIN
49 socklen_t addr_length;
51 ::sockaddr_storage sas;
57 socket_address(
const sockaddr_in& sa) noexcept : addr_length{
sizeof(::sockaddr_in)} {
60 socket_address(
const sockaddr_in6& sa) noexcept : addr_length{
sizeof(::sockaddr_in6)} {
75 ::sockaddr& as_posix_sockaddr() noexcept {
return u.sa; }
76 ::sockaddr_in& as_posix_sockaddr_in() noexcept {
return u.in; }
77 ::sockaddr_in6& as_posix_sockaddr_in6() noexcept {
return u.in6; }
78 const ::sockaddr& as_posix_sockaddr() const noexcept {
return u.sa; }
79 const ::sockaddr_in& as_posix_sockaddr_in() const noexcept {
return u.in; }
80 const ::sockaddr_in6& as_posix_sockaddr_in6() const noexcept {
return u.in6; }
84 socklen_t length() const noexcept {
return addr_length; };
86 bool is_af_unix() const noexcept {
87 return u.sa.sa_family == AF_UNIX;
90 bool is_unspecified() const noexcept;
92 sa_family_t family() const noexcept {
93 return u.sa.sa_family;
96 net::inet_address addr() const noexcept;
97 ::in_port_t port() const noexcept;
98 bool is_wildcard() const noexcept;
102 return !(*
this == a);
106std::ostream& operator<<(std::ostream&,
const socket_address&);
108enum class transport {
118 ipv4_addr(uint32_t ip, uint16_t port) noexcept : ip(ip), port(port) {}
119 ipv4_addr(uint16_t port) noexcept : ip(0), port(port) {}
122 ipv4_addr(
const std::string &addr, uint16_t port);
126 ipv4_addr(const ::in_addr&, uint16_t = 0)
noexcept;
128 bool is_ip_unspecified()
const noexcept {
131 bool is_port_unspecified()
const noexcept {
137 using ipv6_bytes = std::array<uint8_t, 16>;
142 ipv6_addr(
const ipv6_bytes&, uint16_t port = 0)
noexcept;
146 ipv6_addr(
const std::string&, uint16_t port);
148 ipv6_addr(const ::in6_addr&, uint16_t = 0)
noexcept;
149 ipv6_addr(const ::sockaddr_in6&)
noexcept;
152 bool is_ip_unspecified()
const noexcept;
153 bool is_port_unspecified()
const noexcept {
158std::ostream& operator<<(std::ostream&,
const ipv4_addr&);
159std::ostream& operator<<(std::ostream&,
const ipv6_addr&);
162 return lhs.ip == rhs.ip && lhs.port == rhs.port;
164SEASTAR_MODULE_EXPORT_END
181struct hash<::sockaddr_un> {
182 size_t operator()(const ::sockaddr_un&)
const;
187 size_t operator()(seastar::transport tr)
const {
188 return static_cast<size_t>(tr);
194#if FMT_VERSION >= 90000
195template <>
struct fmt::formatter<
seastar::socket_address> : fmt::ostream_formatter {};
196template <>
struct fmt::formatter<
seastar::ipv4_addr> : fmt::ostream_formatter {};
197template <>
struct fmt::formatter<
seastar::ipv6_addr> : fmt::ostream_formatter {};
Definition: inet_address.hh:50
Definition: socket_defs.hh:47
union seastar::socket_address::@14 u
!< actual size of the relevant 'u' member
socket_address() noexcept
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
Definition: socket_defs.hh:113
Definition: socket_defs.hh:136
Definition: unix_address.hh:43