1818#define NSAPI_DNS_H
1919
2020#include " nsapi_types.h"
21+ #ifdef __cplusplus
2122#include " network-socket/NetworkStack.h"
23+ #endif
24+
25+ #ifndef __cplusplus
2226
2327
2428/* * Query a domain name server for an IP address of a given hostname
2529 *
2630 * @param stack Network stack as target for DNS query
2731 * @param addr Destination for the host address
2832 * @param host Hostname to resolve
29- * @param version IP version to resolve (defaults to NSAPI_IPv4)
33+ * @param version IP version to resolve
3034 * @return 0 on success, negative error code on failure
3135 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
3236 */
33- NSAPI_C_LINKAGE
3437int nsapi_dns_query (nsapi_stack_t *stack, nsapi_addr_t *addr,
3538 const char *host, nsapi_version_t version);
3639
37- #ifdef __cplusplus
38- int nsapi_dns_query (nsapi_stack_t *stack, nsapi_addr_t *addr,
39- const char *host);
40+ /* * Query a domain name server for multiple IP address of a given hostname
41+ *
42+ * @param stack Network stack as target for DNS query
43+ * @param addr Array for the host addresses
44+ * @param addr_count Number of addresses allocated in the array
45+ * @param host Hostname to resolve
46+ * @param version IP version to resolve
47+ * @return Number of addresses found on success, negative error code on failure
48+ * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
49+ */
50+ int nsapi_dns_query_multiple (nsapi_stack_t *stack,
51+ nsapi_addr_t *addr, unsigned addr_count,
52+ const char *host, nsapi_version_t version);
53+
54+ /* * Add a domain name server to list of servers to query
55+ *
56+ * @param addr Destination for the host address
57+ * @return 0 on success, negative error code on failure
58+ */
59+ int nsapi_dns_add_server (nsapi_addr_t addr);
60+
61+
62+ #else
63+
64+
65+ /* * Query a domain name server for an IP address of a given hostname
66+ *
67+ * @param stack Network stack as target for DNS query
68+ * @param addr Destination for the host address
69+ * @param host Hostname to resolve
70+ * @param version IP version to resolve (defaults to NSAPI_IPv4)
71+ * @return 0 on success, negative error code on failure
72+ * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
73+ */
4074int nsapi_dns_query (NetworkStack *stack, SocketAddress *addr,
4175 const char *host, nsapi_version_t version = NSAPI_IPv4);
4276
77+ /* * Query a domain name server for an IP address of a given hostname
78+ *
79+ * @param stack Network stack as target for DNS query
80+ * @param addr Destination for the host address
81+ * @param host Hostname to resolve
82+ * @param version IP version to resolve (defaults to NSAPI_IPv4)
83+ * @return 0 on success, negative error code on failure
84+ * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
85+ */
86+ extern " C" int nsapi_dns_query (nsapi_stack_t *stack, nsapi_addr_t *addr,
87+ const char *host, nsapi_version_t version = NSAPI_IPv4);
88+
89+ /* * Query a domain name server for an IP address of a given hostname
90+ *
91+ * @param stack Network stack as target for DNS query
92+ * @param addr Destination for the host address
93+ * @param host Hostname to resolve
94+ * @param version IP version to resolve (defaults to NSAPI_IPv4)
95+ * @return 0 on success, negative error code on failure
96+ * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
97+ */
4398template <typename S>
4499int nsapi_dns_query (S *stack, SocketAddress *addr,
45100 const char *host, nsapi_version_t version = NSAPI_IPv4)
46101{
47102 return nsapi_dns_query (nsapi_create_stack (stack), addr, host, version);
48103}
49- #endif
50-
51104
52105/* * Query a domain name server for multiple IP address of a given hostname
53106 *
@@ -59,19 +112,34 @@ int nsapi_dns_query(S *stack, SocketAddress *addr,
59112 * @return Number of addresses found on success, negative error code on failure
60113 * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
61114 */
62- NSAPI_C_LINKAGE
63- int nsapi_dns_query_multiple (nsapi_stack_t *stack,
64- nsapi_addr_t *addr, unsigned addr_count,
65- const char *host, nsapi_version_t version);
66-
67- #ifdef __cplusplus
68- int nsapi_dns_query_multiple (nsapi_stack_t *stack,
69- nsapi_addr_t *addr, unsigned addr_count,
70- const char *host);
71115int nsapi_dns_query_multiple (NetworkStack *stack,
72116 SocketAddress *addr, unsigned addr_count,
73117 const char *host, nsapi_version_t version = NSAPI_IPv4);
74118
119+ /* * Query a domain name server for multiple IP address of a given hostname
120+ *
121+ * @param stack Network stack as target for DNS query
122+ * @param addr Array for the host addresses
123+ * @param addr_count Number of addresses allocated in the array
124+ * @param host Hostname to resolve
125+ * @param version IP version to resolve (defaults to NSAPI_IPv4)
126+ * @return Number of addresses found on success, negative error code on failure
127+ * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
128+ */
129+ extern " C" int nsapi_dns_query_multiple (nsapi_stack_t *stack,
130+ nsapi_addr_t *addr, unsigned addr_count,
131+ const char *host, nsapi_version_t version = NSAPI_IPv4);
132+
133+ /* * Query a domain name server for multiple IP address of a given hostname
134+ *
135+ * @param stack Network stack as target for DNS query
136+ * @param addr Array for the host addresses
137+ * @param addr_count Number of addresses allocated in the array
138+ * @param host Hostname to resolve
139+ * @param version IP version to resolve (defaults to NSAPI_IPv4)
140+ * @return Number of addresses found on success, negative error code on failure
141+ * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
142+ */
75143template <typename S>
76144int nsapi_dns_query_multiple (S *stack,
77145 SocketAddress *addr, unsigned addr_count,
@@ -80,24 +148,35 @@ int nsapi_dns_query_multiple(S *stack,
80148 return nsapi_dns_query_multiple (nsapi_create_stack (stack),
81149 addr, addr_count, host, version);
82150}
83- #endif
84151
152+ /* * Add a domain name server to list of servers to query
153+ *
154+ * @param addr Destination for the host address
155+ * @return 0 on success, negative error code on failure
156+ */
157+ extern " C" int nsapi_dns_add_server (nsapi_addr_t addr);
85158
86159/* * Add a domain name server to list of servers to query
87160 *
88- * @param stack Network stack as target for DNS query
89161 * @param addr Destination for the host address
90- * @param host Hostname to resolve
91162 * @return 0 on success, negative error code on failure
92- * NSAPI_ERROR_DNS_FAILURE indicates the host could not be found
93163 */
94- NSAPI_C_LINKAGE
95- int nsapi_dns_add_server (nsapi_addr_t addr);
164+ static inline int nsapi_dns_add_server (const SocketAddress &address)
165+ {
166+ return nsapi_dns_add_server (address.get_addr ());
167+ }
168+
169+ /* * Add a domain name server to list of servers to query
170+ *
171+ * @param addr Destination for the host address
172+ * @return 0 on success, negative error code on failure
173+ */
174+ static inline int nsapi_dns_add_server (const char *address)
175+ {
176+ return nsapi_dns_add_server (SocketAddress (address));
177+ }
96178
97- #ifdef __cplusplus
98- int nsapi_dns_add_server (const SocketAddress &address);
99- int nsapi_dns_add_server (const char *address);
100- #endif
101179
180+ #endif
102181
103182#endif
0 commit comments