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.)

Ajay
  • 18,086
  • 12
  • 59
  • 105
Saustin
  • 1,117
  • 6
  • 15
  • 27
  • 4
    It might improve your chances of getting a useful answer if you explained why you think getaddrinfo isn't what you want. – Frank Boyne Jul 10 '11 at 04:00

3 Answers3

14

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.

10

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

Nikolai Fetissov
  • 82,306
  • 11
  • 110
  • 171
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.

Baron Leonardo
  • 329
  • 3
  • 13