6

I can't use gethostbyname to grab a host's IP address, it is a deprecated function that only works 10% of the fricken' time on Windows!

I can't find any adequate resources on other ways to find a host's IP address using other functions (MSDN recommended getaddrinfo but that doesn't seem like what I want.)

12

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.

9

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

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["<li class=\"-item\"><a href=\"https://www.facebook.com/officialstackoverflow/\" class=\"-link\">Facebook</a></li>\r\n                    <li class=\"-item\"><a href=\"https://twitter.com/stackoverflow\" class=\"-link\">Twitter</a></li>\r\n                    <li class=\"-item\"><a href=\"https://linkedin.com/company/stack-overflow\" class=\"-link\">LinkedIn</a></li>\r\n                </ul>\r\n\r\n                <p class=\"mt-auto mb24\">\r\nsite design / logo &#169; 2019 Stack Exchange Inc; user contributions licensed under <a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a>\r\n                            with <a href=\"https://stackoverflow.blog/2009/06/25/attribution-required/\" rel=\"license\">attribution required</a>.\r\n                    <span id=\"svnrev\">rev&nbsp;2019.7.17.34352</span>\r\n                </p>\r\n            </div>\r\n        </div>\r\n\r\n            </footer>\r\n            <script>StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); })</script>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works b"], "copyright__copyright__copyright": [" try things like WSAConnectByName, but getaddrinfo actually is what you want, here's simple example.\n\n1\n\nYou can use gethostbyname2 which supports both IPV4 and IPV6 resolving.\nThis is an article that shows the difference between gethostbyname and getaddrinfo, it also discusses gethostbyname2.\n\nYour Answer\n\nBy clicking \u201cPost Your Answer\u201d, you agree to our terms of service, privacy policy and cookie policy\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}