takashi kadono
/
Nucleo_446
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/features/netsocket/nsapi_dns.h@3:f3764f852aa8, 2018-10-11 (annotated)
- Committer:
- kadonotakashi
- Date:
- Thu Oct 11 02:27:46 2018 +0000
- Revision:
- 3:f3764f852aa8
- Parent:
- 0:8fdf9a60065b
Nucreo 446 + SSD1331 test version;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | |
kadonotakashi | 0:8fdf9a60065b | 2 | /** \addtogroup netsocket */ |
kadonotakashi | 0:8fdf9a60065b | 3 | /** @{*/ |
kadonotakashi | 0:8fdf9a60065b | 4 | /* nsapi_dns.h |
kadonotakashi | 0:8fdf9a60065b | 5 | * Original work Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de) |
kadonotakashi | 0:8fdf9a60065b | 6 | * Modified work Copyright (c) 2015 ARM Limited |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 9 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 10 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 11 | * |
kadonotakashi | 0:8fdf9a60065b | 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 13 | * |
kadonotakashi | 0:8fdf9a60065b | 14 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 17 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 18 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 19 | */ |
kadonotakashi | 0:8fdf9a60065b | 20 | #ifndef NSAPI_DNS_H |
kadonotakashi | 0:8fdf9a60065b | 21 | #define NSAPI_DNS_H |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | #include "nsapi_types.h" |
kadonotakashi | 0:8fdf9a60065b | 24 | #ifdef __cplusplus |
kadonotakashi | 0:8fdf9a60065b | 25 | #include "netsocket/NetworkStack.h" |
kadonotakashi | 0:8fdf9a60065b | 26 | #endif |
kadonotakashi | 0:8fdf9a60065b | 27 | |
kadonotakashi | 0:8fdf9a60065b | 28 | #ifndef __cplusplus |
kadonotakashi | 0:8fdf9a60065b | 29 | |
kadonotakashi | 0:8fdf9a60065b | 30 | |
kadonotakashi | 0:8fdf9a60065b | 31 | /** Query a domain name server for an IP address of a given hostname |
kadonotakashi | 0:8fdf9a60065b | 32 | * |
kadonotakashi | 0:8fdf9a60065b | 33 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 34 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 35 | * @param addr Destination for the host address |
kadonotakashi | 0:8fdf9a60065b | 36 | * @param version IP version to resolve |
kadonotakashi | 0:8fdf9a60065b | 37 | * @return 0 on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 38 | * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 39 | */ |
kadonotakashi | 0:8fdf9a60065b | 40 | nsapi_error_t nsapi_dns_query(nsapi_stack_t *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 41 | nsapi_addr_t *addr, nsapi_version_t version); |
kadonotakashi | 0:8fdf9a60065b | 42 | |
kadonotakashi | 0:8fdf9a60065b | 43 | /** Query a domain name server for multiple IP address of a given hostname |
kadonotakashi | 0:8fdf9a60065b | 44 | * |
kadonotakashi | 0:8fdf9a60065b | 45 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 46 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 47 | * @param addr Array for the host addresses |
kadonotakashi | 0:8fdf9a60065b | 48 | * @param addr_count Number of addresses allocated in the array |
kadonotakashi | 0:8fdf9a60065b | 49 | * @param version IP version to resolve |
kadonotakashi | 0:8fdf9a60065b | 50 | * @return Number of addresses found on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 51 | * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 52 | */ |
kadonotakashi | 0:8fdf9a60065b | 53 | nsapi_size_or_error_t nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 54 | nsapi_addr_t *addr, nsapi_size_t addr_count, nsapi_version_t version); |
kadonotakashi | 0:8fdf9a60065b | 55 | |
kadonotakashi | 0:8fdf9a60065b | 56 | /** Add a domain name server to list of servers to query |
kadonotakashi | 0:8fdf9a60065b | 57 | * |
kadonotakashi | 0:8fdf9a60065b | 58 | * @param addr Destination for the host address |
kadonotakashi | 0:8fdf9a60065b | 59 | * @return 0 on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 60 | */ |
kadonotakashi | 0:8fdf9a60065b | 61 | nsapi_error_t nsapi_dns_add_server(nsapi_addr_t addr); |
kadonotakashi | 0:8fdf9a60065b | 62 | |
kadonotakashi | 0:8fdf9a60065b | 63 | |
kadonotakashi | 0:8fdf9a60065b | 64 | #else |
kadonotakashi | 0:8fdf9a60065b | 65 | |
kadonotakashi | 0:8fdf9a60065b | 66 | typedef mbed::Callback<nsapi_error_t (int delay_ms, mbed::Callback<void()> user_cb)> call_in_callback_cb_t; |
kadonotakashi | 0:8fdf9a60065b | 67 | |
kadonotakashi | 0:8fdf9a60065b | 68 | /** Query a domain name server for an IP address of a given hostname |
kadonotakashi | 0:8fdf9a60065b | 69 | * |
kadonotakashi | 0:8fdf9a60065b | 70 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 71 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 72 | * @param addr Destination for the host address |
kadonotakashi | 0:8fdf9a60065b | 73 | * @param version IP version to resolve (defaults to NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 74 | * @return 0 on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 75 | * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 76 | */ |
kadonotakashi | 0:8fdf9a60065b | 77 | nsapi_error_t nsapi_dns_query(NetworkStack *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 78 | SocketAddress *addr, nsapi_version_t version = NSAPI_IPv4); |
kadonotakashi | 0:8fdf9a60065b | 79 | |
kadonotakashi | 0:8fdf9a60065b | 80 | /** Query a domain name server for an IP address of a given hostname |
kadonotakashi | 0:8fdf9a60065b | 81 | * |
kadonotakashi | 0:8fdf9a60065b | 82 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 83 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 84 | * @param callback Callback that is called for result |
kadonotakashi | 0:8fdf9a60065b | 85 | * @param version IP version to resolve (defaults to NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 86 | * @return 0 on success, negative error code on failure or an unique id that |
kadonotakashi | 0:8fdf9a60065b | 87 | * represents the hostname translation operation and can be passed to |
kadonotakashi | 0:8fdf9a60065b | 88 | * cancel, NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 89 | */ |
kadonotakashi | 0:8fdf9a60065b | 90 | nsapi_error_t nsapi_dns_query_async(NetworkStack *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 91 | NetworkStack::hostbyname_cb_t callback, call_in_callback_cb_t call_in_cb, |
kadonotakashi | 0:8fdf9a60065b | 92 | nsapi_version_t version = NSAPI_IPv4); |
kadonotakashi | 0:8fdf9a60065b | 93 | |
kadonotakashi | 0:8fdf9a60065b | 94 | /** Query a domain name server for an IP address of a given hostname (asynchronous) |
kadonotakashi | 0:8fdf9a60065b | 95 | * |
kadonotakashi | 0:8fdf9a60065b | 96 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 97 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 98 | * @param addr Destination for the host address |
kadonotakashi | 0:8fdf9a60065b | 99 | * @param version IP version to resolve (defaults to NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 100 | * @return 0 on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 101 | * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 102 | */ |
kadonotakashi | 0:8fdf9a60065b | 103 | extern "C" nsapi_error_t nsapi_dns_query(nsapi_stack_t *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 104 | nsapi_addr_t *addr, nsapi_version_t version = NSAPI_IPv4); |
kadonotakashi | 0:8fdf9a60065b | 105 | |
kadonotakashi | 0:8fdf9a60065b | 106 | /** Query a domain name server for an IP address of a given hostname |
kadonotakashi | 0:8fdf9a60065b | 107 | * |
kadonotakashi | 0:8fdf9a60065b | 108 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 109 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 110 | * @param addr Destination for the host address |
kadonotakashi | 0:8fdf9a60065b | 111 | * @param version IP version to resolve (defaults to NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 112 | * @return 0 on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 113 | * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 114 | */ |
kadonotakashi | 0:8fdf9a60065b | 115 | template <typename S> |
kadonotakashi | 0:8fdf9a60065b | 116 | nsapi_error_t nsapi_dns_query(S *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 117 | SocketAddress *addr, nsapi_version_t version = NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 118 | { |
kadonotakashi | 0:8fdf9a60065b | 119 | return nsapi_dns_query(nsapi_create_stack(stack), host, addr, version); |
kadonotakashi | 0:8fdf9a60065b | 120 | } |
kadonotakashi | 0:8fdf9a60065b | 121 | |
kadonotakashi | 0:8fdf9a60065b | 122 | /** Query a domain name server for multiple IP address of a given hostname |
kadonotakashi | 0:8fdf9a60065b | 123 | * |
kadonotakashi | 0:8fdf9a60065b | 124 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 125 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 126 | * @param addr Array for the host addresses |
kadonotakashi | 0:8fdf9a60065b | 127 | * @param addr_count Number of addresses allocated in the array |
kadonotakashi | 0:8fdf9a60065b | 128 | * @param version IP version to resolve (defaults to NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 129 | * @return Number of addresses found on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 130 | * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 131 | */ |
kadonotakashi | 0:8fdf9a60065b | 132 | nsapi_size_or_error_t nsapi_dns_query_multiple(NetworkStack *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 133 | SocketAddress *addr, nsapi_size_t addr_count, nsapi_version_t version = NSAPI_IPv4); |
kadonotakashi | 0:8fdf9a60065b | 134 | |
kadonotakashi | 0:8fdf9a60065b | 135 | /** Query a domain name server for an IP address of a given hostname (asynchronous) |
kadonotakashi | 0:8fdf9a60065b | 136 | * |
kadonotakashi | 0:8fdf9a60065b | 137 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 138 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 139 | * @param callback Callback that is called for result |
kadonotakashi | 0:8fdf9a60065b | 140 | * @param addr_count Number of addresses allocated in the array |
kadonotakashi | 0:8fdf9a60065b | 141 | * @param version IP version to resolve (defaults to NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 142 | * @return 0 on success, negative error code on failure or an unique id that |
kadonotakashi | 0:8fdf9a60065b | 143 | represents the hostname translation operation and can be passed to |
kadonotakashi | 0:8fdf9a60065b | 144 | * cancel, NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 145 | */ |
kadonotakashi | 0:8fdf9a60065b | 146 | nsapi_size_or_error_t nsapi_dns_query_multiple_async(NetworkStack *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 147 | NetworkStack::hostbyname_cb_t callback, nsapi_size_t addr_count, |
kadonotakashi | 0:8fdf9a60065b | 148 | call_in_callback_cb_t call_in_cb, nsapi_version_t version = NSAPI_IPv4); |
kadonotakashi | 0:8fdf9a60065b | 149 | |
kadonotakashi | 0:8fdf9a60065b | 150 | /** Query a domain name server for multiple IP address of a given hostname |
kadonotakashi | 0:8fdf9a60065b | 151 | * |
kadonotakashi | 0:8fdf9a60065b | 152 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 153 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 154 | * @param addr Array for the host addresses |
kadonotakashi | 0:8fdf9a60065b | 155 | * @param addr_count Number of addresses allocated in the array |
kadonotakashi | 0:8fdf9a60065b | 156 | * @param version IP version to resolve (defaults to NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 157 | * @return Number of addresses found on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 158 | * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 159 | */ |
kadonotakashi | 0:8fdf9a60065b | 160 | extern "C" nsapi_size_or_error_t nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 161 | nsapi_addr_t *addr, nsapi_size_t addr_count, nsapi_version_t version = NSAPI_IPv4); |
kadonotakashi | 0:8fdf9a60065b | 162 | |
kadonotakashi | 0:8fdf9a60065b | 163 | |
kadonotakashi | 0:8fdf9a60065b | 164 | /** Query a domain name server for multiple IP address of a given hostname |
kadonotakashi | 0:8fdf9a60065b | 165 | * |
kadonotakashi | 0:8fdf9a60065b | 166 | * @param stack Network stack as target for DNS query |
kadonotakashi | 0:8fdf9a60065b | 167 | * @param host Hostname to resolve |
kadonotakashi | 0:8fdf9a60065b | 168 | * @param addr Array for the host addresses |
kadonotakashi | 0:8fdf9a60065b | 169 | * @param addr_count Number of addresses allocated in the array |
kadonotakashi | 0:8fdf9a60065b | 170 | * @param version IP version to resolve (defaults to NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 171 | * @return Number of addresses found on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 172 | * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found |
kadonotakashi | 0:8fdf9a60065b | 173 | */ |
kadonotakashi | 0:8fdf9a60065b | 174 | template <typename S> |
kadonotakashi | 0:8fdf9a60065b | 175 | nsapi_size_or_error_t nsapi_dns_query_multiple(S *stack, const char *host, |
kadonotakashi | 0:8fdf9a60065b | 176 | SocketAddress *addr, nsapi_size_t addr_count, nsapi_version_t version = NSAPI_IPv4) |
kadonotakashi | 0:8fdf9a60065b | 177 | { |
kadonotakashi | 0:8fdf9a60065b | 178 | return nsapi_dns_query_multiple(nsapi_create_stack(stack), |
kadonotakashi | 0:8fdf9a60065b | 179 | host, addr, addr_count, version); |
kadonotakashi | 0:8fdf9a60065b | 180 | } |
kadonotakashi | 0:8fdf9a60065b | 181 | |
kadonotakashi | 0:8fdf9a60065b | 182 | /** Cancels asynchronous hostname translation |
kadonotakashi | 0:8fdf9a60065b | 183 | * |
kadonotakashi | 0:8fdf9a60065b | 184 | * When translation is cancelled, callback will not be called. |
kadonotakashi | 0:8fdf9a60065b | 185 | * |
kadonotakashi | 0:8fdf9a60065b | 186 | * @param id Unique id of the hostname translation operation |
kadonotakashi | 0:8fdf9a60065b | 187 | * @return 0 on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 188 | */ |
kadonotakashi | 0:8fdf9a60065b | 189 | nsapi_error_t nsapi_dns_query_async_cancel(nsapi_error_t id); |
kadonotakashi | 0:8fdf9a60065b | 190 | |
kadonotakashi | 0:8fdf9a60065b | 191 | /** Set a call in callback |
kadonotakashi | 0:8fdf9a60065b | 192 | * |
kadonotakashi | 0:8fdf9a60065b | 193 | * Can be used to provide an application specific call in callback to |
kadonotakashi | 0:8fdf9a60065b | 194 | * DNS resolver. When callback is set it is used instead of stack |
kadonotakashi | 0:8fdf9a60065b | 195 | * specific call in callbacks. |
kadonotakashi | 0:8fdf9a60065b | 196 | * |
kadonotakashi | 0:8fdf9a60065b | 197 | * @param callback Callback |
kadonotakashi | 0:8fdf9a60065b | 198 | */ |
kadonotakashi | 0:8fdf9a60065b | 199 | void nsapi_dns_call_in_set(call_in_callback_cb_t callback); |
kadonotakashi | 0:8fdf9a60065b | 200 | |
kadonotakashi | 0:8fdf9a60065b | 201 | /** Add a domain name server to list of servers to query |
kadonotakashi | 0:8fdf9a60065b | 202 | * |
kadonotakashi | 0:8fdf9a60065b | 203 | * @param addr Destination for the host address |
kadonotakashi | 0:8fdf9a60065b | 204 | * @return 0 on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 205 | */ |
kadonotakashi | 0:8fdf9a60065b | 206 | extern "C" nsapi_error_t nsapi_dns_add_server(nsapi_addr_t addr); |
kadonotakashi | 0:8fdf9a60065b | 207 | |
kadonotakashi | 0:8fdf9a60065b | 208 | /** Add a domain name server to list of servers to query |
kadonotakashi | 0:8fdf9a60065b | 209 | * |
kadonotakashi | 0:8fdf9a60065b | 210 | * @param addr Destination for the host address |
kadonotakashi | 0:8fdf9a60065b | 211 | * @return 0 on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 212 | */ |
kadonotakashi | 0:8fdf9a60065b | 213 | static inline nsapi_error_t nsapi_dns_add_server(const SocketAddress &address) |
kadonotakashi | 0:8fdf9a60065b | 214 | { |
kadonotakashi | 0:8fdf9a60065b | 215 | return nsapi_dns_add_server(address.get_addr()); |
kadonotakashi | 0:8fdf9a60065b | 216 | } |
kadonotakashi | 0:8fdf9a60065b | 217 | |
kadonotakashi | 0:8fdf9a60065b | 218 | /** Add a domain name server to list of servers to query |
kadonotakashi | 0:8fdf9a60065b | 219 | * |
kadonotakashi | 0:8fdf9a60065b | 220 | * @param addr Destination for the host address |
kadonotakashi | 0:8fdf9a60065b | 221 | * @return 0 on success, negative error code on failure |
kadonotakashi | 0:8fdf9a60065b | 222 | */ |
kadonotakashi | 0:8fdf9a60065b | 223 | static inline nsapi_error_t nsapi_dns_add_server(const char *address) |
kadonotakashi | 0:8fdf9a60065b | 224 | { |
kadonotakashi | 0:8fdf9a60065b | 225 | return nsapi_dns_add_server(SocketAddress(address)); |
kadonotakashi | 0:8fdf9a60065b | 226 | } |
kadonotakashi | 0:8fdf9a60065b | 227 | |
kadonotakashi | 0:8fdf9a60065b | 228 | |
kadonotakashi | 0:8fdf9a60065b | 229 | #endif |
kadonotakashi | 0:8fdf9a60065b | 230 | |
kadonotakashi | 0:8fdf9a60065b | 231 | #endif |
kadonotakashi | 0:8fdf9a60065b | 232 | |
kadonotakashi | 0:8fdf9a60065b | 233 | /** @}*/ |