mdns.h 25 KB

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