mdns.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 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. #define MDNS_TYPE_A 0x0001
  13. #define MDNS_TYPE_PTR 0x000C
  14. #define MDNS_TYPE_TXT 0x0010
  15. #define MDNS_TYPE_AAAA 0x001C
  16. #define MDNS_TYPE_SRV 0x0021
  17. #define MDNS_TYPE_OPT 0x0029
  18. #define MDNS_TYPE_NSEC 0x002F
  19. #define MDNS_TYPE_ANY 0x00FF
  20. /**
  21. * @brief Asynchronous query handle
  22. */
  23. typedef struct mdns_search_once_s mdns_search_once_t;
  24. typedef enum {
  25. MDNS_EVENT_ENABLE_IP4 = 1 << 1,
  26. MDNS_EVENT_ENABLE_IP6 = 1 << 2,
  27. MDNS_EVENT_ANNOUNCE_IP4 = 1 << 3,
  28. MDNS_EVENT_ANNOUNCE_IP6 = 1 << 4,
  29. MDNS_EVENT_DISABLE_IP4 = 1 << 5,
  30. MDNS_EVENT_DISABLE_IP6 = 1 << 6,
  31. } mdns_event_actions_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. /**
  56. * @brief mDNS query type to be explicitly set to either Unicast or Multicast
  57. */
  58. typedef enum {
  59. MDNS_QUERY_UNICAST,
  60. MDNS_QUERY_MULTICAST,
  61. } mdns_query_transmission_type_t;
  62. /**
  63. * @brief mDNS query result structure
  64. */
  65. typedef struct mdns_result_s {
  66. struct mdns_result_s * next; /*!< next result, or NULL for the last result in the list */
  67. esp_netif_t* esp_netif; /*!< ptr to corresponding esp-netif */
  68. uint32_t ttl; /*!< time to live */
  69. mdns_ip_protocol_t ip_protocol; /*!< ip_protocol type of the interface (v4/v6) */
  70. // PTR
  71. char * instance_name; /*!< instance name */
  72. char * service_type; /*!< service type */
  73. char * proto; /*!< srevice protocol */
  74. // SRV
  75. char * hostname; /*!< hostname */
  76. uint16_t port; /*!< service port */
  77. // TXT
  78. mdns_txt_item_t * txt; /*!< txt record */
  79. uint8_t *txt_value_len; /*!< array of txt value len of each record */
  80. size_t txt_count; /*!< number of txt items */
  81. // A and AAAA
  82. mdns_ip_addr_t * addr; /*!< linked list of IP addresses found */
  83. } mdns_result_t;
  84. typedef void (*mdns_query_notify_t)(mdns_search_once_t *search);
  85. /**
  86. * @brief Initialize mDNS on given interface
  87. *
  88. * @return
  89. * - ESP_OK on success
  90. * - ESP_ERR_INVALID_STATE when failed to register event handler
  91. * - ESP_ERR_NO_MEM on memory error
  92. * - ESP_FAIL when failed to start mdns task
  93. */
  94. esp_err_t mdns_init(void);
  95. /**
  96. * @brief Stop and free mDNS server
  97. *
  98. */
  99. void mdns_free(void);
  100. /**
  101. * @brief Set the hostname for mDNS server
  102. * required if you want to advertise services
  103. *
  104. * @param hostname Hostname to set
  105. *
  106. * @return
  107. * - ESP_OK success
  108. * - ESP_ERR_INVALID_ARG Parameter error
  109. * - ESP_ERR_NO_MEM memory error
  110. */
  111. esp_err_t mdns_hostname_set(const char * hostname);
  112. /**
  113. * @brief Adds a hostname and address to be delegated
  114. * A/AAAA queries will be replied for the hostname and
  115. * services can be added to this host.
  116. *
  117. * @param hostname Hostname to add
  118. * @param address_list The IP address list of the host
  119. *
  120. * @return
  121. * - ESP_OK success
  122. * - ESP_ERR_INVALID_STATE mDNS is not running
  123. * - ESP_ERR_INVALID_ARG Parameter error
  124. * - ESP_ERR_NO_MEM memory error
  125. *
  126. */
  127. esp_err_t mdns_delegate_hostname_add(const char * hostname, const mdns_ip_addr_t *address_list);
  128. /**
  129. * @brief Remove a delegated hostname
  130. * All the services added to this host will also be removed.
  131. *
  132. * @param hostname Hostname to remove
  133. *
  134. * @return
  135. * - ESP_OK success
  136. * - ESP_ERR_INVALID_STATE mDNS is not running
  137. * - ESP_ERR_INVALID_ARG Parameter error
  138. * - ESP_ERR_NO_MEM memory error
  139. *
  140. */
  141. esp_err_t mdns_delegate_hostname_remove(const char * hostname);
  142. /**
  143. * @brief Query whether a hostname has been added
  144. *
  145. * @param hostname Hostname to query
  146. *
  147. * @return
  148. * - true The hostname has been added.
  149. * - false The hostname has not been added.
  150. *
  151. */
  152. bool mdns_hostname_exists(const char * hostname);
  153. /**
  154. * @brief Set the default instance name for mDNS server
  155. *
  156. * @param instance_name Instance name to set
  157. *
  158. * @return
  159. * - ESP_OK success
  160. * - ESP_ERR_INVALID_ARG Parameter error
  161. * - ESP_ERR_NO_MEM memory error
  162. */
  163. esp_err_t mdns_instance_name_set(const char * instance_name);
  164. /**
  165. * @brief Add service to mDNS server
  166. *
  167. * @note The value length of txt items will be automatically decided by strlen
  168. *
  169. * @param instance_name instance name to set. If NULL,
  170. * global instance name or hostname will be used.
  171. * Note that MDNS_MULTIPLE_INSTANCE config option
  172. * needs to be enabled for adding multiple instances
  173. * with the same instance type.
  174. * @param service_type service type (_http, _ftp, etc)
  175. * @param proto service protocol (_tcp, _udp)
  176. * @param port service port
  177. * @param txt string array of TXT data (eg. {{"var","val"},{"other","2"}})
  178. * @param num_items number of items in TXT data
  179. *
  180. * @return
  181. * - ESP_OK success
  182. * - ESP_ERR_INVALID_ARG Parameter error
  183. * - ESP_ERR_NO_MEM memory error
  184. * - ESP_FAIL failed to add service
  185. */
  186. 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);
  187. /**
  188. * @brief Add service to mDNS server with a delegated hostname
  189. *
  190. * @note The value length of txt items will be automatically decided by strlen
  191. *
  192. * @param instance_name instance name to set. If NULL,
  193. * global instance name or hostname will be used
  194. * Note that MDNS_MULTIPLE_INSTANCE config option
  195. * needs to be enabled for adding multiple instances
  196. * with the same instance type.
  197. * @param service_type service type (_http, _ftp, etc)
  198. * @param proto service protocol (_tcp, _udp)
  199. * @param hostname service hostname. If NULL, local hostname will be used.
  200. * @param port service port
  201. * @param txt string array of TXT data (eg. {{"var","val"},{"other","2"}})
  202. * @param num_items number of items in TXT data
  203. *
  204. * @return
  205. * - ESP_OK success
  206. * - ESP_ERR_INVALID_ARG Parameter error
  207. * - ESP_ERR_NO_MEM memory error
  208. * - ESP_FAIL failed to add service
  209. */
  210. esp_err_t mdns_service_add_for_host(const char * instance_name, const char * service_type, const char * proto,
  211. const char * hostname, uint16_t port, mdns_txt_item_t txt[], size_t num_items);
  212. /**
  213. * @brief Check whether a service has been added.
  214. *
  215. * @param service_type service type (_http, _ftp, etc)
  216. * @param proto service protocol (_tcp, _udp)
  217. * @param hostname service hostname. If NULL, checks for the local hostname.
  218. *
  219. * @return
  220. * - true Correspondding service has been added.
  221. * - false Service not found.
  222. */
  223. bool mdns_service_exists(const char * service_type, const char * proto, const char * hostname);
  224. /**
  225. * @brief Check whether a service has been added.
  226. *
  227. * @param instance instance name
  228. * @param service_type service type (_http, _ftp, etc)
  229. * @param proto service protocol (_tcp, _udp)
  230. * @param hostname service hostname. If NULL, checks for the local hostname.
  231. *
  232. * @return
  233. * - true Correspondding service has been added.
  234. * - false Service not found.
  235. */
  236. bool mdns_service_exists_with_instance(const char *instance, const char *service_type, const char *proto,
  237. const char *hostname);
  238. /**
  239. * @brief Remove service from mDNS server
  240. *
  241. * @param service_type service type (_http, _ftp, etc)
  242. * @param proto service protocol (_tcp, _udp)
  243. *
  244. * @return
  245. * - ESP_OK success
  246. * - ESP_ERR_INVALID_ARG Parameter error
  247. * - ESP_ERR_NOT_FOUND Service not found
  248. * - ESP_ERR_NO_MEM memory error
  249. */
  250. esp_err_t mdns_service_remove(const char * service_type, const char * proto);
  251. /**
  252. * @brief Remove service from mDNS server with hostname
  253. *
  254. * @param instance instance name
  255. * @param service_type service type (_http, _ftp, etc)
  256. * @param proto service protocol (_tcp, _udp)
  257. * @param hostname service hostname. If NULL, local hostname will be used.
  258. *
  259. * @return
  260. * - ESP_OK success
  261. * - ESP_ERR_INVALID_ARG Parameter error
  262. * - ESP_ERR_NOT_FOUND Service not found
  263. * - ESP_ERR_NO_MEM memory error
  264. */
  265. esp_err_t mdns_service_remove_for_host(const char *instance, const char * service_type, const char * proto, const char *hostname);
  266. /**
  267. * @brief Set instance name for service
  268. *
  269. * @param service_type service type (_http, _ftp, etc)
  270. * @param proto service protocol (_tcp, _udp)
  271. * @param instance_name instance name to set
  272. *
  273. * @return
  274. * - ESP_OK success
  275. * - ESP_ERR_INVALID_ARG Parameter error
  276. * - ESP_ERR_NOT_FOUND Service not found
  277. * - ESP_ERR_NO_MEM memory error
  278. */
  279. esp_err_t mdns_service_instance_name_set(const char * service_type, const char * proto, const char * instance_name);
  280. /**
  281. * @brief Set instance name for service with hostname
  282. *
  283. * @param instance_old original instance name
  284. * @param service_type service type (_http, _ftp, etc)
  285. * @param proto service protocol (_tcp, _udp)
  286. * @param hostname service hostname. If NULL, local hostname will be used.
  287. * @param instance_name instance name to set
  288. *
  289. * @return
  290. * - ESP_OK success
  291. * - ESP_ERR_INVALID_ARG Parameter error
  292. * - ESP_ERR_NOT_FOUND Service not found
  293. * - ESP_ERR_NO_MEM memory error
  294. */
  295. esp_err_t mdns_service_instance_name_set_for_host(const char * instance_old, const char * service_type, const char * proto, const char * hostname,
  296. const char * instance_name);
  297. /**
  298. * @brief Set service port
  299. *
  300. * @param service_type service type (_http, _ftp, etc)
  301. * @param proto service protocol (_tcp, _udp)
  302. * @param port service port
  303. *
  304. * @return
  305. * - ESP_OK success
  306. * - ESP_ERR_INVALID_ARG Parameter error
  307. * - ESP_ERR_NOT_FOUND Service not found
  308. * - ESP_ERR_NO_MEM memory error
  309. */
  310. esp_err_t mdns_service_port_set(const char * service_type, const char * proto, uint16_t port);
  311. /**
  312. * @brief Set service port with hostname
  313. *
  314. * @param instance instance name
  315. * @param service_type service type (_http, _ftp, etc)
  316. * @param proto service protocol (_tcp, _udp)
  317. * @param hostname service hostname. If NULL, local hostname will be used.
  318. * @param port service port
  319. *
  320. * @return
  321. * - ESP_OK success
  322. * - ESP_ERR_INVALID_ARG Parameter error
  323. * - ESP_ERR_NOT_FOUND Service not found
  324. * - ESP_ERR_NO_MEM memory error
  325. */
  326. esp_err_t mdns_service_port_set_for_host(const char * instance, const char * service_type, const char * proto, const char * hostname,
  327. uint16_t port);
  328. /**
  329. * @brief Replace all TXT items for service
  330. *
  331. * @note The value length of txt items will be automatically decided by strlen
  332. *
  333. * @param service_type service type (_http, _ftp, etc)
  334. * @param proto service protocol (_tcp, _udp)
  335. * @param txt array of TXT data (eg. {{"var","val"},{"other","2"}})
  336. * @param num_items number of items in TXT data
  337. *
  338. * @return
  339. * - ESP_OK success
  340. * - ESP_ERR_INVALID_ARG Parameter error
  341. * - ESP_ERR_NOT_FOUND Service not found
  342. * - ESP_ERR_NO_MEM memory error
  343. */
  344. esp_err_t mdns_service_txt_set(const char * service_type, const char * proto, mdns_txt_item_t txt[], uint8_t num_items);
  345. /**
  346. * @brief Replace all TXT items for service with hostname
  347. *
  348. * @note The value length of txt items will be automatically decided by strlen
  349. *
  350. * @param instance instance name
  351. * @param service_type service type (_http, _ftp, etc)
  352. * @param proto service protocol (_tcp, _udp)
  353. * @param hostname service hostname. If NULL, local hostname will be used.
  354. * @param txt array of TXT data (eg. {{"var","val"},{"other","2"}})
  355. * @param num_items number of items in TXT data
  356. *
  357. * @return
  358. * - ESP_OK success
  359. * - ESP_ERR_INVALID_ARG Parameter error
  360. * - ESP_ERR_NOT_FOUND Service not found
  361. * - ESP_ERR_NO_MEM memory error
  362. */
  363. esp_err_t mdns_service_txt_set_for_host(const char * instance, const char * service_type, const char * proto, const char * hostname,
  364. mdns_txt_item_t txt[], uint8_t num_items);
  365. /**
  366. * @brief Set/Add TXT item for service TXT record
  367. *
  368. * @note The value length will be automatically decided by strlen
  369. *
  370. * @param service_type service type (_http, _ftp, etc)
  371. * @param proto service protocol (_tcp, _udp)
  372. * @param key the key that you want to add/update
  373. * @param value the new value of the key
  374. *
  375. * @return
  376. * - ESP_OK success
  377. * - ESP_ERR_INVALID_ARG Parameter error
  378. * - ESP_ERR_NOT_FOUND Service not found
  379. * - ESP_ERR_NO_MEM memory error
  380. */
  381. esp_err_t mdns_service_txt_item_set(const char * service_type, const char * proto, const char * key, const char * value);
  382. /**
  383. * @brief Set/Add TXT item for service TXT record
  384. *
  385. * @param service_type service type (_http, _ftp, etc)
  386. * @param proto service protocol (_tcp, _udp)
  387. * @param key the key that you want to add/update
  388. * @param value the new value of the key
  389. * @param value_len the length of the value
  390. *
  391. * @return
  392. * - ESP_OK success
  393. * - ESP_ERR_INVALID_ARG Parameter error
  394. * - ESP_ERR_NOT_FOUND Service not found
  395. * - ESP_ERR_NO_MEM memory error
  396. */
  397. esp_err_t mdns_service_txt_item_set_with_explicit_value_len(const char *service_type, const char *proto,
  398. const char *key, const char *value, uint8_t value_len);
  399. /**
  400. * @brief Set/Add TXT item for service TXT record with hostname
  401. *
  402. * @note The value length will be automatically decided by strlen
  403. *
  404. * @param instance instance name
  405. * @param service_type service type (_http, _ftp, etc)
  406. * @param proto service protocol (_tcp, _udp)
  407. * @param hostname service hostname. If NULL, local hostname will be used.
  408. * @param key the key that you want to add/update
  409. * @param value the new value of the key
  410. *
  411. * @return
  412. * - ESP_OK success
  413. * - ESP_ERR_INVALID_ARG Parameter error
  414. * - ESP_ERR_NOT_FOUND Service not found
  415. * - ESP_ERR_NO_MEM memory error
  416. */
  417. esp_err_t mdns_service_txt_item_set_for_host(const char * instance, const char * service_type, const char * proto, const char * hostname,
  418. const char * key, const char * value);
  419. /**
  420. * @brief Set/Add TXT item for service TXT record with hostname and txt value length
  421. *
  422. * @param instance instance name
  423. * @param service_type service type (_http, _ftp, etc)
  424. * @param proto service protocol (_tcp, _udp)
  425. * @param hostname service hostname. If NULL, local hostname will be used.
  426. * @param key the key that you want to add/update
  427. * @param value the new value of the key
  428. * @param value_len the length of the value
  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_set_for_host_with_explicit_value_len(const char * instance, const char *service_type, const char *proto,
  437. const char *hostname, const char *key,
  438. const char *value, uint8_t value_len);
  439. /**
  440. * @brief Remove TXT item for service TXT record
  441. *
  442. * @param service_type service type (_http, _ftp, etc)
  443. * @param proto service protocol (_tcp, _udp)
  444. * @param key the key that you want to remove
  445. *
  446. * @return
  447. * - ESP_OK success
  448. * - ESP_ERR_INVALID_ARG Parameter error
  449. * - ESP_ERR_NOT_FOUND Service not found
  450. * - ESP_ERR_NO_MEM memory error
  451. */
  452. esp_err_t mdns_service_txt_item_remove(const char * service_type, const char * proto, const char * key);
  453. /**
  454. * @brief Remove TXT item for service TXT record with hostname
  455. *
  456. * @param instance instance name
  457. * @param service_type service type (_http, _ftp, etc)
  458. * @param proto service protocol (_tcp, _udp)
  459. * @param hostname service hostname. If NULL, local hostname will be used.
  460. * @param key the key that you want to remove
  461. *
  462. * @return
  463. * - ESP_OK success
  464. * - ESP_ERR_INVALID_ARG Parameter error
  465. * - ESP_ERR_NOT_FOUND Service not found
  466. * - ESP_ERR_NO_MEM memory error
  467. */
  468. esp_err_t mdns_service_txt_item_remove_for_host(const char * instance, const char * service_type, const char * proto, const char * hostname,
  469. const char * key);
  470. /**
  471. * @brief Add subtype for service.
  472. *
  473. * @param instance_name instance name. If NULL, will find the first service with the same service type and protocol.
  474. * @param service_type service type (_http, _ftp, etc)
  475. * @param proto service protocol (_tcp, _udp)
  476. * @param hostname service hostname. If NULL, local hostname will be used.
  477. * @param subtype The subtype to add.
  478. *
  479. * @return
  480. * - ESP_OK success
  481. * - ESP_ERR_INVALID_ARG Parameter error
  482. * - ESP_ERR_NOT_FOUND Service not found
  483. * - ESP_ERR_NO_MEM memory error
  484. */
  485. esp_err_t mdns_service_subtype_add_for_host(const char *instance_name, const char *service_type, const char *proto,
  486. const char *hostname, const char *subtype);
  487. /**
  488. * @brief Remove and free all services from mDNS server
  489. *
  490. * @return
  491. * - ESP_OK success
  492. * - ESP_ERR_INVALID_ARG Parameter error
  493. */
  494. esp_err_t mdns_service_remove_all(void);
  495. /**
  496. * @brief Deletes the finished query. Call this only after the search has ended!
  497. *
  498. * @param search pointer to search object
  499. *
  500. * @return
  501. * - ESP_OK success
  502. * - ESP_ERR_INVALID_STATE search has not finished
  503. * - ESP_ERR_INVALID_ARG pointer to search object is NULL
  504. */
  505. esp_err_t mdns_query_async_delete(mdns_search_once_t* search);
  506. /**
  507. * @brief Get results from search pointer. Results available as a pointer to the output parameter.
  508. * Pointer to search object has to be deleted via `mdns_query_async_delete` once the query has finished.
  509. * The results although have to be freed manually.
  510. *
  511. * @param search pointer to search object
  512. * @param timeout time in milliseconds to wait for answers
  513. * @param results pointer to the results of the query
  514. * @param num_results pointer to the number of the actual result items (set to NULL to ignore this return value)
  515. *
  516. * @return
  517. * True if search has finished before or at timeout
  518. * False if search timeout is over
  519. */
  520. bool mdns_query_async_get_results(mdns_search_once_t* search, uint32_t timeout, mdns_result_t ** results, uint8_t * num_results);
  521. /**
  522. * @brief Query mDNS for host or service asynchronousely.
  523. * Search has to be tested for progress and deleted manually!
  524. *
  525. * @param name service instance or host name (NULL for PTR queries)
  526. * @param service_type service type (_http, _arduino, _ftp etc.) (NULL for host queries)
  527. * @param proto service protocol (_tcp, _udp, etc.) (NULL for host queries)
  528. * @param type type of query (MDNS_TYPE_*)
  529. * @param timeout time in milliseconds during which mDNS query is active
  530. * @param max_results maximum results to be collected
  531. * @param notifier Notification function to be called when the result is ready, can be NULL
  532. *
  533. * @return mdns_search_once_s pointer to new search object if query initiated successfully.
  534. * NULL otherwise.
  535. */
  536. mdns_search_once_t *mdns_query_async_new(const char *name, const char *service_type, const char *proto, uint16_t type,
  537. uint32_t timeout, size_t max_results, mdns_query_notify_t notifier);
  538. /**
  539. * @brief Generic mDNS query
  540. * All following query methods are derived from this one
  541. *
  542. * @param name service instance or host name (NULL for PTR queries)
  543. * @param service_type service type (_http, _arduino, _ftp etc.) (NULL for host queries)
  544. * @param proto service protocol (_tcp, _udp, etc.) (NULL for host queries)
  545. * @param type type of query (MDNS_TYPE_*)
  546. * @param transmission_type either Unicast query, or Multicast query
  547. * @param timeout time in milliseconds to wait for answers.
  548. * @param max_results maximum results to be collected
  549. * @param results pointer to the results of the query
  550. * results must be freed using mdns_query_results_free below
  551. *
  552. * @return
  553. * - ESP_OK success
  554. * - ESP_ERR_INVALID_STATE mDNS is not running
  555. * - ESP_ERR_NO_MEM memory error
  556. * - ESP_ERR_INVALID_ARG timeout was not given
  557. */
  558. esp_err_t mdns_query_generic(const char * name, const char * service_type, const char * proto, uint16_t type,
  559. mdns_query_transmission_type_t transmission_type, uint32_t timeout, size_t max_results, mdns_result_t ** results);
  560. /**
  561. * @brief Query mDNS for host or service
  562. *
  563. * Note that querying PTR types sends Multicast query, all other types send Unicast queries
  564. *
  565. * @param name service instance or host name (NULL for PTR queries)
  566. * @param service_type service type (_http, _arduino, _ftp etc.) (NULL for host queries)
  567. * @param proto service protocol (_tcp, _udp, etc.) (NULL for host queries)
  568. * @param type type of query (MDNS_TYPE_*)
  569. * @param timeout time in milliseconds to wait for answers.
  570. * @param max_results maximum results to be collected
  571. * @param results pointer to the results of the query
  572. * results must be freed using mdns_query_results_free below
  573. *
  574. * @return
  575. * - ESP_OK success
  576. * - ESP_ERR_INVALID_STATE mDNS is not running
  577. * - ESP_ERR_NO_MEM memory error
  578. * - ESP_ERR_INVALID_ARG timeout was not given
  579. */
  580. 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);
  581. /**
  582. * @brief Free query results
  583. *
  584. * @param results linked list of results to be freed
  585. */
  586. void mdns_query_results_free(mdns_result_t * results);
  587. /**
  588. * @brief Query mDNS for service
  589. *
  590. * @param service_type service type (_http, _arduino, _ftp etc.)
  591. * @param proto service protocol (_tcp, _udp, etc.)
  592. * @param timeout time in milliseconds to wait for answer.
  593. * @param max_results maximum results to be collected
  594. * @param results pointer to the results of the query
  595. *
  596. * @return
  597. * - ESP_OK success
  598. * - ESP_ERR_INVALID_STATE mDNS is not running
  599. * - ESP_ERR_NO_MEM memory error
  600. * - ESP_ERR_INVALID_ARG parameter error
  601. */
  602. esp_err_t mdns_query_ptr(const char * service_type, const char * proto, uint32_t timeout, size_t max_results, mdns_result_t ** results);
  603. /**
  604. * @brief Query mDNS for SRV record
  605. *
  606. * @param instance_name service instance name
  607. * @param service_type service type (_http, _arduino, _ftp etc.)
  608. * @param proto service protocol (_tcp, _udp, etc.)
  609. * @param timeout time in milliseconds to wait for answer.
  610. * @param result pointer to the result of the query
  611. *
  612. * @return
  613. * - ESP_OK success
  614. * - ESP_ERR_INVALID_STATE mDNS is not running
  615. * - ESP_ERR_NO_MEM memory error
  616. * - ESP_ERR_INVALID_ARG parameter error
  617. */
  618. esp_err_t mdns_query_srv(const char * instance_name, const char * service_type, const char * proto, uint32_t timeout, mdns_result_t ** result);
  619. /**
  620. * @brief Query mDNS for TXT record
  621. *
  622. * @param instance_name service instance name
  623. * @param service_type service type (_http, _arduino, _ftp etc.)
  624. * @param proto service protocol (_tcp, _udp, etc.)
  625. * @param timeout time in milliseconds to wait for answer.
  626. * @param result pointer to the result of the query
  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_txt(const char * instance_name, const char * service_type, const char * proto, uint32_t timeout, mdns_result_t ** result);
  635. /**
  636. * @brief Query mDNS for A record
  637. *
  638. * @param host_name host name to look for
  639. * @param timeout time in milliseconds to wait for answer.
  640. * @param addr pointer to the resulting IP4 address
  641. *
  642. * @return
  643. * - ESP_OK success
  644. * - ESP_ERR_INVALID_STATE mDNS is not running
  645. * - ESP_ERR_NO_MEM memory error
  646. * - ESP_ERR_INVALID_ARG parameter error
  647. */
  648. esp_err_t mdns_query_a(const char * host_name, uint32_t timeout, esp_ip4_addr_t * addr);
  649. #if CONFIG_LWIP_IPV6
  650. /**
  651. * @brief Query mDNS for A record
  652. *
  653. * Please note that hostname must not contain domain name, as mDNS uses '.local' domain.
  654. *
  655. * @param host_name host name to look for
  656. * @param timeout time in milliseconds to wait for answer. If 0, max_results needs to be defined
  657. * @param addr pointer to the resulting IP6 address
  658. *
  659. * @return
  660. * - ESP_OK success
  661. * - ESP_ERR_INVALID_STATE mDNS is not running
  662. * - ESP_ERR_NO_MEM memory error
  663. * - ESP_ERR_INVALID_ARG parameter error
  664. */
  665. esp_err_t mdns_query_aaaa(const char * host_name, uint32_t timeout, esp_ip6_addr_t * addr);
  666. #endif
  667. /**
  668. * @brief Register custom esp_netif with mDNS functionality
  669. * mDNS service runs by default on preconfigured interfaces (STA, AP, ETH).
  670. * This API enables running the service on any customized interface,
  671. * either using standard WiFi or Ethernet driver or any kind of user defined driver.
  672. *
  673. * @param esp_netif Pointer to esp-netif interface
  674. * @return
  675. * - ESP_OK success
  676. * - ESP_ERR_INVALID_STATE mDNS is not running or this netif is already registered
  677. * - ESP_ERR_NO_MEM not enough memory for this in interface in the netif list (see CONFIG_MDNS_MAX_INTERFACES)
  678. */
  679. esp_err_t mdns_register_netif(esp_netif_t *esp_netif);
  680. /**
  681. * @brief Unregister esp-netif already registered in mDNS service
  682. *
  683. * @param esp_netif Pointer to esp-netif interface
  684. * @return
  685. * - ESP_OK success
  686. * - ESP_ERR_INVALID_STATE mDNS is not running
  687. * - ESP_ERR_NOT_FOUND this esp-netif was not registered in mDNS service
  688. */
  689. esp_err_t mdns_unregister_netif(esp_netif_t *esp_netif);
  690. /**
  691. * @brief Set esp_netif to a desired state, or perform a desired action, such as enable/disable this interface
  692. * or send announcement packets to this netif
  693. *
  694. * * This function is used to enable (probe, resolve conflicts and announce), announce, or disable (send bye) mDNS
  695. * services on the specified network interface.
  696. * * This function must be called if users registers a specific interface using mdns_register_netif()
  697. * to enable mDNS services on that interface.
  698. * * This function could be used in IP/connection event handlers to automatically enable/announce mDNS services
  699. * when network properties change and/or disable them on disconnection.
  700. *
  701. * @param esp_netif Pointer to esp-netif interface
  702. * @param event_action Disable/Enable/Announce on this interface over IPv4/IPv6 protocol.
  703. * Actions enumerated in mdns_event_actions_t type.
  704. * @return
  705. * - ESP_OK success
  706. * - ESP_ERR_INVALID_STATE mDNS is not running or this netif is not registered
  707. * - ESP_ERR_NO_MEM memory error
  708. */
  709. esp_err_t mdns_netif_action(esp_netif_t *esp_netif, mdns_event_actions_t event_action);
  710. #ifdef __cplusplus
  711. }
  712. #endif
  713. #endif /* ESP_MDNS_H_ */