5#ifndef WPINET_UV_UTIL_H_
6#define WPINET_UV_UTIL_H_
14#pragma comment(lib, "Ws2_32.lib")
27int AddrToName(
const sockaddr_in& addr, T* ip,
unsigned int* port) {
31 ip->assign(name, name + std::strlen(name));
32 *port = ntohs(addr.sin_port);
34 ip->assign(name, name);
47int AddrToName(
const sockaddr_in6& addr, T* ip,
unsigned int* port) {
51 ip->assign(name, name + std::strlen(name));
52 *port = ntohs(addr.sin6_port);
54 ip->assign(name, name);
67int AddrToName(
const sockaddr_storage& addr, T* ip,
unsigned int* port) {
68 if (addr.ss_family == AF_INET) {
69 return AddrToName(
reinterpret_cast<const sockaddr_in&
>(addr), ip, port);
71 if (addr.ss_family == AF_INET6) {
72 return AddrToName(
reinterpret_cast<const sockaddr_in6&
>(addr), ip, port);
74 char name[1] = {
'\0'};
75 ip->assign(name, name);
90 ip->assign(name, name + std::strlen(name));
92 ip->assign(name, name);
108 ip->assign(name, name + std::strlen(name));
110 ip->assign(name, name);
basic_string_view< char > string_view
Definition: core.h:501
Definition: WebSocket.h:27
int NameToAddr(std::string_view ip, unsigned int port, sockaddr_in *addr)
Convert a string containing an IPv4 address to a binary structure.
int AddrToName(const sockaddr_in &addr, T *ip, unsigned int *port)
Convert a binary structure containing an IPv4 address to a string.
Definition: util.h:27
UV_EXTERN int uv_ip4_name(const struct sockaddr_in *src, char *dst, size_t size)
UV_EXTERN int uv_inet_ntop(int af, const void *src, char *dst, size_t size)
UV_EXTERN int uv_ip6_name(const struct sockaddr_in6 *src, char *dst, size_t size)