-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathDns.cpp
More file actions
100 lines (84 loc) · 2.09 KB
/
Copy pathDns.cpp
File metadata and controls
100 lines (84 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Arduino DNS client for WizNet5100-based Ethernet shield
// (c) Copyright 2009-2010 MCQN Ltd.
// Released under Apache License, version 2.0
#include "EthernetUdp.h"
#include "utility/stm32_eth.h"
#include "Dns.h"
#include <string.h>
#include "Arduino.h"
// Possible return codes from ProcessResponse
#define SUCCESS 1
#define TIMED_OUT -1
#define INVALID_SERVER -2
#define TRUNCATED -3
#define INVALID_RESPONSE -4
void DNSClient::begin(const IPAddress &aDNSServer)
{
iDNSServer = aDNSServer;
stm32_dns_init(iDNSServer.raw_address());
}
int DNSClient::inet_aton(const char *address, IPAddress &result)
{
uint16_t acc = 0; // Accumulator
uint8_t dots = 0;
if (address == NULL) {
return 0;
}
while (*address) {
char c = *address++;
if (c >= '0' && c <= '9') {
acc = acc * 10 + (c - '0');
if (acc > 255) {
// Value out of [0..255] range
return 0;
}
} else if (c == '.') {
if (dots == 3) {
// Too much dots (there must be 3 dots)
return 0;
}
result[dots++] = acc;
acc = 0;
} else {
// Invalid char
return 0;
}
}
if (dots != 3) {
// Too few dots (there must be 3 dots)
return 0;
}
result[3] = acc;
return 1;
}
int DNSClient::getHostByName(const char *aHostname, IPAddress &aResult)
{
int ret = 0;
uint32_t ipResult = 0;
// See if it's a numeric IP address
if (inet_aton(aHostname, aResult)) {
// It is, our work here is done
return SUCCESS;
}
// Check we've got a valid DNS server to use
if (iDNSServer == INADDR_NONE) {
return INVALID_SERVER;
}
ret = stm32_dns_gethostbyname(aHostname, &ipResult);
aResult = IPAddress(ipResult);
return ret;
}
/* Deprecated function. Do not use anymore. */
uint16_t DNSClient::BuildRequest(const char *aName)
{
UNUSED(aName);
return 0;
}
/* Deprecated function. Do not use anymore. */
uint16_t DNSClient::ProcessResponse(uint16_t aTimeout, IPAddress &aAddress)
{
UNUSED(aTimeout);
UNUSED(aAddress);
// If we get here then we haven't found an answer
return -10;//INVALID_RESPONSE;
}