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

Author Topic: GetLocalAddress  (Read 10736 times)

0 Members and 3 Guests are viewing this topic.

TheMagicNumber

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
GetLocalAddress
« on: March 07, 2011, 10:17:17 pm »
Whenever I call GetLocalAddress, I get the localhost IP (127.0.0.1), is this normal? :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GetLocalAddress
« Reply #1 on: March 07, 2011, 10:21:44 pm »
No it shouldn't, unless you have a weird network configuration.

What is your actual local network address?
Laurent Gomila - SFML developer

TheMagicNumber

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
GetLocalAddress
« Reply #2 on: March 07, 2011, 10:23:53 pm »
It's 192.168.0.100.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GetLocalAddress
« Reply #3 on: March 07, 2011, 10:42:49 pm »
Can you show a minimal code that reproduces this problem, just to be sure? :)
Laurent Gomila - SFML developer

TheMagicNumber

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
GetLocalAddress
« Reply #4 on: March 07, 2011, 10:47:47 pm »
Alright, here:
Code: [Select]
#include <iostream>
#include <SFML/Network.hpp>

int main(int argc, char* argv) {
std::cout << sf::IpAddress::GetLocalAddress().ToString();
return 0;
}
Prints "127.0.0.1"

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GetLocalAddress
« Reply #5 on: March 07, 2011, 11:09:52 pm »
What is your OS?
Laurent Gomila - SFML developer

TheMagicNumber

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
GetLocalAddress
« Reply #6 on: March 07, 2011, 11:10:26 pm »
Windows 7 x64

I see you noticed that error of yours, by the way. ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GetLocalAddress
« Reply #7 on: March 07, 2011, 11:18:19 pm »
Everytime I post bullshit, I get caught before I edit my message :lol:
Laurent Gomila - SFML developer

TheMagicNumber

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
GetLocalAddress
« Reply #8 on: March 07, 2011, 11:41:48 pm »
Any ideas? ipconfig gives me the correct information.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GetLocalAddress
« Reply #9 on: March 08, 2011, 07:31:32 am »
No idea. Maybe you can play with the function's code directly and see if anything's wrong.
Laurent Gomila - SFML developer

TheMagicNumber

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
GetLocalAddress
« Reply #10 on: March 08, 2011, 02:40:14 pm »
All the stuff I found online that works used getaddrinfo() or gethostbyname().

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GetLocalAddress
« Reply #11 on: March 08, 2011, 02:47:30 pm »
Yes, there are other solutions. However getsockname on a local socket should be the best option, I'd like to understand why it fails on your machine (and not on any other Windows PC).
Laurent Gomila - SFML developer

TheMagicNumber

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
GetLocalAddress
« Reply #12 on: March 08, 2011, 03:00:35 pm »
Quote
If the socket is using a connectionless protocol, the address may not be available until I/O occurs on the socket.

From: http://msdn.microsoft.com/en-us/library/ms738543(v=vs.85).aspx

Is this relevant? I would probably assume that the function would return SOCKET_ERROR, though.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
GetLocalAddress
« Reply #13 on: March 08, 2011, 03:06:23 pm »
Hum...
Quote from: "MSDN"
If the socket is using a connectionless protocol, the address may not be available until I/O occurs on the socket.

Can you try to add this, between connect and gethostname?
Code: [Select]
char buffer[] = {0};
send(socket, buffer, 1, 0);

You can copy the function into your code directly if you don't want to recompile SFML. If you do so, you'll have to do the following replacements:
  • SocketHelper::SocketType --> SOCKET
  • SocketHelper::InvalidSocket() --> INVALID_SOCKET
  • SocketHelper::Close --> closesocket
Laurent Gomila - SFML developer

TheMagicNumber

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
GetLocalAddress
« Reply #14 on: March 08, 2011, 03:15:03 pm »
Nope. :(

 

anything