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.
DNS.h
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 #ifndef DNS_H 00018 #define DNS_H 00019 00020 class DNS { 00021 public: 00022 00023 /** Translates a hostname to an IP address with specific version 00024 * 00025 * The hostname may be either a domain name or an IP address. If the 00026 * hostname is an IP address, no network transactions will be performed. 00027 * 00028 * If no stack-specific DNS resolution is provided, the hostname 00029 * will be resolve using a UDP socket on the stack. 00030 * 00031 * @param host Hostname to resolve 00032 * @param address Destination for the host SocketAddress 00033 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates 00034 * version is chosen by the stack (defaults to NSAPI_UNSPEC) 00035 * @return 0 on success, negative error code on failure 00036 */ 00037 virtual nsapi_error_t gethostbyname(const char *host, 00038 SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC ) = 0; 00039 00040 /** Hostname translation callback (asynchronous) 00041 * 00042 * Callback will be called after DNS resolution completes or a failure occurs. 00043 * 00044 * Callback should not take more than 10ms to execute, otherwise it might 00045 * prevent underlying thread processing. A portable user of the callback 00046 * should not make calls to network operations due to stack size limitations. 00047 * The callback should not perform expensive operations such as socket recv/send 00048 * calls or blocking operations. 00049 * 00050 * @param status 0 on success, negative error code on failure 00051 * @param address On success, destination for the host SocketAddress 00052 */ 00053 typedef mbed::Callback<void (nsapi_error_t result, SocketAddress *address)> hostbyname_cb_t; 00054 00055 /** Translates a hostname to an IP address (asynchronous) 00056 * 00057 * The hostname may be either a domain name or an IP address. If the 00058 * hostname is an IP address, no network transactions will be performed. 00059 * 00060 * If no stack-specific DNS resolution is provided, the hostname 00061 * will be resolve using a UDP socket on the stack. 00062 * 00063 * Call is non-blocking. Result of the DNS operation is returned by the callback. 00064 * If this function returns failure, callback will not be called. In case result 00065 * is success (IP address was found from DNS cache), callback will be called 00066 * before function returns. 00067 * 00068 * @param host Hostname to resolve 00069 * @param callback Callback that is called for result 00070 * @param version IP version of address to resolve, NSAPI_UNSPEC indicates 00071 * version is chosen by the stack (defaults to NSAPI_UNSPEC) 00072 * @return 0 on immediate success, 00073 * negative error code on immediate failure or 00074 * a positive unique id that represents the hostname translation operation 00075 * and can be passed to cancel 00076 */ 00077 virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, 00078 nsapi_version_t version = NSAPI_UNSPEC ) = 0; 00079 00080 /** Cancels asynchronous hostname translation 00081 * 00082 * When translation is cancelled, callback will not be called. 00083 * 00084 * @param id Unique id of the hostname translation operation 00085 * @return 0 on success, negative error code on failure 00086 */ 00087 virtual nsapi_error_t gethostbyname_async_cancel(int id) = 0; 00088 00089 /** Add a domain name server to list of servers to query 00090 * 00091 * @param address Destination for the host address 00092 * @return 0 on success, negative error code on failure 00093 */ 00094 virtual nsapi_error_t add_dns_server(const SocketAddress &address) = 0; 00095 }; 00096 00097 #endif
Generated on Tue Jul 12 2022 12:43:49 by
