2#if defined(USE_SOCKET_IMPL_LWIP_TCP) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || defined(USE_SOCKET_IMPL_BSD_SOCKETS)
31 if (ip_address.find(
':') != std::string::npos) {
38 server->sin6_family = AF_INET6;
39 server->sin6_port = htons(port);
41#ifdef USE_SOCKET_IMPL_BSD_SOCKETS
43 if (inet_pton(AF_INET6, ip_address.c_str(), &server->sin6_addr) != 1) {
50 inet6_aton(ip_address.c_str(), &ip6);
51 memcpy(server->sin6_addr.un.u32_addr, ip6.addr,
sizeof(ip6.addr));
60 auto *server =
reinterpret_cast<sockaddr_in *
>(addr);
62 server->sin_family = AF_INET;
63 server->sin_addr.s_addr = inet_addr(ip_address.c_str());
64 server->sin_port = htons(port);
76 server->sin6_family = AF_INET6;
77 server->sin6_port = htons(port);
78 server->sin6_addr = IN6ADDR_ANY_INIT;
85 auto *server =
reinterpret_cast<sockaddr_in *
>(addr);
87 server->sin_family = AF_INET;
88 server->sin_addr.s_addr = ESPHOME_INADDR_ANY;
89 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.
std::unique_ptr< Socket > socket(int domain, int type, int protocol)
Create a socket of the given domain, type and protocol.
std::unique_ptr< Socket > socket_ip_loop_monitored(int type, int protocol)
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().
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().
std::unique_ptr< Socket > socket_loop_monitored(int domain, int type, int protocol)
Create a socket and monitor it for data in the main loop.