Alternative to gethostbyname

强颜欢笑 提交于 2019-12-05 07:50:58

Actually, getaddrinfo is what you want. It's just a long-winded way to do it, not to mention the fact that sometimes multiple IP addresses are found (e.g. one IPv4 address and one IPv6 address). I'd recommend looking at Beej's Guide to Network Programming, specifically getaddrinfo.

You can try things like WSAConnectByName, but getaddrinfo actually is what you want, here's simple example.

You can use gethostbyname2 which supports both IPV4 and IPV6 resolving.
This is an article that shows the difference between gethostbyname and getaddrinfo, it also discusses gethostbyname2.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!