Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1
marcozecchini 0:9fca2b23d0ba 2 /** \addtogroup netsocket */
marcozecchini 0:9fca2b23d0ba 3 /** @{*/
marcozecchini 0:9fca2b23d0ba 4 /* nsapi_dns.h
marcozecchini 0:9fca2b23d0ba 5 * Original work Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
marcozecchini 0:9fca2b23d0ba 6 * Modified work Copyright (c) 2015 ARM Limited
marcozecchini 0:9fca2b23d0ba 7 *
marcozecchini 0:9fca2b23d0ba 8 * Licensed under the Apache License, Version 2.0 (the "License");
marcozecchini 0:9fca2b23d0ba 9 * you may not use this file except in compliance with the License.
marcozecchini 0:9fca2b23d0ba 10 * You may obtain a copy of the License at
marcozecchini 0:9fca2b23d0ba 11 *
marcozecchini 0:9fca2b23d0ba 12 * http://www.apache.org/licenses/LICENSE-2.0
marcozecchini 0:9fca2b23d0ba 13 *
marcozecchini 0:9fca2b23d0ba 14 * Unless required by applicable law or agreed to in writing, software
marcozecchini 0:9fca2b23d0ba 15 * distributed under the License is distributed on an "AS IS" BASIS,
marcozecchini 0:9fca2b23d0ba 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
marcozecchini 0:9fca2b23d0ba 17 * See the License for the specific language governing permissions and
marcozecchini 0:9fca2b23d0ba 18 * limitations under the License.
marcozecchini 0:9fca2b23d0ba 19 */
marcozecchini 0:9fca2b23d0ba 20 #ifndef NSAPI_DNS_H
marcozecchini 0:9fca2b23d0ba 21 #define NSAPI_DNS_H
marcozecchini 0:9fca2b23d0ba 22
marcozecchini 0:9fca2b23d0ba 23 #include "nsapi_types.h"
marcozecchini 0:9fca2b23d0ba 24 #ifdef __cplusplus
marcozecchini 0:9fca2b23d0ba 25 #include "netsocket/NetworkStack.h"
marcozecchini 0:9fca2b23d0ba 26 #endif
marcozecchini 0:9fca2b23d0ba 27
marcozecchini 0:9fca2b23d0ba 28 #ifndef __cplusplus
marcozecchini 0:9fca2b23d0ba 29
marcozecchini 0:9fca2b23d0ba 30
marcozecchini 0:9fca2b23d0ba 31 /** Query a domain name server for an IP address of a given hostname
marcozecchini 0:9fca2b23d0ba 32 *
marcozecchini 0:9fca2b23d0ba 33 * @param stack Network stack as target for DNS query
marcozecchini 0:9fca2b23d0ba 34 * @param host Hostname to resolve
marcozecchini 0:9fca2b23d0ba 35 * @param addr Destination for the host address
marcozecchini 0:9fca2b23d0ba 36 * @param version IP version to resolve
marcozecchini 0:9fca2b23d0ba 37 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 38 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
marcozecchini 0:9fca2b23d0ba 39 */
marcozecchini 0:9fca2b23d0ba 40 nsapi_error_t nsapi_dns_query(nsapi_stack_t *stack, const char *host,
marcozecchini 0:9fca2b23d0ba 41 nsapi_addr_t *addr, nsapi_version_t version);
marcozecchini 0:9fca2b23d0ba 42
marcozecchini 0:9fca2b23d0ba 43 /** Query a domain name server for multiple IP address of a given hostname
marcozecchini 0:9fca2b23d0ba 44 *
marcozecchini 0:9fca2b23d0ba 45 * @param stack Network stack as target for DNS query
marcozecchini 0:9fca2b23d0ba 46 * @param host Hostname to resolve
marcozecchini 0:9fca2b23d0ba 47 * @param addr Array for the host addresses
marcozecchini 0:9fca2b23d0ba 48 * @param addr_count Number of addresses allocated in the array
marcozecchini 0:9fca2b23d0ba 49 * @param version IP version to resolve
marcozecchini 0:9fca2b23d0ba 50 * @return Number of addresses found on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 51 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
marcozecchini 0:9fca2b23d0ba 52 */
marcozecchini 0:9fca2b23d0ba 53 nsapi_size_or_error_t nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host,
marcozecchini 0:9fca2b23d0ba 54 nsapi_addr_t *addr, nsapi_size_t addr_count, nsapi_version_t version);
marcozecchini 0:9fca2b23d0ba 55
marcozecchini 0:9fca2b23d0ba 56 /** Add a domain name server to list of servers to query
marcozecchini 0:9fca2b23d0ba 57 *
marcozecchini 0:9fca2b23d0ba 58 * @param addr Destination for the host address
marcozecchini 0:9fca2b23d0ba 59 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 60 */
marcozecchini 0:9fca2b23d0ba 61 nsapi_error_t nsapi_dns_add_server(nsapi_addr_t addr);
marcozecchini 0:9fca2b23d0ba 62
marcozecchini 0:9fca2b23d0ba 63
marcozecchini 0:9fca2b23d0ba 64 #else
marcozecchini 0:9fca2b23d0ba 65
marcozecchini 0:9fca2b23d0ba 66
marcozecchini 0:9fca2b23d0ba 67 /** Query a domain name server for an IP address of a given hostname
marcozecchini 0:9fca2b23d0ba 68 *
marcozecchini 0:9fca2b23d0ba 69 * @param stack Network stack as target for DNS query
marcozecchini 0:9fca2b23d0ba 70 * @param host Hostname to resolve
marcozecchini 0:9fca2b23d0ba 71 * @param addr Destination for the host address
marcozecchini 0:9fca2b23d0ba 72 * @param version IP version to resolve (defaults to NSAPI_IPv4)
marcozecchini 0:9fca2b23d0ba 73 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 74 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
marcozecchini 0:9fca2b23d0ba 75 */
marcozecchini 0:9fca2b23d0ba 76 nsapi_error_t nsapi_dns_query(NetworkStack *stack, const char *host,
marcozecchini 0:9fca2b23d0ba 77 SocketAddress *addr, nsapi_version_t version = NSAPI_IPv4);
marcozecchini 0:9fca2b23d0ba 78
marcozecchini 0:9fca2b23d0ba 79 /** Query a domain name server for an IP address of a given hostname
marcozecchini 0:9fca2b23d0ba 80 *
marcozecchini 0:9fca2b23d0ba 81 * @param stack Network stack as target for DNS query
marcozecchini 0:9fca2b23d0ba 82 * @param host Hostname to resolve
marcozecchini 0:9fca2b23d0ba 83 * @param addr Destination for the host address
marcozecchini 0:9fca2b23d0ba 84 * @param version IP version to resolve (defaults to NSAPI_IPv4)
marcozecchini 0:9fca2b23d0ba 85 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 86 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
marcozecchini 0:9fca2b23d0ba 87 */
marcozecchini 0:9fca2b23d0ba 88 extern "C" nsapi_error_t nsapi_dns_query(nsapi_stack_t *stack, const char *host,
marcozecchini 0:9fca2b23d0ba 89 nsapi_addr_t *addr, nsapi_version_t version = NSAPI_IPv4);
marcozecchini 0:9fca2b23d0ba 90
marcozecchini 0:9fca2b23d0ba 91 /** Query a domain name server for an IP address of a given hostname
marcozecchini 0:9fca2b23d0ba 92 *
marcozecchini 0:9fca2b23d0ba 93 * @param stack Network stack as target for DNS query
marcozecchini 0:9fca2b23d0ba 94 * @param host Hostname to resolve
marcozecchini 0:9fca2b23d0ba 95 * @param addr Destination for the host address
marcozecchini 0:9fca2b23d0ba 96 * @param version IP version to resolve (defaults to NSAPI_IPv4)
marcozecchini 0:9fca2b23d0ba 97 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 98 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
marcozecchini 0:9fca2b23d0ba 99 */
marcozecchini 0:9fca2b23d0ba 100 template <typename S>
marcozecchini 0:9fca2b23d0ba 101 nsapi_error_t nsapi_dns_query(S *stack, const char *host,
marcozecchini 0:9fca2b23d0ba 102 SocketAddress *addr, nsapi_version_t version = NSAPI_IPv4)
marcozecchini 0:9fca2b23d0ba 103 {
marcozecchini 0:9fca2b23d0ba 104 return nsapi_dns_query(nsapi_create_stack(stack), host, addr, version);
marcozecchini 0:9fca2b23d0ba 105 }
marcozecchini 0:9fca2b23d0ba 106
marcozecchini 0:9fca2b23d0ba 107 /** Query a domain name server for multiple IP address of a given hostname
marcozecchini 0:9fca2b23d0ba 108 *
marcozecchini 0:9fca2b23d0ba 109 * @param stack Network stack as target for DNS query
marcozecchini 0:9fca2b23d0ba 110 * @param host Hostname to resolve
marcozecchini 0:9fca2b23d0ba 111 * @param addr Array for the host addresses
marcozecchini 0:9fca2b23d0ba 112 * @param addr_count Number of addresses allocated in the array
marcozecchini 0:9fca2b23d0ba 113 * @param version IP version to resolve (defaults to NSAPI_IPv4)
marcozecchini 0:9fca2b23d0ba 114 * @return Number of addresses found on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 115 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
marcozecchini 0:9fca2b23d0ba 116 */
marcozecchini 0:9fca2b23d0ba 117 nsapi_size_or_error_t nsapi_dns_query_multiple(NetworkStack *stack, const char *host,
marcozecchini 0:9fca2b23d0ba 118 SocketAddress *addr, nsapi_size_t addr_count, nsapi_version_t version = NSAPI_IPv4);
marcozecchini 0:9fca2b23d0ba 119
marcozecchini 0:9fca2b23d0ba 120 /** Query a domain name server for multiple IP address of a given hostname
marcozecchini 0:9fca2b23d0ba 121 *
marcozecchini 0:9fca2b23d0ba 122 * @param stack Network stack as target for DNS query
marcozecchini 0:9fca2b23d0ba 123 * @param host Hostname to resolve
marcozecchini 0:9fca2b23d0ba 124 * @param addr Array for the host addresses
marcozecchini 0:9fca2b23d0ba 125 * @param addr_count Number of addresses allocated in the array
marcozecchini 0:9fca2b23d0ba 126 * @param version IP version to resolve (defaults to NSAPI_IPv4)
marcozecchini 0:9fca2b23d0ba 127 * @return Number of addresses found on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 128 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
marcozecchini 0:9fca2b23d0ba 129 */
marcozecchini 0:9fca2b23d0ba 130 extern "C" nsapi_size_or_error_t nsapi_dns_query_multiple(nsapi_stack_t *stack, const char *host,
marcozecchini 0:9fca2b23d0ba 131 nsapi_addr_t *addr, nsapi_size_t addr_count, nsapi_version_t version = NSAPI_IPv4);
marcozecchini 0:9fca2b23d0ba 132
marcozecchini 0:9fca2b23d0ba 133 /** Query a domain name server for multiple IP address of a given hostname
marcozecchini 0:9fca2b23d0ba 134 *
marcozecchini 0:9fca2b23d0ba 135 * @param stack Network stack as target for DNS query
marcozecchini 0:9fca2b23d0ba 136 * @param host Hostname to resolve
marcozecchini 0:9fca2b23d0ba 137 * @param addr Array for the host addresses
marcozecchini 0:9fca2b23d0ba 138 * @param addr_count Number of addresses allocated in the array
marcozecchini 0:9fca2b23d0ba 139 * @param version IP version to resolve (defaults to NSAPI_IPv4)
marcozecchini 0:9fca2b23d0ba 140 * @return Number of addresses found on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 141 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
marcozecchini 0:9fca2b23d0ba 142 */
marcozecchini 0:9fca2b23d0ba 143 template <typename S>
marcozecchini 0:9fca2b23d0ba 144 nsapi_size_or_error_t nsapi_dns_query_multiple(S *stack, const char *host,
marcozecchini 0:9fca2b23d0ba 145 SocketAddress *addr, nsapi_size_t addr_count, nsapi_version_t version = NSAPI_IPv4)
marcozecchini 0:9fca2b23d0ba 146 {
marcozecchini 0:9fca2b23d0ba 147 return nsapi_dns_query_multiple(nsapi_create_stack(stack),
marcozecchini 0:9fca2b23d0ba 148 host, addr, addr_count, version);
marcozecchini 0:9fca2b23d0ba 149 }
marcozecchini 0:9fca2b23d0ba 150
marcozecchini 0:9fca2b23d0ba 151 /** Add a domain name server to list of servers to query
marcozecchini 0:9fca2b23d0ba 152 *
marcozecchini 0:9fca2b23d0ba 153 * @param addr Destination for the host address
marcozecchini 0:9fca2b23d0ba 154 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 155 */
marcozecchini 0:9fca2b23d0ba 156 extern "C" nsapi_error_t nsapi_dns_add_server(nsapi_addr_t addr);
marcozecchini 0:9fca2b23d0ba 157
marcozecchini 0:9fca2b23d0ba 158 /** Add a domain name server to list of servers to query
marcozecchini 0:9fca2b23d0ba 159 *
marcozecchini 0:9fca2b23d0ba 160 * @param addr Destination for the host address
marcozecchini 0:9fca2b23d0ba 161 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 162 */
marcozecchini 0:9fca2b23d0ba 163 static inline nsapi_error_t nsapi_dns_add_server(const SocketAddress &address)
marcozecchini 0:9fca2b23d0ba 164 {
marcozecchini 0:9fca2b23d0ba 165 return nsapi_dns_add_server(address.get_addr());
marcozecchini 0:9fca2b23d0ba 166 }
marcozecchini 0:9fca2b23d0ba 167
marcozecchini 0:9fca2b23d0ba 168 /** Add a domain name server to list of servers to query
marcozecchini 0:9fca2b23d0ba 169 *
marcozecchini 0:9fca2b23d0ba 170 * @param addr Destination for the host address
marcozecchini 0:9fca2b23d0ba 171 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 172 */
marcozecchini 0:9fca2b23d0ba 173 static inline nsapi_error_t nsapi_dns_add_server(const char *address)
marcozecchini 0:9fca2b23d0ba 174 {
marcozecchini 0:9fca2b23d0ba 175 return nsapi_dns_add_server(SocketAddress(address));
marcozecchini 0:9fca2b23d0ba 176 }
marcozecchini 0:9fca2b23d0ba 177
marcozecchini 0:9fca2b23d0ba 178
marcozecchini 0:9fca2b23d0ba 179 #endif
marcozecchini 0:9fca2b23d0ba 180
marcozecchini 0:9fca2b23d0ba 181 #endif
marcozecchini 0:9fca2b23d0ba 182
marcozecchini 0:9fca2b23d0ba 183 /** @}*/