query the socket name if an explicit address binding is requested on host creation

This commit is contained in:
Lee Salzman
2013-03-20 00:43:34 +02:00
parent eb7126c662
commit 726ff6bc6d
4 changed files with 32 additions and 1 deletions
+15
View File
@@ -125,6 +125,21 @@ enet_socket_bind (ENetSocket socket, const ENetAddress * address)
sizeof (struct sockaddr_in)) == SOCKET_ERROR ? -1 : 0;
}
int
enet_socket_get_address (ENetSocket socket, ENetAddress * address)
{
struct sockaddr_in sin;
int sinLength = sizeof (struct sockaddr_in);
if (getsockname (socket, (struct sockaddr *) & sin, & sinLength) == -1)
return -1;
address -> host = (enet_uint32) sin.sin_addr.s_addr;
address -> port = ENET_NET_TO_HOST_16 (sin.sin_port);
return 0;
}
int
enet_socket_listen (ENetSocket socket, int backlog)
{