C++ Windows function call that get local hostname and IP address

Stan picture Stan · May 29, 2010 · Viewed 20.7k times · Source

Is there built-in windows C++ function call that can get hostname and IP address? Thanks.

Answer

Brian R. Bondy picture Brian R. Bondy · May 29, 2010

To get the hostname you can use: gethostname or the async method WSAAsyncGetHostByName

To get the address info, you can use: getaddrinfo or the unicode version GetAddrInfoW

You can get more information about the computer name like the domain by using the Win32 API: GetComputerNameEx.