mdns.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef ESP_MDNS_H_
  14. #define ESP_MDNS_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <esp_netif.h>
  19. #include "esp_event.h"
  20. #define MDNS_TYPE_A 0x0001
  21. #define MDNS_TYPE_PTR 0x000C
  22. #define MDNS_TYPE_TXT 0x0010
  23. #define MDNS_TYPE_AAAA 0x001C
  24. #define MDNS_TYPE_SRV 0x0021
  25. #define MDNS_TYPE_OPT 0x0029
  26. #define MDNS_TYPE_NSEC 0x002F
  27. #define MDNS_TYPE_ANY 0x00FF
  28. /**
  29. * @brief Asynchronous query handle
  30. */
  31. typedef struct mdns_search_once_s mdns_search_once_t;
  32. /**
  33. * @brief mDNS enum to specify the ip_protocol type
  34. */
  35. typedef enum {
  36. MDNS_IP_PROTOCOL_V4,
  37. MDNS_IP_PROTOCOL_V6,
  38. MDNS_IP_PROTOCOL_MAX
  39. } mdns_ip_protocol_t;
  40. /**
  41. * @brief mDNS basic text item structure
  42. * Used in mdns_service_add()
  43. */
  44. typedef struct {
  45. const char * key; /*!< item key name */
  46. const char * value; /*!< item value string */
  47. } mdns_txt_item_t;
  48. /**
  49. * @brief mDNS query linked list IP item
  50. */
  51. typedef struct mdns_ip_addr_s {
  52. esp_ip_addr_t addr; /*!< IP address */
  53. struct mdns_ip_addr_s * next; /*!< next IP, or NULL for the last IP in the list */
  54. } mdns_ip_addr_t;
  55. typedef enum mdns_if_internal {
  56. MDNS_IF_STA = 0,
  57. MDNS_IF_AP = 1,
  58. MDNS_IF_ETH = 2,
  59. MDNS_IF_MAX
  60. } mdns_if_t;
  61. /**
  62. * @brief mDNS query result structure
  63. */
  64. typedef struct mdns_result_s {
  65. struct mdns_result_s * next; /*!< next result, or NULL for the last result in the list */
  66. mdns_if_t tcpip_if; /*!< interface index */
  67. mdns_ip_protocol_t ip_protocol; /*!< ip_protocol type of the interface (v4/v6) */
  68. // PTR
  69. char * instance_name; /*!< instance name */
  70. // SRV
  71. char * hostname; /*!< hostname */
  72. uint16_t port; /*!< service port */
  73. // TXT
  74. mdns_txt_item_t * txt; /*!< txt record */
  75. uint8_t *txt_value_len; /*!< array of txt value len of each record */
  76. size_t txt_count; /*!< number of txt items */
  77. // A and AAAA
  78. mdns_ip_addr_t * addr; /*!< linked list of IP addresses found */
  79. } mdns_result_t;
  80. /**
  81. * @brief Initialize mDNS on given interface
  82. *
  83. * @return
  84. * - ESP_OK on success
  85. * - ESP_ERR_INVALID_STATE when failed to register event handler
  86. * - ESP_ERR_NO_MEM on memory error
  87. * - ESP_FAIL when failed to start mdns task
  88. */
  89. esp_err_t mdns_init(void);
  90. /**
  91. * @brief Stop and free mDNS server
  92. *
  93. */
  94. void mdns_free(void);
  95. /**
  96. * @brief Set the hostname for mDNS server
  97. * required if you want to advertise services
  98. *
  99. * @param hostname Hostname to set
  100. *
  101. * @return
  102. * - ESP_OK success
  103. * - ESP_ERR_INVALID_ARG Parameter error
  104. * - ESP_ERR_NO_MEM memory error
  105. */
  106. esp_err_t mdns_hostname_set(const char * hostname);
  107. /**
  108. * @brief Adds a hostname and address to be delegated
  109. * A/AAAA queries will be replied for the hostname and
  110. * services can be added to this host.
  111. *
  112. * @param hostname Hostname to add
  113. * @param address_list The IP address list of the host
  114. *
  115. * @return
  116. * - ESP_OK success
  117. * - ESP_ERR_INVALID_STATE mDNS is not running
  118. * - ESP_ERR_INVALID_ARG Parameter error
  119. * - ESP_ERR_NO_MEM memory error
  120. *
  121. */
  122. esp_err_t mdns_delegate_hostname_add(const char * hostname, const mdns_ip_addr_t *address_list);
  123. /**
  124. * @brief Remove a delegated hostname
  125. * All the services added to this host will also be removed.
  126. *
  127. * @param hostname Hostname to remove
  128. *
  129. * @return
  130. * - ESP_OK success
  131. * - ESP_ERR_INVALID_STATE mDNS is not running
  132. * - ESP_ERR_INVALID_ARG Parameter error
  133. * - ESP_ERR_NO_MEM memory error
  134. *
  135. */
  136. esp_err_t mdns_delegate_hostname_remove(const char * hostname);
  137. /**
  138. * @brief Query whether a hostname has been added
  139. *
  140. * @param hostname Hostname to query
  141. *
  142. * @return
  143. * - true The hostname has been added.
  144. * - false The hostname has not been added.
  145. *
  146. */
  147. bool mdns_hostname_exists(const char * hostname);
  148. /**
  149. * @brief Set the default instance name for mDNS server
  150. *
  151. * @param instance_name Instance name to set
  152. *
  153. * @return
  154. * - ESP_OK success
  155. * - ESP_ERR_INVALID_ARG Parameter error
  156. * - ESP_ERR_NO_MEM memory error
  157. */
  158. esp_err_t mdns_instance_name_set(const char * instance_name);
  159. /**
  160. * @brief Add service to mDNS server
  161. *
  162. * @note The value length of txt items will be automatically decided by strlen
  163. *
  164. * @param instance_name instance name to set. If NULL,
  165. * global instance name or hostname will be used
  166. * @param service_type service type (_http, _ftp, etc)
  167. * @param proto service protocol (_tcp, _udp)
  168. * @param port service port
  169. * @param txt string array of TXT data (eg. {{"var","val"},{"other","2"}})
  170. * @param num_items number of items in TXT data
  171. *
  172. * @return
  173. * - ESP_OK success
  174. * - ESP_ERR_INVALID_ARG Parameter error
  175. * - ESP_ERR_NO_MEM memory error
  176. * - ESP_FAIL failed to add service
  177. */
  178. esp_err_t mdns_service_add(const char * instance_name, const char * service_type, const char * proto, uint16_t port, mdns_txt_item_t txt[], size_t num_items);
  179. /**
  180. * @brief Add service to mDNS server with a delegated hostname
  181. *
  182. * @note The value length of txt items will be automatically decided by strlen
  183. *
  184. * @param instance_name instance name to set. If NULL,
  185. * global instance name or hostname will be used
  186. * @param service_type service type (_http, _ftp, etc)
  187. * @param proto service protocol (_tcp, _udp)
  188. * @param hostname service hostname. If NULL, local hostname will be used.
  189. * @param port service port
  190. * @param txt string array of TXT data (eg. {{"var","val"},{"other","2"}})
  191. * @param num_items number of items in TXT data
  192. *
  193. * @return
  194. * - ESP_OK success
  195. * - ESP_ERR_INVALID_ARG Parameter error
  196. * - ESP_ERR_NO_MEM memory error
  197. * - ESP_FAIL failed to add service
  198. */
  199. esp_err_t mdns_service_add_for_host(const char * instance_name, const char * service_type, const char * proto,
  200. const char * hostname, uint16_t port, mdns_txt_item_t txt[], size_t num_items);
  201. /**
  202. * @brief Check whether a service has been added.
  203. *
  204. * @param service_type service type (_http, _ftp, etc)
  205. * @param proto service protocol (_tcp, _udp)
  206. * @param hostname service hostname. If NULL, checks for the local hostname.
  207. *
  208. * @return
  209. * - true Correspondding service has been added.
  210. * - false Service not found.
  211. */
  212. bool mdns_service_exists(const char * service_type, const char * proto, const char * hostname);
  213. /**
  214. * @brief Remove service from mDNS server
  215. *
  216. * @param service_type service type (_http, _ftp, etc)
  217. * @param proto service protocol (_tcp, _udp)
  218. *
  219. * @return
  220. * - ESP_OK success
  221. * - ESP_ERR_INVALID_ARG Parameter error
  222. * - ESP_ERR_NOT_FOUND Service not found
  223. * - ESP_ERR_NO_MEM memory error
  224. */
  225. esp_err_t mdns_service_remove(const char * service_type, const char * proto);
  226. /**
  227. * @brief Remove service from mDNS server with hostname
  228. *
  229. * @param service_type service type (_http, _ftp, etc)
  230. * @param proto service protocol (_tcp, _udp)
  231. * @param hostname service hostname. If NULL, local hostname will be used.
  232. *
  233. * @return
  234. * - ESP_OK success
  235. * - ESP_ERR_INVALID_ARG Parameter error
  236. * - ESP_ERR_NOT_FOUND Service not found
  237. * - ESP_ERR_NO_MEM memory error
  238. */
  239. esp_err_t mdns_service_remove_for_host(const char * service_type, const char * proto, const char *hostname);
  240. /**
  241. * @brief Set instance name for service
  242. *
  243. * @param service_type service type (_http, _ftp, etc)
  244. * @param proto service protocol (_tcp, _udp)
  245. * @param instance_name instance name to set
  246. *
  247. * @return
  248. * - ESP_OK success
  249. * - ESP_ERR_INVALID_ARG Parameter error
  250. * - ESP_ERR_NOT_FOUND Service not found
  251. * - ESP_ERR_NO_MEM memory error
  252. */
  253. esp_err_t mdns_service_instance_name_set(const char * service_type, const char * proto, const char * instance_name);
  254. /**
  255. * @brief Set instance name for service with hostname
  256. *
  257. * @param service_type service type (_http, _ftp, etc)
  258. * @param proto service protocol (_tcp, _udp)
  259. * @param hostname service hostname. If NULL, local hostname will be used.
  260. * @param instance_name instance name to set
  261. *
  262. * @return
  263. * - ESP_OK success
  264. * - ESP_ERR_INVALID_ARG Parameter error
  265. * - ESP_ERR_NOT_FOUND Service not found
  266. * - ESP_ERR_NO_MEM memory error
  267. */
  268. esp_err_t mdns_service_instance_name_set_for_host(const char * service_type, const char * proto, const char * hostname,
  269. const char * instance_name);
  270. /**
  271. * @brief Set service port
  272. *
  273. * @param service_type service type (_http, _ftp, etc)
  274. * @param proto service protocol (_tcp, _udp)
  275. * @param port service port
  276. *
  277. * @return
  278. * - ESP_OK success
  279. * - ESP_ERR_INVALID_ARG Parameter error
  280. * - ESP_ERR_NOT_FOUND Service not found
  281. * - ESP_ERR_NO_MEM memory error
  282. */
  283. esp_err_t mdns_service_port_set(const char * service_type, const char * proto, uint16_t port);
  284. /**
  285. * @brief Set service port with hostname
  286. *
  287. * @param service_type service type (_http, _ftp, etc)
  288. * @param proto service protocol (_tcp, _udp)
  289. * @param hostname service hostname. If NULL, local hostname will be used.
  290. * @param port service port
  291. *
  292. * @return
  293. * - ESP_OK success
  294. * - ESP_ERR_INVALID_ARG Parameter error
  295. * - ESP_ERR_NOT_FOUND Service not found
  296. * - ESP_ERR_NO_MEM memory error
  297. */
  298. esp_err_t mdns_service_port_set_for_host(const char * service_type, const char * proto, const char * hostname,
  299. uint16_t port);
  300. /**
  301. * @brief Replace all TXT items for service
  302. *
  303. * @note The value length of txt items will be automatically decided by strlen
  304. *
  305. * @param service_type service type (_http, _ftp, etc)
  306. * @param proto service protocol (_tcp, _udp)
  307. * @param txt array of TXT data (eg. {{"var","val"},{"other","2"}})
  308. * @param num_items number of items in TXT data
  309. *
  310. * @return
  311. * - ESP_OK success
  312. * - ESP_ERR_INVALID_ARG Parameter error
  313. * - ESP_ERR_NOT_FOUND Service not found
  314. * - ESP_ERR_NO_MEM memory error
  315. */
  316. esp_err_t mdns_service_txt_set(const char * service_type, const char * proto, mdns_txt_item_t txt[], uint8_t num_items);
  317. /**
  318. * @brief Replace all TXT items for service with hostname
  319. *
  320. * @note The value length of txt items will be automatically decided by strlen
  321. *
  322. * @param service_type service type (_http, _ftp, etc)
  323. * @param proto service protocol (_tcp, _udp)
  324. * @param hostname service hostname. If NULL, local hostname will be used.
  325. * @param txt array of TXT data (eg. {{"var","val"},{"other","2"}})
  326. * @param num_items number of items in TXT data
  327. *
  328. * @return
  329. * - ESP_OK success
  330. * - ESP_ERR_INVALID_ARG Parameter error
  331. * - ESP_ERR_NOT_FOUND Service not found
  332. * - ESP_ERR_NO_MEM memory error
  333. */
  334. esp_err_t mdns_service_txt_set_for_host(const char * service_type, const char * proto, const char * hostname,
  335. mdns_txt_item_t txt[], uint8_t num_items);
  336. /**
  337. * @brief Set/Add TXT item for service TXT record
  338. *
  339. * @note The value length will be automatically decided by strlen
  340. *
  341. * @param service_type service type (_http, _ftp, etc)
  342. * @param proto service protocol (_tcp, _udp)
  343. * @param key the key that you want to add/update
  344. * @param value the new value of the key
  345. *
  346. * @return
  347. * - ESP_OK success
  348. * - ESP_ERR_INVALID_ARG Parameter error
  349. * - ESP_ERR_NOT_FOUND Service not found
  350. * - ESP_ERR_NO_MEM memory error
  351. */
  352. esp_err_t mdns_service_txt_item_set(const char * service_type, const char * proto, const char * key, const char * value);
  353. /**
  354. * @brief Set/Add TXT item for service TXT record
  355. *
  356. * @param service_type service type (_http, _ftp, etc)
  357. * @param proto service protocol (_tcp, _udp)
  358. * @param key the key that you want to add/update
  359. * @param value the new value of the key
  360. * @param value_len the length of the value
  361. *
  362. * @return
  363. * - ESP_OK success
  364. * - ESP_ERR_INVALID_ARG Parameter error
  365. * - ESP_ERR_NOT_FOUND Service not found
  366. * - ESP_ERR_NO_MEM memory error
  367. */
  368. esp_err_t mdns_service_txt_item_set_with_explicit_value_len(const char *service_type, const char *proto,
  369. const char *key, const char *value, uint8_t value_len);
  370. /**
  371. * @brief Set/Add TXT item for service TXT record with hostname
  372. *
  373. * @note The value length will be automatically decided by strlen
  374. *
  375. * @param service_type service type (_http, _ftp, etc)
  376. * @param proto service protocol (_tcp, _udp)
  377. * @param hostname service hostname. If NULL, local hostname will be used.
  378. * @param key the key that you want to add/update
  379. * @param value the new value of the key
  380. *
  381. * @return
  382. * - ESP_OK success
  383. * - ESP_ERR_INVALID_ARG Parameter error
  384. * - ESP_ERR_NOT_FOUND Service not found
  385. * - ESP_ERR_NO_MEM memory error
  386. */
  387. esp_err_t mdns_service_txt_item_set_for_host(const char * service_type, const char * proto, const char * hostname,
  388. const char * key, const char * value);
  389. /**
  390. * @brief Set/Add TXT item for service TXT record with hostname and txt value length
  391. *
  392. * @param service_type service type (_http, _ftp, etc)
  393. * @param proto service protocol (_tcp, _udp)
  394. * @param hostname service hostname. If NULL, local hostname will be used.
  395. * @param key the key that you want to add/update
  396. * @param value the new value of the key
  397. * @param value_len the length of the value
  398. *
  399. * @return
  400. * - ESP_OK success
  401. * - ESP_ERR_INVALID_ARG Parameter error
  402. * - ESP_ERR_NOT_FOUND Service not found
  403. * - ESP_ERR_NO_MEM memory error
  404. */
  405. esp_err_t mdns_service_txt_item_set_for_host_with_explicit_value_len(const char *service_type, const char *proto,
  406. const char *hostname, const char *key,
  407. const char *value, uint8_t value_len);
  408. /**
  409. * @brief Remove TXT item for service TXT record
  410. *
  411. * @param service_type service type (_http, _ftp, etc)
  412. * @param proto service protocol (_tcp, _udp)
  413. * @param key the key that you want to remove
  414. *
  415. * @return
  416. * - ESP_OK success
  417. * - ESP_ERR_INVALID_ARG Parameter error
  418. * - ESP_ERR_NOT_FOUND Service not found
  419. * - ESP_ERR_NO_MEM memory error
  420. */
  421. esp_err_t mdns_service_txt_item_remove(const char * service_type, const char * proto, const char * key);
  422. /**
  423. * @brief Remove TXT item for service TXT record with hostname
  424. *
  425. * @param service_type service type (_http, _ftp, etc)
  426. * @param proto service protocol (_tcp, _udp)
  427. * @param hostname service hostname. If NULL, local hostname will be used.
  428. * @param key the key that you want to remove
  429. *
  430. * @return
  431. * - ESP_OK success
  432. * - ESP_ERR_INVALID_ARG Parameter error
  433. * - ESP_ERR_NOT_FOUND Service not found
  434. * - ESP_ERR_NO_MEM memory error
  435. */
  436. esp_err_t mdns_service_txt_item_remove_for_host(const char * service_type, const char * proto, const char * hostname,
  437. const char * key);
  438. /**
  439. * @brief Remove and free all services from mDNS server
  440. *
  441. * @return
  442. * - ESP_OK success
  443. * - ESP_ERR_INVALID_ARG Parameter error
  444. */
  445. esp_err_t mdns_service_remove_all(void);
  446. /**
  447. * @brief Deletes the finished query. Call this only after the search has ended!
  448. *
  449. * @param search pointer to search object
  450. *
  451. * @return
  452. * - ESP_OK success
  453. * - ESP_ERR_INVALID_STATE search has not finished
  454. * - ESP_ERR_INVALID_ARG pointer to search object is NULL
  455. */
  456. esp_err_t mdns_query_async_delete(mdns_search_once_t* search);
  457. /**
  458. * @brief Get results from search pointer. Results available as a pointer to the output parameter.
  459. * Pointer to search object has to be deleted via `mdns_query_async_delete` once the query has finished.
  460. * The results although have to be freed manually.
  461. *
  462. * @param search pointer to search object
  463. * @param timeout time in milliseconds to wait for answers
  464. * @param results pointer to the results of the query
  465. *
  466. * @return
  467. * True if search has finished before or at timeout
  468. * False if search timeout is over
  469. */
  470. bool mdns_query_async_get_results(mdns_search_once_t* search, uint32_t timeout, mdns_result_t ** results);
  471. /**
  472. * @brief Query mDNS for host or service asynchronousely.
  473. * Search has to be tested for progress and deleted manually!
  474. *
  475. * @param name service instance or host name (NULL for PTR queries)
  476. * @param service_type service type (_http, _arduino, _ftp etc.) (NULL for host queries)
  477. * @param proto service protocol (_tcp, _udp, etc.) (NULL for host queries)
  478. * @param type type of query (MDNS_TYPE_*)
  479. * @param timeout time in milliseconds during which mDNS query is active
  480. * @param max_results maximum results to be collected
  481. *
  482. * @return mdns_search_once_s pointer to new search object if query initiated successfully.
  483. * NULL otherwise.
  484. */
  485. mdns_search_once_t* mdns_query_async_new(const char * name, const char * service_type, const char * proto, uint16_t type, uint32_t timeout, size_t max_results);
  486. /**
  487. * @brief Query mDNS for host or service
  488. * All following query methods are derived from this one
  489. *
  490. * @param name service instance or host name (NULL for PTR queries)
  491. * @param service_type service type (_http, _arduino, _ftp etc.) (NULL for host queries)
  492. * @param proto service protocol (_tcp, _udp, etc.) (NULL for host queries)
  493. * @param type type of query (MDNS_TYPE_*)
  494. * @param timeout time in milliseconds to wait for answers.
  495. * @param max_results maximum results to be collected
  496. * @param results pointer to the results of the query
  497. * results must be freed using mdns_query_results_free below
  498. *
  499. * @return
  500. * - ESP_OK success
  501. * - ESP_ERR_INVALID_STATE mDNS is not running
  502. * - ESP_ERR_NO_MEM memory error
  503. * - ESP_ERR_INVALID_ARG timeout was not given
  504. */
  505. esp_err_t mdns_query(const char * name, const char * service_type, const char * proto, uint16_t type, uint32_t timeout, size_t max_results, mdns_result_t ** results);
  506. /**
  507. * @brief Free query results
  508. *
  509. * @param results linked list of results to be freed
  510. */
  511. void mdns_query_results_free(mdns_result_t * results);
  512. /**
  513. * @brief Query mDNS for service
  514. *
  515. * @param service_type service type (_http, _arduino, _ftp etc.)
  516. * @param proto service protocol (_tcp, _udp, etc.)
  517. * @param timeout time in milliseconds to wait for answer.
  518. * @param max_results maximum results to be collected
  519. * @param results pointer to the results of the query
  520. *
  521. * @return
  522. * - ESP_OK success
  523. * - ESP_ERR_INVALID_STATE mDNS is not running
  524. * - ESP_ERR_NO_MEM memory error
  525. * - ESP_ERR_INVALID_ARG parameter error
  526. */
  527. esp_err_t mdns_query_ptr(const char * service_type, const char * proto, uint32_t timeout, size_t max_results, mdns_result_t ** results);
  528. /**
  529. * @brief Query mDNS for SRV record
  530. *
  531. * @param instance_name service instance name
  532. * @param service_type service type (_http, _arduino, _ftp etc.)
  533. * @param proto service protocol (_tcp, _udp, etc.)
  534. * @param timeout time in milliseconds to wait for answer.
  535. * @param result pointer to the result of the query
  536. *
  537. * @return
  538. * - ESP_OK success
  539. * - ESP_ERR_INVALID_STATE mDNS is not running
  540. * - ESP_ERR_NO_MEM memory error
  541. * - ESP_ERR_INVALID_ARG parameter error
  542. */
  543. esp_err_t mdns_query_srv(const char * instance_name, const char * service_type, const char * proto, uint32_t timeout, mdns_result_t ** result);
  544. /**
  545. * @brief Query mDNS for TXT record
  546. *
  547. * @param instance_name service instance name
  548. * @param service_type service type (_http, _arduino, _ftp etc.)
  549. * @param proto service protocol (_tcp, _udp, etc.)
  550. * @param timeout time in milliseconds to wait for answer.
  551. * @param result pointer to the result of the query
  552. *
  553. * @return
  554. * - ESP_OK success
  555. * - ESP_ERR_INVALID_STATE mDNS is not running
  556. * - ESP_ERR_NO_MEM memory error
  557. * - ESP_ERR_INVALID_ARG parameter error
  558. */
  559. esp_err_t mdns_query_txt(const char * instance_name, const char * service_type, const char * proto, uint32_t timeout, mdns_result_t ** result);
  560. /**
  561. * @brief Query mDNS for A record
  562. *
  563. * @param host_name host name to look for
  564. * @param timeout time in milliseconds to wait for answer.
  565. * @param addr pointer to the resulting IP4 address
  566. *
  567. * @return
  568. * - ESP_OK success
  569. * - ESP_ERR_INVALID_STATE mDNS is not running
  570. * - ESP_ERR_NO_MEM memory error
  571. * - ESP_ERR_INVALID_ARG parameter error
  572. */
  573. esp_err_t mdns_query_a(const char * host_name, uint32_t timeout, esp_ip4_addr_t * addr);
  574. #if CONFIG_LWIP_IPV6
  575. /**
  576. * @brief Query mDNS for A record
  577. *
  578. * Please note that hostname must not contain domain name, as mDNS uses '.local' domain.
  579. *
  580. * @param host_name host name to look for
  581. * @param timeout time in milliseconds to wait for answer. If 0, max_results needs to be defined
  582. * @param addr pointer to the resulting IP6 address
  583. *
  584. * @return
  585. * - ESP_OK success
  586. * - ESP_ERR_INVALID_STATE mDNS is not running
  587. * - ESP_ERR_NO_MEM memory error
  588. * - ESP_ERR_INVALID_ARG parameter error
  589. */
  590. esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, esp_ip6_addr_t * addr);
  591. #endif
  592. /**
  593. * @brief System event handler
  594. * This method controls the service state on all active interfaces and applications are required
  595. * to call it from the system event handler for normal operation of mDNS service.
  596. *
  597. * Please note that hostname must not contain domain name, as mDNS uses '.local' domain.
  598. *
  599. * @param ctx The system event context
  600. * @param event The system event
  601. */
  602. esp_err_t mdns_handle_system_event(void *ctx, system_event_t *event) __attribute__((deprecated));
  603. #ifdef __cplusplus
  604. }
  605. #endif
  606. #endif /* ESP_MDNS_H_ */