开发者

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 */
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜