How do I get an IP address if I have a hostname, using JUCE?

Hi!

In my JUCE project I’m using a 3rd party library for zeroconf discovery, which gives me the hostname of the device to connect to.

Do you know how I can convert that hostname to an IP address, using methods in the JUCE library?
I’ve looked through the JUCE code base and forum but have not managed to find something, hopefully I haven’t missed something obvious.

Thanks!

There is the function getAddressInfo in the juce::SocketHelpers namespace (but I don’t know how to use it).

Hi!

Yes I found that one too, but it is not really for end-users, is it? It doesn’t seem to be exposed outside of the. cpp file.

You could #include that .cpp file, I suppose. Or you could just use the POSIX function directly (i.e., getaddrinfo()). Converting a URL to an IP address is not something an app usually needs to do internally. (If you’re making some kind of tool for users, they can always just ping the URL from the command line.)

Actually yes, that function is not particularly involved, and seems to be the same for Windows / OS X, so I just replicated it in my class and it worked fine, you were absolutely right.

Thank you!

1 Like