[socket] Fix IPv6 address parsing for BSD sockets (#11996)

This commit is contained in:
David Woodhouse
2025-11-20 03:01:32 +00:00
committed by GitHub
parent 4398fd84d2
commit da25951f6e

View File

@@ -61,9 +61,18 @@ socklen_t set_sockaddr(struct sockaddr *addr, socklen_t addrlen, const std::stri
server->sin6_family = AF_INET6;
server->sin6_port = htons(port);
#ifdef USE_SOCKET_IMPL_BSD_SOCKETS
// Use standard inet_pton for BSD sockets
if (inet_pton(AF_INET6, ip_address.c_str(), &server->sin6_addr) != 1) {
errno = EINVAL;
return 0;
}
#else
// Use LWIP-specific functions
ip6_addr_t ip6;
inet6_aton(ip_address.c_str(), &ip6);
memcpy(server->sin6_addr.un.u32_addr, ip6.addr, sizeof(ip6.addr));
#endif
return sizeof(sockaddr_in6);
}
#endif /* USE_NETWORK_IPV6 */