char ipstr[16] = {'\0'};
volatile int ret;
struct addrinfo *answer, hint, *curr;
bzero (&hint, sizeof (hint));
hint.ai_family = AF_UNSPEC;
hint.ai_socktype = SOCK_STREAM;
if ((ret = getaddrinfo(host.c_str(),NULL,&hint,&answer)) != 0) {
return ;
}
for (curr = answer; curr != NULL; curr = curr->ai_next) {
inet_ntop (curr->ai_family, &(((struct sockaddr_in *)(curr->ai_addr))->sin_addr), ipstr, sizeof (ipstr));
}
c++ DNS 域名解析实现
最新推荐文章于 2025-06-03 15:40:04 发布