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