aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGene Cumm <gene.cumm@gmail.com>2013-07-18 11:20:49 -0400
committerGene Cumm <gene.cumm@gmail.com>2014-01-08 06:35:02 -0500
commitc7b71e2641e91d8d8c2c818d1108cd35b9b641c3 (patch)
treebd81193213effc9709fcf06020dbd972d34ac196 /core
parentdbe7f9fdb797047522d588cffcbe5681e12b5807 (diff)
downloadsyslinux-c7b71e2641e91d8d8c2c818d1108cd35b9b641c3.tar.gz
syslinux-c7b71e2641e91d8d8c2c818d1108cd35b9b641c3.tar.xz
syslinux-c7b71e2641e91d8d8c2c818d1108cd35b9b641c3.zip
core/legacynet: Enable dot quad resolution
in dnsresolv.c:dns_resolv() Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/legacynet/dnsresolv.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/core/legacynet/dnsresolv.c b/core/legacynet/dnsresolv.c
index fab36aef..fdbe795c 100644
--- a/core/legacynet/dnsresolv.c
+++ b/core/legacynet/dnsresolv.c
@@ -170,6 +170,37 @@ extern uint16_t get_port(void);
extern void free_port(uint16_t port);
/*
+ * parse the ip_str and return the ip address with *res.
+ * return true if the whole string was consumed and the result
+ * was valid.
+ *
+ */
+static bool parse_dotquad(const char *ip_str, uint32_t *res)
+{
+ const char *p = ip_str;
+ uint8_t part = 0;
+ uint32_t ip = 0;
+ int i;
+
+ for (i = 0; i < 4; i++) {
+ while (is_digit(*p)) {
+ part = part * 10 + *p - '0';
+ p++;
+ }
+ if (i != 3 && *p != '.')
+ return false;
+
+ ip = (ip << 8) | part;
+ part = 0;
+ p++;
+ }
+ p--;
+
+ *res = htonl(ip);
+ return *p == '\0';
+}
+
+/*
* Actual resolver function
* Points to a null-terminated or :-terminated string in _name_
* and returns the ip addr in _ip_ if it exists and can be found.
@@ -209,6 +240,10 @@ __export uint32_t dns_resolv(const char *name)
if (!name || !*name)
return 0;
+ /* If it is a valid dot quad, just return that value */
+ if (parse_dotquad(name, &result))
+ return result;
+
/* Make sure we have at least one valid DNS server */
if (!dns_server[0])
return 0;