summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/network/core/address.cpp1
-rw-r--r--src/network/network.cpp11
-rw-r--r--src/network/network_internal.h2
-rw-r--r--src/network/network_udp.cpp4
4 files changed, 8 insertions, 10 deletions
diff --git a/src/network/core/address.cpp b/src/network/core/address.cpp
index d8420b206..7d91aa9a4 100644
--- a/src/network/core/address.cpp
+++ b/src/network/core/address.cpp
@@ -124,6 +124,7 @@ static SOCKET ConnectLoopProc(addrinfo *runp)
if (connect(sock, runp->ai_addr, runp->ai_addrlen) != 0) {
DEBUG(net, 1, "Could not connect socket: %s", strerror(errno));
+ closesocket(sock);
return INVALID_SOCKET;
}
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 88206ae0c..8bf97e873 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -62,7 +62,6 @@ uint32 _frame_counter_max; // To where we may go with our clients
uint32 _frame_counter;
uint32 _last_sync_frame; // Used in the server to store the last time a sync packet was sent to clients.
uint32 _broadcast_list[MAX_INTERFACES + 1];
-uint32 _network_server_bind_ip;
uint32 _sync_seed_1, _sync_seed_2;
uint32 _sync_frame;
bool _network_first_time;
@@ -776,7 +775,7 @@ bool NetworkServerStart()
/* Try to start UDP-server */
_network_udp_server = true;
- _network_udp_server = _udp_server_socket->Listen(NetworkAddress(_network_server_bind_ip, _settings_client.network.server_port), false);
+ _network_udp_server = _udp_server_socket->Listen(NetworkAddress(_settings_client.network.server_bind_ip, _settings_client.network.server_port), false);
_network_company_states = CallocT<NetworkCompanyState>(MAX_COMPANIES);
_network_server = true;
@@ -1097,10 +1096,10 @@ void NetworkStartUp()
_network_need_advertise = true;
_network_advertise_retries = 0;
- /* Load the ip from the openttd.cfg */
- _network_server_bind_ip = inet_addr(_settings_client.network.server_bind_ip);
- /* And put the data back in it in case it was an invalid ip */
- snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
+ /* Set an ip when the hostname is empty */
+ if (StrEmpty(_settings_client.network.server_bind_ip)) {
+ snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", NetworkAddress().GetHostname());
+ }
/* Generate an unique id when there is none yet */
if (StrEmpty(_settings_client.network.network_id)) NetworkGenerateUniqueId();
diff --git a/src/network/network_internal.h b/src/network/network_internal.h
index 696d42828..c2ed87543 100644
--- a/src/network/network_internal.h
+++ b/src/network/network_internal.h
@@ -103,8 +103,6 @@ extern uint32 _last_sync_frame; // Used in the server to store the last time a s
/* networking settings */
extern uint32 _broadcast_list[MAX_INTERFACES + 1];
-extern uint32 _network_server_bind_ip;
-
extern uint32 _sync_seed_1, _sync_seed_2;
extern uint32 _sync_frame;
extern bool _network_first_time;
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index b49fa9bd9..01dad9cbc 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -483,7 +483,7 @@ void NetworkUDPRemoveAdvertise()
/* check for socket */
if (!_udp_master_socket->IsConnected()) {
- if (!_udp_master_socket->Listen(NetworkAddress(_network_server_bind_ip, 0), false)) return;
+ if (!_udp_master_socket->Listen(NetworkAddress(_settings_client.network.server_bind_ip, 0), false)) return;
}
if (!ThreadObject::New(NetworkUDPRemoveAdvertiseThread, NULL)) {
@@ -520,7 +520,7 @@ void NetworkUDPAdvertise()
/* check for socket */
if (!_udp_master_socket->IsConnected()) {
- if (!_udp_master_socket->Listen(NetworkAddress(_network_server_bind_ip, 0), false)) return;
+ if (!_udp_master_socket->Listen(NetworkAddress(_settings_client.network.server_bind_ip, 0), false)) return;
}
if (_network_need_advertise) {