About Store Forum Documentation Contact



Post Reply 
find out ip on local network
Author Message
yvanvds Offline
Member

Post: #1
find out ip on local network
I'm using the SockAddr setLocal function to find out my local ip on a client program. But it always sets 127.0.0.1 as my local IP.

If I understand correctly, setLocalFast should set 127.0.0.1, setLocal should set the ip of the internal network (like 192.168.0.1) and setGlobal should set the public ip of my router. setLocalFast and setGlobal work as expected.

But is there any obvious reason why setLocal only sets 127.0.0.1? I do have a working network connection on this computer, ipconfig is returning the right address, i don't have a secondary network card active. I am also able to communicate with an external server.

Any ideas?
08-27-2013 08:21 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: find out ip on local network
Hi,

This did work on all the computers/networks that I've tested.

Could you let me know if this WinApi code works ok for you:
Code:
static Char8    Host[NI_MAXHOST];

     char service[NI_MAXSERV];
      Int  port=0;

      sockaddr_in addr;
      addr.sin_family     =AF_INET;
      addr.sin_addr.s_addr=16777343; // ip="127.0.0.1" localhost
      addr.sin_port       =htons(port);

      if(!GetNameInfoA((sockaddr*)&addr, SIZE(sockaddr), Host, Elms(Host), service, Elms(service), NI_NUMERICSERV))
      {
         // ok
      }
is the 'Host' value ok in the end? it should be a string to your host name
08-28-2013 09:48 AM
Find all posts by this user Quote this message in a reply
Post Reply