24 if (addr->getRawAddress()->sa_family == AF_INET) {
25 const auto ipv4 =
reinterpret_cast<sockaddr_in *
>(addr->getRawAddress());
26 return asio::ip::make_address_v4(htonl(ipv4->sin_addr.s_addr));
28 const auto ipv6 =
reinterpret_cast<sockaddr_in6 *
>(addr->getRawAddress());
29 const std::array<unsigned char, 16> bytes = {
30 ipv6->sin6_addr.s6_addr[0],
31 ipv6->sin6_addr.s6_addr[1],
32 ipv6->sin6_addr.s6_addr[2],
33 ipv6->sin6_addr.s6_addr[3],
34 ipv6->sin6_addr.s6_addr[4],
35 ipv6->sin6_addr.s6_addr[5],
36 ipv6->sin6_addr.s6_addr[6],
37 ipv6->sin6_addr.s6_addr[7],
38 ipv6->sin6_addr.s6_addr[8],
39 ipv6->sin6_addr.s6_addr[9],
40 ipv6->sin6_addr.s6_addr[10],
41 ipv6->sin6_addr.s6_addr[11],
42 ipv6->sin6_addr.s6_addr[12],
43 ipv6->sin6_addr.s6_addr[13],
44 ipv6->sin6_addr.s6_addr[14],
45 ipv6->sin6_addr.s6_addr[15]
47 return asio::ip::make_address_v6(bytes, ipv6->sin6_scope_id);
53 std::is_same_v<EndpointType, asio::ip::tcp::endpoint> || std::is_same_v<EndpointType, asio::ip::udp::endpoint>,
54 "EndpointType must be either asio::ip::tcp::endpoint or asio::ip::udp::endpoint"
57 if (endpoint.address().is_v4()) {
58 sockaddr_in sockaddr{};
59 sockaddr.sin_family = AF_INET;
60 sockaddr.sin_port = htons(endpoint.port());
61 sockaddr.sin_addr.s_addr = htonl(endpoint.address().to_v4().to_uint());
62 return std::make_shared<sese::net::IPv4Address>(sockaddr);
64 sockaddr_in6 sockaddr{};
65 sockaddr.sin6_family = AF_INET6;
66 sockaddr.sin6_port = htons(endpoint.port());
67 auto bytes = endpoint.address().to_v6().to_bytes();
68 memcpy(&sockaddr.sin6_addr, bytes.data(), bytes.size());
69 return std::make_shared<sese::net::IPv6Address>(sockaddr);