mdns.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  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. uint32_t ttl; /*!< time to live */
  68. mdns_ip_protocol_t ip_protocol; /*!< ip_protocol type of the interface (v4/v6) */
  69. // PTR
  70. char * instance_name; /*!< instance name */
  71. char * service_type; /*!< service type */
  72. char * proto; /*!< srevice protocol */
  73. // SRV
  74. char * hostname; /*!< hostname */
  75. uint16_t port; /*!< service port */
  76. // TXT
  77. mdns_txt_item_t * txt; /*!< txt record */
  78. uint8_t *txt_value_len; /*!< array of txt value len of each record */
  79. size_t txt_count; /*!< number of txt items */
  80. // A and AAAA
  81. mdns_ip_addr_t * addr; /*!< linked list of IP addresses found */
  82. } mdns_result_t;
  83. typedef void (*mdns_query_notify_t)(mdns_search_once_t *search);
  84. /**
  85. * @brief Initialize mDNS on given interface
  86. *
  87. * @return
  88. * - ESP_OK on success
  89. * - ESP_ERR_INVALID_STATE when failed to register event handler
  90. * - ESP_ERR_NO_MEM on memory error
  91. * - ESP_FAIL when failed to start mdns task
  92. */
  93. esp_err_t mdns_init(void);
  94. /**
  95. * @brief Stop and free mDNS server
  96. *
  97. */
  98. void mdns_free(void);
  99. /**
  100. * @brief Set the hostname for mDNS server
  101. * required if you want to advertise services
  102. *
  103. * @param hostname Hostname to set
  104. *
  105. * @return
  106. * - ESP_OK success
  107. * - ESP_ERR_INVALID_ARG Parameter error
  108. * - ESP_ERR_NO_MEM memory error
  109. */
  110. esp_err_t mdns_hostname_set(const char * hostname);
  111. /**
  112. * @brief Adds a hostname and address to be delegated
  113. * A/AAAA queries will be replied for the hostname and
  114. * services can be added to this host.
  115. *
  116. * @param hostname Hostname to add
  117. * @param address_list The IP address list of the host
  118. *
  119. * @return
  120. * - ESP_OK success
  121. * - ESP_ERR_INVALID_STATE mDNS is not running
  122. * - ESP_ERR_INVALID_ARG Parameter error
  123. * - ESP_ERR_NO_MEM memory error
  124. *
  125. */
  126. esp_err_t mdns_delegate_hostname_add(const char * hostname, const mdns_ip_addr_t *address_list);
  127. /**
  128. * @brief Remove a delegated hostname
  129. * All the services added to this host will also be removed.
  130. *
  131. * @param hostname Hostname to remove
  132. *
  133. * @return
  134. * - ESP_OK success
  135. * - ESP_ERR_INVALID_STATE mDNS is not running
  136. * - ESP_ERR_INVALID_ARG Parameter error
  137. * - ESP_ERR_NO_MEM memory error
  138. *
  139. */
  140. esp_err_t mdns_delegate_hostname_remove(const char * hostname);
  141. /**
  142. * @brief Query whether a hostname has been added
  143. *
  144. * @param hostname Hostname to query
  145. *
  146. * @return
  147. * - true The hostname has been added.
  148. * - false The hostname has not been added.
  149. *
  150. */
  151. bool mdns_hostname_exists(const char * hostname);
  152. /**
  153. * @brief Set the default instance name for mDNS server
  154. *
  155. * @param instance_name Instance name to set
  156. *
  157. * @return
  158. * - ESP_OK success
  159. * - ESP_ERR_INVALID_ARG Parameter error
  160. * - ESP_ERR_NO_MEM memory error
  161. */
  162. esp_err_t mdns_instance_name_set(const char * instance_name);
  163. /**
  164. * @brief Add service to mDNS server
  165. *
  166. * @note The value length of txt items will be automatically decided by strlen
  167. *
  168. * @param instance_name instance name to set. If NULL,
  169. * global instance name or hostname will be used.
  170. * Note that MDNS_MULTIPLE_INSTANCE config option
  171. * needs to be enabled for adding multiple instances
  172. * with the same instance type.
  173. * @param service_type service type (_http, _ftp, etc)
  174. * @param proto service protocol (_tcp, _udp)
  175. * @param port service port
  176. * @param txt string array of TXT data (eg. {{"var","val"},{"other","2"}})
  177. * @param num_items number of items in TXT data
  178. *
  179. * @return
  180. * - ESP_OK success
  181. * - ESP_ERR_INVALID_ARG Parameter error
  182. * - ESP_ERR_NO_MEM memory error
  183. * - ESP_FAIL failed to add service
  184. */
  185. 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);
  186. /**
  187. * @brief Add service to mDNS server with a delegated hostname
  188. *
  189. * @note The value length of txt items will be automatically decided by strlen
  190. *
  191. * @param instance_name instance name to set. If NULL,
  192. * global instance name or hostname will be used
  193. * Note that MDNS_MULTIPLE_INSTANCE config option
  194. * needs to be enabled for adding multiple instances
  195. * with the same instance type.
  196. * @param service_type service type (_http, _ftp, etc)
  197. * @param proto service protocol (_tcp, _udp)
  198. * @param hostname service hostname. If NULL, local hostname will be used.
  199. * @param port service port
  200. * @param txt string array of TXT data (eg. {{"var","val"},{"other","2"}})
  201. * @param num_items number of items in TXT data
  202. *
  203. * @return
  204. * - ESP_OK success
  205. * - ESP_ERR_INVALID_ARG Parameter error
  206. * - ESP_ERR_NO_MEM memory error
  207. * - ESP_FAIL failed to add service
  208. */
  209. esp_err_t mdns_service_add_for_host(const char * instance_name, const char * service_type, const char * proto,
  210. const char * hostname, uint16_t port, mdns_txt_item_t txt[], size_t num_items);
  211. /**
  212. * @brief Check whether a service has been added.
  213. *
  214. * @param service_type service type (_http, _ftp, etc)
  215. * @param proto service protocol (_tcp, _udp)
  216. * @param hostname service hostname. If NULL, checks for the local hostname.
  217. *
  218. * @return
  219. * - true Correspondding service has been added.
  220. * - false Service not found.
  221. */
  222. bool mdns_service_exists(const char * service_type, const char * proto, const char * hostname);
  223. /**
  224. * @brief Check whether a service has been added.
  225. *
  226. * @param instance instance name
  227. * @param service_type service type (_http, _ftp, etc)
  228. * @param proto service protocol (_tcp, _udp)
  229. * @param hostname service hostname. If NULL, checks for the local hostname.
  230. *
  231. * @return
  232. * - true Correspondding service has been added.
  233. * - false Service not found.
  234. */
  235. bool mdns_service_exists_with_instance(const char *instance, const char *service_type, const char *proto,
  236. const char *hostname);
  237. /**
  238. * @brief Remove service from mDNS server
  239. *
  240. * @param service_type service type (_http, _ftp, etc)
  241. * @param proto service protocol (_tcp, _udp)
  242. *
  243. * @return
  244. * - ESP_OK success
  245. * - ESP_ERR_INVALID_ARG Parameter error
  246. * - ESP_ERR_NOT_FOUND Service not found
  247. * - ESP_ERR_NO_MEM memory error
  248. */
  249. esp_err_t mdns_service_remove(const char * service_type, const char * proto);
  250. /**
  251. * @brief Remove service from mDNS server with hostname
  252. *
  253. * @param service_type service type (_http, _ftp, etc)
  254. * @param proto service protocol (_tcp, _udp)
  255. * @param hostname service hostname. If NULL, local hostname will be used.
  256. *
  257. * @return
  258. * - ESP_OK success
  259. * - ESP_ERR_INVALID_ARG Parameter error
  260. * - ESP_ERR_NOT_FOUND Service not found
  261. * - ESP_ERR_NO_MEM memory error
  262. */
  263. esp_err_t mdns_service_remove_for_host(const char * service_type, const char * proto, const char *hostname);
  264. /**
  265. * @brief Set instance name for service
  266. *
  267. * @param service_type service type (_http, _ftp, etc)
  268. * @param proto service protocol (_tcp, _udp)
  269. * @param instance_name instance name to set
  270. *
  271. * @return
  272. * - ESP_OK success
  273. * - ESP_ERR_INVALID_ARG Parameter error
  274. * - ESP_ERR_NOT_FOUND Service not found
  275. * - ESP_ERR_NO_MEM memory error
  276. */
  277. esp_err_t mdns_service_instance_name_set(const char * service_type, const char * proto, const char * instance_name);
  278. /**
  279. * @brief Set instance name for service with hostname
  280. *
  281. * @param service_type service type (_http, _ftp, etc)
  282. * @param proto service protocol (_tcp, _udp)
  283. * @param hostname service hostname. If NULL, local hostname will be used.
  284. * @param instance_name instance name to set
  285. *
  286. * @return
  287. * - ESP_OK success
  288. * - ESP_ERR_INVALID_ARG Parameter error
  289. * - ESP_ERR_NOT_FOUND Service not found
  290. * - ESP_ERR_NO_MEM memory error
  291. */
  292. esp_err_t mdns_service_instance_name_set_for_host(const char * service_type, const char * proto, const char * hostname,
  293. const char * instance_name);
  294. /**
  295. * @brief Set service port
  296. *
  297. * @param service_type service type (_http, _ftp, etc)
  298. * @param proto service protocol (_tcp, _udp)
  299. * @param port service port
  300. *
  301. * @return
  302. * - ESP_OK success
  303. * - ESP_ERR_INVALID_ARG Parameter error
  304. * - ESP_ERR_NOT_FOUND Service not found
  305. * - ESP_ERR_NO_MEM memory error
  306. */
  307. esp_err_t mdns_service_port_set(const char * service_type, const char * proto, uint16_t port);
  308. /**
  309. * @brief Set service port with hostname
  310. *
  311. * @param service_type service type (_http, _ftp, etc)
  312. * @param proto service protocol (_tcp, _udp)
  313. * @param hostname service hostname. If NULL, local hostname will be used.
  314. * @param port service port
  315. *
  316. * @return
  317. * - ESP_OK success
  318. * - ESP_ERR_INVALID_ARG Parameter error
  319. * - ESP_ERR_NOT_FOUND Service not found
  320. * - ESP_ERR_NO_MEM memory error
  321. */
  322. esp_err_t mdns_service_port_set_for_host(const char * service_type, const char * proto, const char * hostname,
  323. uint16_t port);
  324. /**
  325. * @brief Replace all TXT items for service
  326. *
  327. * @note The value length of txt items will be automatically decided by strlen
  328. *
  329. * @param service_type service type (_http, _ftp, etc)
  330. * @param proto service protocol (_tcp, _udp)
  331. * @param txt array of TXT data (eg. {{"var","val"},{"other","2"}})
  332. * @param num_items number of items in TXT data
  333. *
  334. * @return
  335. * - ESP_OK success
  336. * - ESP_ERR_INVALID_ARG Parameter error
  337. * - ESP_ERR_NOT_FOUND Service not found
  338. * - ESP_ERR_NO_MEM memory error
  339. */
  340. esp_err_t mdns_service_txt_set(const char * service_type, const char * proto, mdns_txt_item_t txt[], uint8_t num_items);
  341. /**
  342. * @brief Replace all TXT items for service with hostname
  343. *
  344. * @note The value length of txt items will be automatically decided by strlen
  345. *
  346. * @param service_type service type (_http, _ftp, etc)
  347. * @param proto service protocol (_tcp, _udp)
  348. * @param hostname service hostname. If NULL, local hostname will be used.
  349. * @param txt array of TXT data (eg. {{"var","val"},{"other","2"}})
  350. * @param num_items number of items in TXT data
  351. *
  352. * @return
  353. * - ESP_OK success
  354. * - ESP_ERR_INVALID_ARG Parameter error
  355. * - ESP_ERR_NOT_FOUND Service not found
  356. * - ESP_ERR_NO_MEM memory error
  357. */
  358. esp_err_t mdns_service_txt_set_for_host(const char * service_type, const char * proto, const char * hostname,
  359. mdns_txt_item_t txt[], uint8_t num_items);
  360. /**
  361. * @brief Set/Add TXT item for service TXT record
  362. *
  363. * @note The value length will be automatically decided by strlen
  364. *
  365. * @param service_type service type (_http, _ftp, etc)
  366. * @param proto service protocol (_tcp, _udp)
  367. * @param key the key that you want to add/update
  368. * @param value the new value of the key
  369. *
  370. * @return
  371. * - ESP_OK success
  372. * - ESP_ERR_INVALID_ARG Parameter error
  373. * - ESP_ERR_NOT_FOUND Service not found
  374. * - ESP_ERR_NO_MEM memory error
  375. */
  376. esp_err_t mdns_service_txt_item_set(const char * service_type, const char * proto, const char * key, const char * value);
  377. /**
  378. * @brief Set/Add TXT item for service TXT record
  379. *
  380. * @param service_type service type (_http, _ftp, etc)
  381. * @param proto service protocol (_tcp, _udp)
  382. * @param key the key that you want to add/update
  383. * @param value the new value of the key
  384. * @param value_len the length of the value
  385. *
  386. * @return
  387. * - ESP_OK success
  388. * - ESP_ERR_INVALID_ARG Parameter error
  389. * - ESP_ERR_NOT_FOUND Service not found
  390. * - ESP_ERR_NO_MEM memory error
  391. */
  392. esp_err_t mdns_service_txt_item_set_with_explicit_value_len(const char *service_type, const char *proto,
  393. const char *key, const char *value, uint8_t value_len);
  394. /**
  395. * @brief Set/Add TXT item for service TXT record with hostname
  396. *
  397. * @note The value length will be automatically decided by strlen
  398. *
  399. * @param service_type service type (_http, _ftp, etc)
  400. * @param proto service protocol (_tcp, _udp)
  401. * @param hostname service hostname. If NULL, local hostname will be used.
  402. * @param key the key that you want to add/update
  403. * @param value the new value of the key
  404. *
  405. * @return
  406. * - ESP_OK success
  407. * - ESP_ERR_INVALID_ARG Parameter error
  408. * - ESP_ERR_NOT_FOUND Service not found
  409. * - ESP_ERR_NO_MEM memory error
  410. */
  411. esp_err_t mdns_service_txt_item_set_for_host(const char * service_type, const char * proto, const char * hostname,
  412. const char * key, const char * value);
  413. /**
  414. * @brief Set/Add TXT item for service TXT record with hostname and txt value length
  415. *
  416. * @param service_type service type (_http, _ftp, etc)
  417. * @param proto service protocol (_tcp, _udp)
  418. * @param hostname service hostname. If NULL, local hostname will be used.
  419. * @param key the key that you want to add/update
  420. * @param value the new value of the key
  421. * @param value_len the length of the value
  422. *
  423. * @return
  424. * - ESP_OK success
  425. * - ESP_ERR_INVALID_ARG Parameter error
  426. * - ESP_ERR_NOT_FOUND Service not found
  427. * - ESP_ERR_NO_MEM memory error
  428. */
  429. esp_err_t mdns_service_txt_item_set_for_host_with_explicit_value_len(const char *service_type, const char *proto,
  430. const char *hostname, const char *key,
  431. const char *value, uint8_t value_len);
  432. /**
  433. * @brief Remove TXT item for service TXT record
  434. *
  435. * @param service_type service type (_http, _ftp, etc)
  436. * @param proto service protocol (_tcp, _udp)
  437. * @param key the key that you want to remove
  438. *
  439. * @return
  440. * - ESP_OK success
  441. * - ESP_ERR_INVALID_ARG Parameter error
  442. * - ESP_ERR_NOT_FOUND Service not found
  443. * - ESP_ERR_NO_MEM memory error
  444. */
  445. esp_err_t mdns_service_txt_item_remove(const char * service_type, const char * proto, const char * key);
  446. /**
  447. * @brief Remove TXT item for service TXT record with hostname
  448. *
  449. * @param service_type service type (_http, _ftp, etc)
  450. * @param proto service protocol (_tcp, _udp)
  451. * @param hostname service hostname. If NULL, local hostname will be used.
  452. * @param key the key that you want to remove
  453. *
  454. * @return
  455. * - ESP_OK success
  456. * - ESP_ERR_INVALID_ARG Parameter error
  457. * - ESP_ERR_NOT_FOUND Service not found
  458. * - ESP_ERR_NO_MEM memory error
  459. */
  460. esp_err_t mdns_service_txt_item_remove_for_host(const char * service_type, const char * proto, const char * hostname,
  461. const char * key);
  462. /**
  463. * @brief Remove and free all services from mDNS server
  464. *
  465. * @return
  466. * - ESP_OK success
  467. * - ESP_ERR_INVALID_ARG Parameter error
  468. */
  469. esp_err_t mdns_service_remove_all(void);
  470. /**
  471. * @brief Deletes the finished query. Call this only after the search has ended!
  472. *
  473. * @param search pointer to search object
  474. *
  475. * @return
  476. * - ESP_OK success
  477. * - ESP_ERR_INVALID_STATE search has not finished
  478. * - ESP_ERR_INVALID_ARG pointer to search object is NULL
  479. */
  480. esp_err_t mdns_query_async_delete(mdns_search_once_t* search);
  481. /**
  482. * @brief Get results from search pointer. Results available as a pointer to the output parameter.
  483. * Pointer to search object has to be deleted via `mdns_query_async_delete` once the query has finished.
  484. * The results although have to be freed manually.
  485. *
  486. * @param search pointer to search object
  487. * @param timeout time in milliseconds to wait for answers
  488. * @param results pointer to the results of the query
  489. *
  490. * @return
  491. * True if search has finished before or at timeout
  492. * False if search timeout is over
  493. */
  494. bool mdns_query_async_get_results(mdns_search_once_t* search, uint32_t timeout, mdns_result_t ** results);
  495. /**
  496. * @brief Query mDNS for host or service asynchronousely.
  497. * Search has to be tested for progress and deleted manually!
  498. *
  499. * @param name service instance or host name (NULL for PTR queries)
  500. * @param service_type service type (_http, _arduino, _ftp etc.) (NULL for host queries)
  501. * @param proto service protocol (_tcp, _udp, etc.) (NULL for host queries)
  502. * @param type type of query (MDNS_TYPE_*)
  503. * @param timeout time in milliseconds during which mDNS query is active
  504. * @param max_results maximum results to be collected
  505. * @param notifier Notification function to be called when the result is ready, can be NULL
  506. *
  507. * @return mdns_search_once_s pointer to new search object if query initiated successfully.
  508. * NULL otherwise.
  509. */
  510. mdns_search_once_t *mdns_query_async_new(const char *name, const char *service_type, const char *proto, uint16_t type,
  511. uint32_t timeout, size_t max_results, mdns_query_notify_t notifier);
  512. /**
  513. * @brief Query mDNS for host or service
  514. * All following query methods are derived from this one
  515. *
  516. * @param name service instance or host name (NULL for PTR queries)
  517. * @param service_type service type (_http, _arduino, _ftp etc.) (NULL for host queries)
  518. * @param proto service protocol (_tcp, _udp, etc.) (NULL for host queries)
  519. * @param type type of query (MDNS_TYPE_*)
  520. * @param timeout time in milliseconds to wait for answers.
  521. * @param max_results maximum results to be collected
  522. * @param results pointer to the results of the query
  523. * results must be freed using mdns_query_results_free below
  524. *
  525. * @return
  526. * - ESP_OK success
  527. * - ESP_ERR_INVALID_STATE mDNS is not running
  528. * - ESP_ERR_NO_MEM memory error
  529. * - ESP_ERR_INVALID_ARG timeout was not given
  530. */
  531. 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);
  532. /**
  533. * @brief Free query results
  534. *
  535. * @param results linked list of results to be freed
  536. */
  537. void mdns_query_results_free(mdns_result_t * results);
  538. /**
  539. * @brief Query mDNS for service
  540. *
  541. * @param service_type service type (_http, _arduino, _ftp etc.)
  542. * @param proto service protocol (_tcp, _udp, etc.)
  543. * @param timeout time in milliseconds to wait for answer.
  544. * @param max_results maximum results to be collected
  545. * @param results pointer to the results of the query
  546. *
  547. * @return
  548. * - ESP_OK success
  549. * - ESP_ERR_INVALID_STATE mDNS is not running
  550. * - ESP_ERR_NO_MEM memory error
  551. * - ESP_ERR_INVALID_ARG parameter error
  552. */
  553. esp_err_t mdns_query_ptr(const char * service_type, const char * proto, uint32_t timeout, size_t max_results, mdns_result_t ** results);
  554. /**
  555. * @brief Query mDNS for SRV record
  556. *
  557. * @param instance_name service instance name
  558. * @param service_type service type (_http, _arduino, _ftp etc.)
  559. * @param proto service protocol (_tcp, _udp, etc.)
  560. * @param timeout time in milliseconds to wait for answer.
  561. * @param result pointer to the result of the query
  562. *
  563. * @return
  564. * - ESP_OK success
  565. * - ESP_ERR_INVALID_STATE mDNS is not running
  566. * - ESP_ERR_NO_MEM memory error
  567. * - ESP_ERR_INVALID_ARG parameter error
  568. */
  569. esp_err_t mdns_query_srv(const char * instance_name, const char * service_type, const char * proto, uint32_t timeout, mdns_result_t ** result);
  570. /**
  571. * @brief Query mDNS for TXT record
  572. *
  573. * @param instance_name service instance name
  574. * @param service_type service type (_http, _arduino, _ftp etc.)
  575. * @param proto service protocol (_tcp, _udp, etc.)
  576. * @param timeout time in milliseconds to wait for answer.
  577. * @param result pointer to the result of the query
  578. *
  579. * @return
  580. * - ESP_OK success
  581. * - ESP_ERR_INVALID_STATE mDNS is not running
  582. * - ESP_ERR_NO_MEM memory error
  583. * - ESP_ERR_INVALID_ARG parameter error
  584. */
  585. esp_err_t mdns_query_txt(const char * instance_name, const char * service_type, const char * proto, uint32_t timeout, mdns_result_t ** result);
  586. /**
  587. * @brief Query mDNS for A record
  588. *
  589. * @param host_name host name to look for
  590. * @param timeout time in milliseconds to wait for answer.
  591. * @param addr pointer to the resulting IP4 address
  592. *
  593. * @return
  594. * - ESP_OK success
  595. * - ESP_ERR_INVALID_STATE mDNS is not running
  596. * - ESP_ERR_NO_MEM memory error
  597. * - ESP_ERR_INVALID_ARG parameter error
  598. */
  599. esp_err_t mdns_query_a(const char * host_name, uint32_t timeout, esp_ip4_addr_t * addr);
  600. #if CONFIG_LWIP_IPV6
  601. /**
  602. * @brief Query mDNS for A record
  603. *
  604. * Please note that hostname must not contain domain name, as mDNS uses '.local' domain.
  605. *
  606. * @param host_name host name to look for
  607. * @param timeout time in milliseconds to wait for answer. If 0, max_results needs to be defined
  608. * @param addr pointer to the resulting IP6 address
  609. *
  610. * @return
  611. * - ESP_OK success
  612. * - ESP_ERR_INVALID_STATE mDNS is not running
  613. * - ESP_ERR_NO_MEM memory error
  614. * - ESP_ERR_INVALID_ARG parameter error
  615. */
  616. esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, esp_ip6_addr_t * addr);
  617. #endif
  618. /**
  619. * @brief System event handler
  620. * This method controls the service state on all active interfaces and applications are required
  621. * to call it from the system event handler for normal operation of mDNS service.
  622. *
  623. * Please note that hostname must not contain domain name, as mDNS uses '.local' domain.
  624. *
  625. * @param ctx The system event context
  626. * @param event The system event
  627. */
  628. esp_err_t mdns_handle_system_event(void *ctx, system_event_t *event) __attribute__((deprecated));
  629. #ifdef __cplusplus
  630. }
  631. #endif
  632. #endif /* ESP_MDNS_H_ */