libiio  0.24
Library for interfacing with IIO devices
/builddir/build/BUILD/libiio-0.24/dns_sd.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * libiio - Library for interfacing industrial I/O (IIO) devices
4  *
5  * Copyright (C) 2014-2020 Analog Devices, Inc.
6  * Author: Paul Cercueil
7  * Robin Getz
8  */
9 
10 #ifndef __IIO_DNS_SD_H
11 #define __IIO_DNS_SD_H
12 
13 #include <stdbool.h>
14 #include <stdint.h>
15 
16 #ifdef _WIN32
17 #include <winsock2.h>
18 #else
19 #include <sys/param.h>
20 #endif
21 
22 #define DNS_SD_ADDRESS_STR_MAX (40) /* IPv6 Max = 4*8 + 7 + 1 for NUL */
23 #define FQDN_LEN (255) /* RFC 1035 */
24 
25 /* MacOS doesn't include ENOMEDIUM (No medium found) like Linux does */
26 #ifndef ENOMEDIUM
27 #define ENOMEDIUM ENOENT
28 #endif
29 
30 /* Used everywhere */
31 #define IIOD_PORT 30431
32 
33 struct addrinfo;
34 struct AvahiSimplePoll;
35 struct AvahiAddress;
36 
37 /* Common structure which all dns_sd_[*] files fill out
38  * Anything that is dynamically allocated (malloc) needs to be managed
39  */
40 struct dns_sd_discovery_data {
41  struct iio_mutex *lock;
42  struct AvahiSimplePoll *poll;
43  struct AvahiAddress *address;
44  uint16_t found, resolved;
45  char addr_str[DNS_SD_ADDRESS_STR_MAX];
46  char *hostname;
47  uint16_t port;
48  struct dns_sd_discovery_data *next;
49 };
50 
51 
52 /* This functions is implemented in network.c, but used in dns_sd.c
53  */
54 int create_socket(const struct addrinfo *addrinfo);
55 
56 /* These functions are common, and implemented in dns_sd_[*].c based on the
57  * implementations: avahi (linux), bonjour (mac), or ServiceDiscovery (Win10)
58  */
59 
60 /* Resolves all IIO hosts on the available networks, and passes back a linked list */
61 int dnssd_find_hosts(struct dns_sd_discovery_data ** ddata);
62 
63 /* Deallocates complete list of discovery data */
64 void dnssd_free_all_discovery_data(struct dns_sd_discovery_data *d);
65 
66 /* These functions are common, and found in dns_sd.c, but are used in the
67  * dns_sd_[*].c implementations or network.c
68  */
69 
70 /* Passed back the first (random) IIOD service resolved by DNS DS. */
71 int dnssd_discover_host(char *addr_str, size_t addr_len, uint16_t *port);
72 
73 /* remove duplicates from the list */
74 void remove_dup_discovery_data(struct dns_sd_discovery_data **ddata);
75 
76 /* port knocks */
77 void port_knock_discovery_data(struct dns_sd_discovery_data **ddata);
78 
79 /* Use dnssd to resolve a given hostname */
80 int dnssd_resolve_host(const char *hostname, char *ip_addr, const int addr_len);
81 
82 #endif /* __IIO_DNS_SD_H */