Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: IpAddress::GetLocalAddress() returns 127.0.0.1  (Read 11051 times)

0 Members and 3 Guests are viewing this topic.

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
IpAddress::GetLocalAddress() returns 127.0.0.1
« on: January 23, 2012, 08:06:45 pm »
So as the title says, whenever I call IpAddress::GetLocalAddress(), it gives me the self-referential home address rather than the address other computers on the LAN will use to connect to it. 127.0.0.1 does me no good! Am I doing something wrong, or am I misusing this function?

(Sorry if I used wrong terminology or whatever--I'm new to network programming.)

Elgan

  • Jr. Member
  • **
  • Posts: 77
    • AOL Instant Messenger - Flat+1,+17+st+Cl
    • View Profile
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #1 on: January 23, 2012, 09:34:18 pm »
127.0.0.1 is local.

I have no used nore looked at the networking yet.

but I assume,...you will have to breadcast your a server over the network, or scan the network on a given port.


so what does
GetPublicAddress (Time timeout=Time::Zero)
    Get the computer's public address.
do?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #2 on: January 23, 2012, 10:02:42 pm »
Quote
127.0.0.1 is local.

127.0.0.1 is localhost, not the local network address (which is usually 192.168.0.x).

There was such a problem but it was fixed 5 months ago in SFML 2. Which version do you use?
Laurent Gomila - SFML developer

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #3 on: January 23, 2012, 10:06:51 pm »
Ah, okay, that's probably it. I haven't updated in a while. Thanks for the tip.

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #4 on: January 25, 2012, 02:54:44 am »
Hmm...so I updated SFML, but there is still a similar problem.

So there are to networks in my home. One is a network switch which is not connected to the internet, the other a router that is. When I am connected to the network with the router, GetLocalAddress works fine; but when I am connected to the network switch, GetLocalAddress returns the address 0.0.0.0 instead of the actual address. Could this be because it is a network switch instead of a router?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #5 on: January 25, 2012, 10:35:09 am »
What's your IP address when you're connected to the switch? (ipconfig on Windows, ifconfig on Linux)
Laurent Gomila - SFML developer

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #6 on: January 26, 2012, 04:08:52 am »
right now it's 169.254.40.22. But GetLocalAddress still thinks it's 0.0.0.0. Other computers can connect to it over the network, but I have to look up the address and type it in manually--SFML doesn't know what it is for some reason.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #7 on: January 26, 2012, 08:13:34 am »
Quote
right now it's 169.254.40.22

I think there's something special with your network configuration, but I don't know why it makes SFML fail to retrieve your local network address.

Can you step into the GetLocalAddress() function to see if it fails, and where?
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #8 on: January 26, 2012, 09:08:22 am »
169.254/16 IP addresses are used when manual configuration is disabled and DHCP setup failed. I guess your OS's "GetLocalAddress" function wasn't designed to manage such ip config.
SFML / OS X developer

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #9 on: January 26, 2012, 06:22:07 pm »
Okay, so I think I found where the problem is.

In IpAddress IpAddress::GetLocalAddress(), it returns prematurely right here:

Code: [Select]
// Connect the socket to localhost on any port
sockaddr_in address = CreateAddress(ntohl(INADDR_LOOPBACK), 0);
if (connect(sock, reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1)
{
    priv::SocketImpl::Close(sock);
    return localAddress;
}


So it looks like it is not the fault of SFML. Anyone know exactly what the problem is?

EDIT: FYI, my system is Windows XP SP2

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #10 on: January 26, 2012, 07:15:46 pm »
Quote
Anyone know exactly what the problem is?

Nop. Connecting a UDP socket actually does nothing, it should never fail.
Laurent Gomila - SFML developer

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #11 on: January 26, 2012, 07:39:41 pm »
Does it literally do nothing? If so, could I just comment out the call to connect? I think I will try that.

Edit: Well that didn't work. :/

I'm not good with networks...anyone have any suggestions for me?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #12 on: January 26, 2012, 07:49:42 pm »
Quote
Does it literally do nothing? If so, could I just comment out the call to connect? I think I will try that.

No... I didn't put this call just for fun, you know ;)

But since UDP is a connectionless protocol, all this call does is to store the host address and port. And it is normally enough so that the next call correctly returns the local network address.
Laurent Gomila - SFML developer

JayArby

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #13 on: January 26, 2012, 08:34:02 pm »
So how could I manually store the host address and port (what struct members I guess) to enable to skip the failing call?

EDIT: Hmm, it's not a struct, just a UINT_PTR. What is it really? a pointer to a sockaddr_in struct, perhaps?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
IpAddress::GetLocalAddress() returns 127.0.0.1
« Reply #14 on: January 26, 2012, 08:56:56 pm »
Quote
So how could I manually store the host address and port (what struct members I guess) to enable to skip the failing call?

You can't skip it, it's the low-level socket API, you can't emulate things that don't work. This code is a well known technique for retrieving the local network address, it is supposed to work out of the box.

To make it work we would probably need to find another technique, involving other functions. But I don't know any other way to get the local address.
Laurent Gomila - SFML developer