Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DNS.h Source File

DNS.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2018 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /** @file DNS.h Domain Name Service */
00018 /** @addtogroup netsocket
00019  * @{ */
00020 
00021 #ifndef DNS_H
00022 #define DNS_H
00023 
00024 /** Base class for DNS provider */
00025 class DNS {
00026 public:
00027 
00028     /** Translate a hostname to an IP address with specific version using network interface name.
00029      *
00030      *  The hostname may be either a domain name or an IP address. If the
00031      *  hostname is an IP address, no network transactions will be performed.
00032      *
00033      *  If no stack-specific DNS resolution is provided, the hostname
00034      *  will be resolve using a UDP socket on the stack.
00035      *
00036      *  @param host     Hostname to resolve.
00037      *  @param address  Pointer to a SocketAddress to store the result.
00038      *  @param version  IP version of address to resolve, NSAPI_UNSPEC indicates
00039      *                  version is chosen by the stack (defaults to NSAPI_UNSPEC).
00040      *  @param interface_name  Network interface name
00041      *  @return         NSAPI_ERROR_OK on success, negative error code on failure.
00042      */
00043     virtual nsapi_error_t gethostbyname(const char *host,
00044                                         SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC , const char *interface_name = NULL) = 0;
00045     /** Hostname translation callback for gethostbyname_async.
00046      *
00047      *  The callback is called after DNS resolution completes, or a failure occurs.
00048      *
00049      *  Callback should not take more than 10ms to execute, otherwise it might
00050      *  prevent underlying thread processing. A portable user of the callback
00051      *  should not make calls to network operations due to stack size limitations.
00052      *  The callback should not perform expensive operations such as socket recv/send
00053      *  calls or blocking operations.
00054      *
00055      *  @param result  NSAPI_ERROR_OK on success, negative error code on failure.
00056      *  @param address On success, destination for the host SocketAddress.
00057      */
00058     typedef mbed::Callback<void (nsapi_error_t result, SocketAddress *address)> hostbyname_cb_t;
00059 
00060     /** Translate a hostname to an IP address (asynchronous)
00061      *
00062      *  The hostname may be either a domain name or an IP address. If the
00063      *  hostname is an IP address, no network transactions will be performed.
00064      *
00065      *  If no stack-specific DNS resolution is provided, the hostname
00066      *  will be resolved using a UDP socket on the stack.
00067      *
00068      *  The call is non-blocking. The result of the DNS operation is returned by the callback.
00069      *  If this function returns failure, the callback will not be called. If it is successful,
00070      *  (the IP address was found from the DNS cache), the callback will be called
00071      *  before the function returns.
00072      *
00073      *  @param host     Hostname to resolve.
00074      *  @param callback Callback that is called to return the result.
00075      *  @param version  IP version of address to resolve. NSAPI_UNSPEC indicates that the
00076      *                  version is chosen by the stack (defaults to NSAPI_UNSPEC).
00077      *  @param interface_name  Network interface name
00078      *  @return         NSAPI_ERROR_OK on immediate success,
00079      *                  negative error code on immediate failure or
00080      *                  a positive unique ID that represents the hostname translation operation
00081      *                  and can be passed to cancel.
00082      */
00083     virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, nsapi_version_t version = NSAPI_UNSPEC ,
00084                                                        const char *interface_name = NULL) = 0;
00085 
00086     /** Cancel asynchronous hostname translation.
00087      *
00088      *  When translation is canceled, callback is not called.
00089      *
00090      *  @param id       Unique ID of the hostname translation operation returned by gethostbyname_async.
00091      *  @return         NSAPI_ERROR_OK on success, negative error code on failure.
00092      */
00093     virtual nsapi_error_t gethostbyname_async_cancel(int id) = 0;
00094 
00095     /** Add a domain name server to list of servers to query.
00096      *
00097      *  @param address  DNS server host address.
00098      *  @param interface_name  Network interface name
00099      *  @return         NSAPI_ERROR_OK on success, negative error code on failure.
00100      */
00101     virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name = NULL) = 0;
00102 };
00103 
00104 #endif
00105 
00106 /** @} */