diff --git a/src/net/udp/tftp.c b/src/net/udp/tftp.c index 953bcb46a..f3cb34342 100644 --- a/src/net/udp/tftp.c +++ b/src/net/udp/tftp.c @@ -1180,13 +1180,12 @@ struct uri_opener mtftp_uri_opener __uri_opener = { */ static int tftp_apply_settings ( void ) { static struct in_addr tftp_server = { 0 }; - struct in_addr last_tftp_server; + struct in_addr new_tftp_server; char uri_string[32]; struct uri *uri; /* Retrieve TFTP server setting */ - last_tftp_server = tftp_server; - fetch_ipv4_setting ( NULL, &next_server_setting, &tftp_server ); + fetch_ipv4_setting ( NULL, &next_server_setting, &new_tftp_server ); /* If TFTP server setting has changed, set the current working * URI to match. Do it only when the TFTP server has changed @@ -1195,18 +1194,19 @@ static int tftp_apply_settings ( void ) { * an unrelated setting and triggered all the settings * applicators. */ - if ( tftp_server.s_addr != last_tftp_server.s_addr ) { - if ( tftp_server.s_addr ) { - snprintf ( uri_string, sizeof ( uri_string ), - "tftp://%s/", inet_ntoa ( tftp_server ) ); - uri = parse_uri ( uri_string ); - if ( ! uri ) - return -ENOMEM; - } else { - uri = NULL; - } + if ( new_tftp_server.s_addr && + ( new_tftp_server.s_addr != tftp_server.s_addr ) ) { + DBGC ( &tftp_server, "TFTP server changed %s => ", + inet_ntoa ( tftp_server ) ); + DBGC ( &tftp_server, "%s\n", inet_ntoa ( new_tftp_server ) ); + snprintf ( uri_string, sizeof ( uri_string ), + "tftp://%s/", inet_ntoa ( new_tftp_server ) ); + uri = parse_uri ( uri_string ); + if ( ! uri ) + return -ENOMEM; churi ( uri ); uri_put ( uri ); + tftp_server = new_tftp_server; } return 0;