net: Consolidate the parsing of bootfile

The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
This commit is contained in:
Joe Hershberger
2018-07-03 19:36:43 -05:00
parent f43308fa0c
commit 6ab1283092
4 changed files with 34 additions and 25 deletions

View File

@@ -1517,6 +1517,26 @@ int is_serverip_in_cmd(void)
return !!strchr(net_boot_file_name, ':');
}
int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len)
{
char *colon;
if (net_boot_file_name[0] == '\0')
return 0;
colon = strchr(net_boot_file_name, ':');
if (colon) {
if (ipaddr)
*ipaddr = string_to_ip(net_boot_file_name);
strncpy(filename, colon + 1, max_len);
} else {
strncpy(filename, net_boot_file_name, max_len);
}
filename[max_len - 1] = '\0';
return 1;
}
#if defined(CONFIG_CMD_NFS) || \
defined(CONFIG_CMD_SNTP) || \
defined(CONFIG_CMD_DNS)