1

I know the remote machine name, this machine is on the same network.

If I ping that machine from command prompt, I get the IP information as well.

C:\Users\anikumar>ping neemqx01g

Pinging neemqx01g.efi.internal [10.210.98.194] with 32 bytes of data:
Reply from 10.210.98.194: bytes=32 time=2ms TTL=128
Reply from 10.210.98.194: bytes=32 time<1ms TTL=128
Reply from 10.210.98.194: bytes=32 time<1ms TTL=128
Reply from 10.210.98.194: bytes=32 time<1ms TTL=128

Ping statistics for 10.210.98.194:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 2ms, Average = 0ms

How can I achieve programmatically in wxWidgets or boost to get the IP address?

Answer:

C function:

const wxString GetIPbyName(const wxString& name)
{
    struct hostent* pHostInfo;
    pHostInfo = gethostbyname(name.c_str());

    in_addr * address = (in_addr *)pHostInfo->h_addr;
    std::string ip_address = inet_ntoa(*address);

    return ip_address;
}

wxWidgets:

   wxIPV4address ipv4;
   ipv4.Hostname(m_currentServer);
   wxString m_currentServer = ipv4.IPAddress();

I am not how above will behave in case of multiple active network cards.

Anil8753
  • 2,663
  • 4
  • 29
  • 40

2 Answers2

2

I've looked through the documentation for you and, you can't.

For portable network name lookups you could consider making use of a general-purpose cross-platform networking library, such as Boost.ASIO.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
1

C socket library is (almost) portable. You will have the old gethostbyaddr call or the newer getaddrinfo one.

But you will need some #ifdef to make them truely portable because:

  • headers are not the same netdb.h (and optionaly sys/types.h and sys/socket.h) on a Posix system and Ws2tcpip.h and winsock2.h on Windows
  • on windows, you need a call to WSAStartup to initialize winsock.
Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252