mirror of
https://github.com/espressif/openthread.git
synced 2026-08-30 05:49:54 +00:00
Add initial implementation of DNS Client (#1460)
* [DNS] Initial DNS Client implementation.
This commit is contained in:
committed by
Jonathan Hui
parent
0c95d6506e
commit
3316daa43c
@@ -55,6 +55,7 @@ openthread_headers = \
|
||||
diag.h \
|
||||
dhcp6_client.h \
|
||||
dhcp6_server.h \
|
||||
dns.h \
|
||||
icmp6.h \
|
||||
instance.h \
|
||||
ip6.h \
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2017, The OpenThread Authors.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
* This file defines the top-level dns functions for the OpenThread library.
|
||||
*/
|
||||
|
||||
#ifndef OPENTHREAD_DNS_H_
|
||||
#define OPENTHREAD_DNS_H_
|
||||
|
||||
#include <openthread/types.h>
|
||||
#include <openthread/message.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup dns DNS
|
||||
*
|
||||
* @brief
|
||||
* This module includes functions that control DNS communication.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
|
||||
#define OT_DNS_MAX_HOSTNAME_LENGTH 62 ///< Maximum allowed hostname length (maximum label size - 1 for compression).
|
||||
|
||||
#define OT_DNS_DEFAULT_DNS_SERVER_IP "2001:4860:4860::8888" ///< Defines default DNS Server address - Google DNS.
|
||||
#define OT_DNS_DEFAULT_DNS_SERVER_PORT 53 ///< Defines default DNS Server port.
|
||||
|
||||
/**
|
||||
* This structure implements DNS Query parameters.
|
||||
*
|
||||
*/
|
||||
typedef struct otDnsQuery
|
||||
{
|
||||
const char *mHostname; ///< Identifies hostname to be found. It shall not change during resolving.
|
||||
const otMessageInfo *mMessageInfo; ///< A reference to the message info related with DNS Server.
|
||||
bool mNoRecursion; ///< If cleared, it directs name server to pursue the query recursively.
|
||||
} otDnsQuery;
|
||||
|
||||
/**
|
||||
* This function pointer is called when a DNS response is received.
|
||||
*
|
||||
* @param[in] aContext A pointer to application-specific context.
|
||||
* @param[in] aHostname Identifies hostname related with DNS response.
|
||||
* @param[in] aAddress A pointer to the IPv6 address received in DNS response. May be null.
|
||||
* @param[in] aTtl Specifies the maximum time in seconds that the resource record may be cached.
|
||||
* @param[in] aResult A result of the DNS transaction.
|
||||
*
|
||||
* @retval kThreadError_None A response was received successfully and IPv6 address is provided
|
||||
* in @p aAddress.
|
||||
* @retval kThreadError_Abort A DNS transaction was aborted by stack.
|
||||
* @retval kThreadError_ResponseTimeout No DNS response has been received within timeout.
|
||||
* @retval kThreadError_NotFound A response was received but no IPv6 address has been found.
|
||||
* @retval kThreadError_Failed A response was received but status code is different than success.
|
||||
*
|
||||
*/
|
||||
typedef void (*otDnsResponseHandler)(void *aContext, const char *aHostname, otIp6Address *aAddress,
|
||||
uint32_t aTtl, ThreadError aResult);
|
||||
|
||||
#if OPENTHREAD_ENABLE_DNS_CLIENT
|
||||
/**
|
||||
* This function sends a DNS query for AAAA (IPv6) record.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[in] aQuery A pointer to specify DNS query parameters.
|
||||
* @param[in] aHandler A function pointer that shall be called on response reception or time-out.
|
||||
* @param[in] aContext A pointer to arbitrary context information.
|
||||
*
|
||||
*/
|
||||
ThreadError otDnsClientQuery(otInstance *aInstance, const otDnsQuery *aQuery, otDnsResponseHandler aHandler,
|
||||
void *aContext);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif // OPENTHREAD_DNS_H_
|
||||
@@ -185,7 +185,7 @@ typedef enum ThreadError
|
||||
kThreadError_NotCapable = 29,
|
||||
|
||||
/**
|
||||
* Coap response or acknowledgment not received.
|
||||
* Coap response or acknowledgment or DNS response not received.
|
||||
*/
|
||||
kThreadError_ResponseTimeout = 30,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user