aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGene Cumm <gene.cumm@gmail.com>2013-07-18 11:20:49 -0400
committerGene Cumm <gene.cumm@gmail.com>2013-07-18 11:20:49 -0400
commit82d3dcee9ed95423a5bc7dc8159a576e9fc04431 (patch)
tree9edcdfa9e5c56f52ed834ad33080177c70ffa9f9
parent89794a3d0b8659e2a143faeffc77877b45754c52 (diff)
downloadsyslinux-82d3dcee9ed95423a5bc7dc8159a576e9fc04431.tar.gz
syslinux-82d3dcee9ed95423a5bc7dc8159a576e9fc04431.tar.xz
syslinux-82d3dcee9ed95423a5bc7dc8159a576e9fc04431.zip
core/legacynet: Enable dot quad resolution
in dnsresolv.c:dns_resolv() Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
-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;