Jump to content

  • Log In with Google      Sign In   
  • Create Account

Theres a standard way to find wich address have internet connection?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Icebone1000   Members   -  Reputation: 438

Like
0Likes
Like

Posted 07 March 2013 - 08:24 AM

Ive been long away from networking programming, but something just poped back to my head.

Winsock returns only a list of addresses avliable on your machine, he doesnt give you the "WAN address" with internet connection..if I remember correctly..

 

How does programs like browsers and other stuff finds out witch address to use? they ping all of them to a private server or something?



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 4933

Like
0Likes
Like

Posted 07 March 2013 - 09:13 AM

You mention browsers, but I don't see why they typically need to know what the actual address on the other side of the NAT is. Anything special you had in mind? And does your own program really need to know it?

 

If you have a multiplayer game but don't provide a match making service (just match two or more players, and have the connect to each other without an intermediate game server), or something similar, then you may need to inform the users about what address to connect to and you cannot list the local addresses since they are often non-routable. But if you do have a match making service, or again something similar, then your server already knows the actual address from the incoming connection to your server.



#3 hplus0603   Moderators   -  Reputation: 3376

Like
0Likes
Like

Posted 07 March 2013 - 10:50 AM

A browser doesn't need to know the local address. It needs to know the remote address to connect to. The remote address for a particular site (say, www.gamedev.net) is stored and looked up using the DNS system.
enum Bool { True, False, FileNotFound };

#4 Icebone1000   Members   -  Reputation: 438

Like
0Likes
Like

Posted 07 March 2013 - 11:38 AM

Im doing confusion..I forgot that the client socket dont need to bind to an address..

 

Ok, its p2p stuff, and forget a bit about nat stuff..

 

The server needs to bind to an address with available internet connection, thats what Im interested, how to find it?

 

 My last p2p application opened a diag box with all the addresses available, so the user would pick one to bind the server, and also there was a menuitem to input an address to connect to (due the "who will be the server" annoying factor, the app could act as a server or client, manually, there was 2 options: "wait for client" and "connect to").

 

 

A more practical example:

On zsnesw 1.36, you can play p2p, theres 2 options, "start as a server" and "connect to server", the option "start as a server" get the the correct IP address with internet connection, automatically. How? How can he know is that one, between all the ones available?


Edited by Icebone1000, 07 March 2013 - 11:56 AM.


#5 rip-off   Moderators   -  Reputation: 5310

Like
2Likes
Like

Posted 07 March 2013 - 03:43 PM

The server needs to bind to an address with available internet connection, thats what Im interested, how to find it?

Don't bind to a specific address, unless you have advanced needs (such as creating a host-only service that is not reachable from the local area network). Use INADDR_ANY or the equivalent in your networking API.

 

On zsnesw 1.36, you can play p2p, theres 2 options, "start as a server" and "connect to server", the option "start as a server" get the the correct IP address with internet connection, automatically. How? How can he know is that one, between all the ones available?

The only "reliable" way to do this is to ask a service on the internet what your public address appears to be. There may be a number of layers of NAT devices and other hurdles between the user's computer and the public internet.

 

To work with NAT devices, you'll need to buy or build such a public service that can be used by players to locate and "punch through" to each other.

 

Despite the name, most peer to peer modes do rely on a central server for discovery and punch through.



#6 Icebone1000   Members   -  Reputation: 438

Like
0Likes
Like

Posted 07 March 2013 - 05:56 PM

Don't bind to a specific address, unless you have advanced needs (such as creating a host-only service that is not reachable from the local area network). Use INADDR_ANY or the equivalent in your networking API.

I didnt know you could bind without a specific address o.o

In the book Network Programming For MS Windows it says:

"Once the socket of a particular protocol is created, you must bind it to a well-known address. The bind function associates the given socket with a well-known address"

Damn books..(but I really like this one)

On msdn, thou:

"If an application does not care what local address is assigned, specify the constant value INADDR_ANY for an IPv4 local address or the constant value in6addr_any for an IPv6 local address in the sa_data member of the name parameter. This allows the underlying service provider to use any appropriate network address, potentially simplifying application programming in the presence of multihomed hosts (that is, hosts that have more than one network interface and address)."

 

So, I can bind using INADDR_ANY, and rest assured that if I give to my friend my external address (found on google, whatever) its gonna work ?(consider I have the port used forwarded on the router, thats how my app worked)

 

Despite the name, most peer to peer modes do rely on a central server for discovery and punch through.

Despite that, is this the purpose of the Hamachi software or am I mistaked again?

Any inputs about solutions that dont require a server (a more "home" approach) to p2p software? uTorrent uses the upnp (universal plug and play) thing to open ports on the router automatically (witch is much better than asking your friend to do porting forward on his router and test your app, witch makes him block you on the msn forever), if the one supports it. Stuff like that.



#7 hplus0603   Moderators   -  Reputation: 3376

Like
0Likes
Like

Posted 07 March 2013 - 07:50 PM

That "you must bind" section sounds like it comes from a "server side" description. If you are building a server that accepts connections from other places, then yes, you must bind to a well-known address, so that other places can find you.
enum Bool { True, False, FileNotFound };

#8 Icebone1000   Members   -  Reputation: 438

Like
0Likes
Like

Posted 08 March 2013 - 06:31 AM

http://stackoverflow.com/questions/9726845/ip-address-when-multiple-nics-are-involved

 

"When calling listen() on a server socket, binding to INADDR_ANY will bind the socket to all available local IPs on the machine. That allows a client to connect to any of the server's IPs. If the server usesinet_addr() instead, that will be the only IP that the server can accept client connections on."

 

Thats clarifying. The post tells about the client socket too.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS