C++ convert struct hostent.h_addr_list IP to sockaddr struct
In my linux C++ application I have hostent struct whi开发者_如何转开发ch contains h_addr_list. I want the IP h_addr_list contains to be contain in struct sockaddr. do you know how to do it?
thanks.
gethostby*()
is an ancient relict. If you use getaddrinfo
/getnameinfo
instead, you get a proper struct sockaddr
.
struct addrinfo *res;
getaddrinfo("hostname", NULL, NULL, &res);
/* then see res->ai_addr */
精彩评论