in demo_example/asio/asio/detail/impl/winrt_ssocket_service_base.ipp [165:228]
std::size_t winrt_ssocket_service_base::do_get_endpoint(
const base_implementation_type& impl, bool local,
void* addr, std::size_t addr_len, asio::error_code& ec) const
{
if (!is_open(impl))
{
ec = asio::error::bad_descriptor;
return addr_len;
}
try
{
std::string addr_string = winrt_utils::string(local
? impl.socket_->Information->LocalAddress->CanonicalName
: impl.socket_->Information->RemoteAddress->CanonicalName);
unsigned short port = winrt_utils::integer(local
? impl.socket_->Information->LocalPort
: impl.socket_->Information->RemotePort);
unsigned long scope = 0;
switch (reinterpret_cast<const socket_addr_type*>(addr)->sa_family)
{
case ASIO_OS_DEF(AF_INET):
if (addr_len < sizeof(sockaddr_in4_type))
{
ec = asio::error::invalid_argument;
return addr_len;
}
else
{
socket_ops::inet_pton(ASIO_OS_DEF(AF_INET), addr_string.c_str(),
&reinterpret_cast<sockaddr_in4_type*>(addr)->sin_addr, &scope, ec);
reinterpret_cast<sockaddr_in4_type*>(addr)->sin_port
= socket_ops::host_to_network_short(port);
ec = asio::error_code();
return sizeof(sockaddr_in4_type);
}
case ASIO_OS_DEF(AF_INET6):
if (addr_len < sizeof(sockaddr_in6_type))
{
ec = asio::error::invalid_argument;
return addr_len;
}
else
{
socket_ops::inet_pton(ASIO_OS_DEF(AF_INET6), addr_string.c_str(),
&reinterpret_cast<sockaddr_in6_type*>(addr)->sin6_addr, &scope, ec);
reinterpret_cast<sockaddr_in6_type*>(addr)->sin6_port
= socket_ops::host_to_network_short(port);
ec = asio::error_code();
return sizeof(sockaddr_in6_type);
}
default:
ec = asio::error::address_family_not_supported;
return addr_len;
}
}
catch (Platform::Exception^ e)
{
ec = asio::error_code(e->HResult,
asio::system_category());
return addr_len;
}
}