[ENet-discuss] Getting the local IP address of the machine for the network where the enet host is.

Sebastian Ahlman sebastian.ahlman at gmail.com
Thu Feb 13 14:05:31 PST 2014


Hello,

I have a question about multiple local addresses and detecting which one is
the one for the network enet is using.

I am writing a game where you create an enet host which acts as the server,
and other players connect to the server as clients. I implemented basic NAT
punch through for the system which works fairly well. However, for some
setups I cannot seem to connect two computers to each other if they are in
the same local network. Because of this, I send the local address of each
computer along with the public address used for the punch through. If the
two hosts cannot reach each other after some time, they switch to using
their local addresses and usually that works fine.

To get local address of the machine I call gethostname() to get the name
and then gethostbyname() to get the hostent struct for the local machine.
The struct has a list of all the addresses for the machine.

The problem is that sometimes there are multiple addresses. For example,
installing the Windows 8 SDK creates a virtual network for Windows Phone 8
development. Passing this address as the local address obviously wont work.
So the question is, given a number of addresses, how do I determine which
one is the one which other computers can use to reach the enet host of this
machine?

PS: my hosts are created like so:

ENetAddress addr;
addr.host = ENET_HOST_ANY;
addr.port = portNumber;

Ie. the port is known, the address is not (?).

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubik.org/pipermail/enet-discuss/attachments/20140214/cf54024c/attachment-0001.html>


More information about the ENet-discuss mailing list