Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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