14 return socket(AF_INET6, type, protocol);
16 return socket(AF_INET, type, protocol);
28 server->sin6_family = AF_INET6;
29 server->sin6_port = htons(port);
31 if (ip_address.find(
'.') != std::string::npos) {
32 server->sin6_addr.un.u32_addr[3] = inet_addr(ip_address.c_str());
35 inet6_aton(ip_address.c_str(), &ip6);
36 memcpy(server->sin6_addr.un.u32_addr, ip6.addr,
sizeof(ip6.addr));
44 auto *server =
reinterpret_cast<sockaddr_in *
>(addr);
46 server->sin_family = AF_INET;
47 server->sin_addr.s_addr = inet_addr(ip_address.c_str());
48 server->sin_port = htons(port);
61 server->sin6_family = AF_INET6;
62 server->sin6_port = htons(port);
63 server->sin6_addr = in6addr_any;
70 auto *server =
reinterpret_cast<sockaddr_in *
>(addr);
72 server->sin_family = AF_INET;
73 server->sin_addr.s_addr = ESPHOME_INADDR_ANY;
74 server->sin_port = htons(port);
std::unique_ptr< Socket > socket_ip(int type, int protocol)
Create a socket in the newest available IP domain (IPv6 or IPv4) of the given type and protocol...
socklen_t set_sockaddr_any(struct sockaddr *addr, socklen_t addrlen, uint16_t port)
Set a sockaddr to the any address and specified port for the IP version used by socket_ip().
socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const std::string &ip_address, uint16_t port)
Set a sockaddr to the specified address and port for the IP version used by socket_ip().
std::unique_ptr< Socket > socket(int domain, int type, int protocol)
Create a socket of the given domain, type and protocol.