diff options
author | Gene Cumm <gene.cumm@gmail.com> | 2013-07-18 11:20:49 -0400 |
---|---|---|
committer | Gene Cumm <gene.cumm@gmail.com> | 2013-07-18 11:20:49 -0400 |
commit | 82d3dcee9ed95423a5bc7dc8159a576e9fc04431 (patch) | |
tree | 9edcdfa9e5c56f52ed834ad33080177c70ffa9f9 /core/legacynet/dnsresolv.c | |
parent | 89794a3d0b8659e2a143faeffc77877b45754c52 (diff) | |
download | syslinux-82d3dcee9ed95423a5bc7dc8159a576e9fc04431.tar.gz |
core/legacynet: Enable dot quad resolution
in dnsresolv.c:dns_resolv()
Signed-off-by: Gene Cumm <gene.cumm@gmail.com>
Diffstat (limited to 'core/legacynet/dnsresolv.c')
-rw-r--r-- | core/legacynet/dnsresolv.c | 35 |
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; |