diff options
Diffstat (limited to 'unix.c')
-rw-r--r-- | unix.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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) { |