我只需要我的全局IPv6地址而不是本地链接地址。我已按照msdn中的说明将ai_flags设置为AI_ADDRCONFIG。但GetAddrInfoW返回全局和本地链接地址。有什么方法可以从ADDRINFOW
结果结构中找出地址类型吗?
std::wstring whostname = L"hostname";
ADDRINFOW hints;
memset(&hints, 0, sizeof(ADDRINFOW));
hints.ai_family = AF_UNSPEC; // IPv4 and IPv6
hints.ai_socktype = SOCK_STREAM; // TCP only, no UDP
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_ADDRCONFIG; // Get only global IPv6 address
ADDRINFOW *list = NULL;
result = GetAddrInfoW(
whostname.c_str(),
NULL,
&hints,
&list
);