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