Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of DnsQuery by
Diff: DnsQuery.cpp
- Branch:
- api-changes
- Revision:
- 7:cbe1ef566314
- Parent:
- 6:5b28cbc8169c
- Child:
- 9:16e5208cc4ef
diff -r 5b28cbc8169c -r cbe1ef566314 DnsQuery.cpp
--- a/DnsQuery.cpp Mon Feb 22 19:58:10 2016 -0600
+++ b/DnsQuery.cpp Tue Feb 23 01:24:53 2016 -0600
@@ -46,6 +46,11 @@
bool DnsQuery::getHostByName(const char* hostname, char* resolvedIp)
{
+ if (isIP(hostname)) {
+ strcpy(resolvedIp, hostname);
+ return true;
+ }
+
const char * dnsIPs[] = {
"8.8.8.8",
"209.244.0.3",
@@ -64,6 +69,24 @@
}
+bool DnsQuery::isIP(const char* hostname) const
+{
+ int i;
+
+ for (i = 0; hostname[i]; i++) {
+ if (!(hostname[i] >= '0' && hostname[i] <= '9') && hostname[i] != '.') {
+ return false;
+ }
+ }
+
+ // Ending with '.' garuntees hostname
+ if (i > 0 && hostname[i-1] == '.') {
+ return false;
+ }
+
+ return true;
+}
+
bool DnsQuery::getIP(const char* hostname, char* ipaddress)
{
INFO("%s", hostname);
