@@ -234,7 +234,7 @@ int main(int argc, char *argv[])
234234
235235 char * pid_file_path = nullptr ;
236236 char * keys_file_path = nullptr ;
237- int port ;
237+ int start_port ;
238238 int enable_ipv6 ;
239239 int enable_ipv4_fallback ;
240240 int enable_lan_discovery ;
@@ -244,16 +244,16 @@ int main(int argc, char *argv[])
244244 int enable_motd ;
245245 char * motd = nullptr ;
246246
247- if (get_general_config (cfg_file_path , & pid_file_path , & keys_file_path , & port , & enable_ipv6 , & enable_ipv4_fallback ,
247+ if (get_general_config (cfg_file_path , & pid_file_path , & keys_file_path , & start_port , & enable_ipv6 , & enable_ipv4_fallback ,
248248 & enable_lan_discovery , & enable_tcp_relay , & tcp_relay_ports , & tcp_relay_port_count , & enable_motd , & motd )) {
249249 log_write (LOG_LEVEL_INFO , "General config read successfully\n" );
250250 } else {
251251 log_write (LOG_LEVEL_ERROR , "Couldn't read config file: %s. Exiting.\n" , cfg_file_path );
252252 return 1 ;
253253 }
254254
255- if (port < MIN_ALLOWED_PORT || port > MAX_ALLOWED_PORT ) {
256- log_write (LOG_LEVEL_ERROR , "Invalid port: %d, should be in [%d, %d]. Exiting.\n" , port , MIN_ALLOWED_PORT ,
255+ if (start_port < MIN_ALLOWED_PORT || start_port > MAX_ALLOWED_PORT ) {
256+ log_write (LOG_LEVEL_ERROR , "Invalid port: %d, should be in [%d, %d]. Exiting.\n" , start_port , MIN_ALLOWED_PORT ,
257257 MAX_ALLOWED_PORT );
258258 free (motd );
259259 free (tcp_relay_ports );
@@ -277,14 +277,15 @@ int main(int argc, char *argv[])
277277 logger_callback_log (logger , toxcore_logger_callback , nullptr , nullptr );
278278 }
279279
280- Networking_Core * net = new_networking (logger , & ip , port );
280+ const uint16_t end_port = start_port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM );
281+ Networking_Core * net = new_networking_ex (logger , & ip , start_port , end_port , nullptr );
281282
282283 if (net == nullptr ) {
283284 if (enable_ipv6 && enable_ipv4_fallback ) {
284285 log_write (LOG_LEVEL_WARNING , "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n" );
285286 enable_ipv6 = 0 ;
286287 ip_init (& ip , enable_ipv6 );
287- net = new_networking (logger , & ip , port );
288+ net = new_networking_ex (logger , & ip , start_port , end_port , nullptr );
288289
289290 if (net == nullptr ) {
290291 log_write (LOG_LEVEL_ERROR , "Couldn't fallback to IPv4. Exiting.\n" );
@@ -470,7 +471,7 @@ int main(int argc, char *argv[])
470471 print_public_key (dht_get_self_public_key (dht ));
471472
472473 uint64_t last_LANdiscovery = 0 ;
473- const uint16_t net_htons_port = net_htons (port );
474+ const uint16_t net_htons_port = net_htons (start_port );
474475
475476 int waiting_for_dht_connection = 1 ;
476477
0 commit comments