Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:27:58 2016 +0000
Revision:
0:6c56fb4bc5f0
Moving to library for sharing updates

Who changed what in which revision?

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