summaryrefslogtreecommitdiffhomepage
path: root/unix.c
diff options
context:
space:
mode:
authorLee Salzman <[email protected]>2013-03-20 00:43:34 +0200
committerLee Salzman <[email protected]>2013-03-20 00:43:34 +0200
commit726ff6bc6d0f596b8ff067f5ac10708d385767d3 (patch)
treeac1513268123d886149a40ff568f9443c424c173 /unix.c
parenteb7126c66225d04aff084e19274e15a43db884d4 (diff)
downloadenet-726ff6bc6d0f596b8ff067f5ac10708d385767d3.tar.gz
enet-726ff6bc6d0f596b8ff067f5ac10708d385767d3.zip
query the socket name if an explicit address binding is requested on host creation
Diffstat (limited to 'unix.c')
-rw-r--r--unix.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/unix.c b/unix.c
index d425b4b..fe8a280 100644
--- a/unix.c
+++ b/unix.c
@@ -194,6 +194,21 @@ enet_socket_bind (ENetSocket socket, const ENetAddress * address)
sizeof (struct sockaddr_in));
}
+int
+enet_socket_get_address (ENetSocket socket, ENetAddress * address)
+{
+ struct sockaddr_in sin;
+ socklen_t 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)
{