28 memcpy(m_server, server,
sizeof(m_server));
30 return (sock !=
NULL);
48 if (
INET::aton(hostname, addr, progmem) == 0)
return (0);
57 request.ID =
hton((int16_t) ID);
58 request.FC =
hton(QUERY_FLAG | OPCODE_STANDARD_QUERY | RECURSION_DESIRED_FLAG);
66 attr.TYPE =
hton(TYPE_A);
67 attr.CLASS =
hton(CLASS_IN);
70 for (int8_t retry = 0; retry < RETRY_MAX; retry++) {
72 m_sock->
write(&request,
sizeof(request));
73 m_sock->
write(path, len);
74 m_sock->
write(&attr,
sizeof(attr));
79 for (uint16_t i = 0; i < TIMEOUT; i += 32) {
80 if ((res = m_sock->
available()) != 0)
break;
83 if (res == 0)
continue;
86 uint8_t response[128];
89 res = m_sock->
recv(response,
sizeof(response), dest, port);
93 header_t* header = (header_t*) response;
94 ntoh((int16_t*) header, (int16_t*) header,
sizeof(header_t) / 2);
95 if (header->ID != ID)
continue;
96 uint8_t* ptr = &response[
sizeof(header_t)];
100 while ((n = *ptr++) != 0) ptr += n;
101 ptr +=
sizeof(attr_t);
104 for (uint16_t i = 0; i < header->ANC; i++) {
107 if ((n & LABEL_COMPRESSION_MASK) == 0) {
108 if ((n & 0x80) == 0) {
117 rec_t* rec = (rec_t*) ptr;
118 ntoh((int16_t*) rec, (int16_t*) rec,
sizeof(rec_t) / 2);
119 ptr +=
sizeof(rec_t);
121 if (rec->TYPE != TYPE_A)
continue;
122 if (rec->CLASS != CLASS_IN)
continue;
virtual int recv(void *buf, size_t len)=0
virtual int write(const void *buf, size_t size)
bool begin(Socket *sock, uint8_t server[4])
static int aton(const char *addr, uint8_t ip[IP_MAX], bool progmem=false)
virtual int datagram(uint8_t addr[4], uint16_t port)=0
void(* delay)(uint32_t ms)
static const uint8_t IP_MAX
static const uint16_t PORT
static const uint8_t PATH_MAX
int gethostbyname(const char *hostname, uint8_t ip[4])
static int nametopath(const char *hostname, char *path, bool progmem=false)