dre*_*lax 13
您可以使用POSIX inet_pton将字符串转换为struct in6_addr.
#include <arpa/inet.h>
...
const char *ip6str = "::2";
struct in6_addr result;
if (inet_pton(AF_INET6, ip6str, &result) == 1) // success!
{
//successfully parsed string into "result"
}
else
{
//failed, perhaps not a valid representation of IPv6?
}
Run Code Online (Sandbox Code Playgroud)
Tha*_*tos 10
getaddrinfo()可以理解IPv6地址.在提示中将AF_INET6传递给它,以及AI_NUMERICHOST(以防止DNS查找).Linux拥有它,Windows在Windows XP中拥有它.