aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2016-04-06 13:02:13 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2016-04-06 13:02:13 -0700
commitb61bdc9acc1df765eec9b43e6f83846dfb8a70d0 (patch)
tree0df9e7b385f48eaef0ed977681fb0dea4b212889 /core
parentedb6d3e81a891331d0adea527dc4adbe45db64d4 (diff)
downloadsyslinux-b61bdc9acc1df765eec9b43e6f83846dfb8a70d0.tar.gz
syslinux-b61bdc9acc1df765eec9b43e6f83846dfb8a70d0.tar.xz
syslinux-b61bdc9acc1df765eec9b43e6f83846dfb8a70d0.zip
libupload: use url_set_ip()
We already have a core function for setting the IP address of an URL object based on network lookup or the server default. Export and use it instead of open-coding the equivalent logic in upload_tftp.c. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'core')
-rw-r--r--core/fs/pxe/pxe.c18
-rw-r--r--core/fs/pxe/url.h3
2 files changed, 17 insertions, 4 deletions
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index 9b1a7329..21763395 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -237,13 +237,25 @@ static uint32_t pxe_getfssec(struct file *file, char *buf,
/*
* Assign an IP address to a URL
*/
-static void url_set_ip(struct url_info *url)
+__export int url_set_ip(struct url_info *url)
{
+ int err = -ntohs(TFTP_OK);
+
url->ip = 0;
- if (url->host)
+ if (url->host && url->host[0]) {
url->ip = pxe_dns(url->host);
- if (!url->ip)
+ if (!url->ip)
+ err = -ntohs(TFTP_ERESOLVE);
+ }
+
+ /* Note: default to the server IP on resolve failure */
+ if (!url->ip) {
url->ip = IPInfo.serverip;
+ if (!url->ip)
+ err = -ntohs(TFTP_NONETWORK);
+ }make
+
+ return err;
}
/**
diff --git a/core/fs/pxe/url.h b/core/fs/pxe/url.h
index 53984f3a..93462004 100644
--- a/core/fs/pxe/url.h
+++ b/core/fs/pxe/url.h
@@ -19,7 +19,7 @@ struct url_info {
char *user;
char *passwd;
char *host;
- uint32_t ip; /* Placeholder field not set by parse_url() */
+ uint32_t ip; /* Not set by parse_url(), use url_set_ip() */
unsigned int port;
char *path; /* Includes query */
enum url_type type;
@@ -29,5 +29,6 @@ enum url_type url_type(const char *url);
void parse_url(struct url_info *ui, char *url);
size_t url_escape_unsafe(char *output, const char *input, size_t bufsize);
char *url_unescape(char *buffer, char terminator);
+int url_set_ip(struct url_info *ui);
#endif /* CORE_PXE_URL_H */