@@ -250,11 +250,29 @@ int ENetConnection::get_max_channels() const {
250250 return host->channelLimit ;
251251}
252252
253+ IPAddress ENetConnection::get_local_address () const {
254+ ERR_FAIL_NULL_V_MSG (host, IPAddress (), " The ENetConnection instance isn't currently active." );
255+ ERR_FAIL_COND_V_MSG (!(host->socket ), IPAddress (), " The ENetConnection instance isn't currently bound." );
256+ ENetAddress address;
257+ ERR_FAIL_COND_V_MSG (enet_socket_get_address (host->socket , &address), IPAddress (), " Unable to get socket address." );
258+
259+ IPAddress out;
260+ #ifdef GODOT_ENET
261+ out.set_ipv6 ((uint8_t *)&(address.host ));
262+ if (out == IPAddress (" ::" )) {
263+ return IPAddress (" *" );
264+ }
265+ #else
266+ out.set_ipv4 ((uint8_t *)&(address.host ));
267+ #endif
268+ return out;
269+ }
270+
253271int ENetConnection::get_local_port () const {
254272 ERR_FAIL_NULL_V_MSG (host, 0 , " The ENetConnection instance isn't currently active." );
255273 ERR_FAIL_COND_V_MSG (!(host->socket ), 0 , " The ENetConnection instance isn't currently bound." );
256274 ENetAddress address;
257- ERR_FAIL_COND_V_MSG (enet_socket_get_address (host->socket , &address), 0 , " Unable to get socket address" );
275+ ERR_FAIL_COND_V_MSG (enet_socket_get_address (host->socket , &address), 0 , " Unable to get socket address. " );
258276 return address.port ;
259277}
260278
@@ -387,6 +405,7 @@ void ENetConnection::_bind_methods() {
387405 ClassDB::bind_method (D_METHOD (" refuse_new_connections" , " refuse" ), &ENetConnection::refuse_new_connections);
388406 ClassDB::bind_method (D_METHOD (" pop_statistic" , " statistic" ), &ENetConnection::pop_statistic);
389407 ClassDB::bind_method (D_METHOD (" get_max_channels" ), &ENetConnection::get_max_channels);
408+ ClassDB::bind_method (D_METHOD (" get_local_address" ), &ENetConnection::get_local_address);
390409 ClassDB::bind_method (D_METHOD (" get_local_port" ), &ENetConnection::get_local_port);
391410 ClassDB::bind_method (D_METHOD (" get_peers" ), &ENetConnection::_get_peers);
392411 ClassDB::bind_method (D_METHOD (" socket_send" , " destination_address" , " destination_port" , " packet" ), &ENetConnection::socket_send);
0 commit comments