libiio  1.0
Library for interfacing with IIO devices
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 #include <ntddndis.h>
19 #include <netioapi.h>
20 #else
21 #include <net/if.h>
22 #include <sys/param.h>
23 #endif
24 
25 /* IPv6 Max = 4*8 + 7 + 1 for '%' + interface length */
26 #define DNS_SD_ADDRESS_STR_MAX (40 + IF_NAMESIZE)
27 
28 /* MacOS doesn't include ENOMEDIUM (No medium found) like Linux does */
29 #ifndef ENOMEDIUM
30 #define ENOMEDIUM ENOENT
31 #endif
32 
33 /* Used everywhere */
34 #define IIOD_PORT 30431
35 
36 struct addrinfo;
37 struct AvahiSimplePoll;
38 struct AvahiAddress;
39 struct iio_context_params;
40 struct iio_scan;
41 
42 /* Common structure which all dns_sd_[*] files fill out
43  * Anything that is dynamically allocated (malloc) needs to be managed
44  */
45 struct dns_sd_discovery_data {
46  struct iio_mutex *lock;
47  struct AvahiSimplePoll *poll;
48  struct AvahiAddress *address;
49  uint16_t found, resolved;
50  char addr_str[DNS_SD_ADDRESS_STR_MAX];
51  char *hostname;
52  uint16_t port, iface;
53  struct dns_sd_discovery_data *next;
54 };
55 
56 struct dns_sd_cb_data {
57  struct dns_sd_discovery_data *d;
58  const struct iio_context_params *params;
59 };
60 
61 /* These functions are common, and implemented in dns_sd_[*].c based on the
62  * implementations: avahi (linux), bonjour (mac), or ServiceDiscovery (Win10)
63  */
64 
65 /* Resolves all IIO hosts on the available networks, and passes back a linked list */
66 int dnssd_find_hosts(const struct iio_context_params *params,
67  struct dns_sd_discovery_data **ddata);
68 
69 /* Deallocates complete list of discovery data */
70 void dnssd_free_all_discovery_data(const struct iio_context_params *params,
71  struct dns_sd_discovery_data *d);
72 
73 /* These functions are common, and found in dns_sd.c, but are used in the
74  * dns_sd_[*].c implementations or network.c
75  */
76 
77 /* Passed back the first (random) IIOD service resolved by DNS DS. */
78 int dnssd_discover_host(const struct iio_context_params *params,
79  char *addr_str, size_t addr_len, uint16_t *port);
80 
81 /* remove duplicates from the list */
82 void remove_dup_discovery_data(const struct iio_context_params *params,
83  struct dns_sd_discovery_data **ddata);
84 
85 /* port knocks */
86 void port_knock_discovery_data(const struct iio_context_params *params,
87  struct dns_sd_discovery_data **ddata);
88 
89 /* Use dnssd to resolve a given hostname */
90 int dnssd_resolve_host(const struct iio_context_params *params,
91  const char *hostname, char *ip_addr, const int addr_len);
92 
93 int dnssd_context_scan(const struct iio_context_params *params,
94  struct iio_scan *ctx, const char *args);
95 
96 #endif /* __IIO_DNS_SD_H */
iio_create_scan_context
struct iio_scan * iio_create_scan_context(const char *backends, unsigned int flags)
Create a scan context.
Definition: compat.c:527
iio_create_scan_block
struct iio_scan_block * iio_create_scan_block(const char *backend, unsigned int flags)
Create a scan block.
Definition: compat.c:652
iio_create_default_context
struct iio_context * iio_create_default_context(void)
Create a context from local or remote IIO devices.
Definition: compat.c:504
iio_context_info_get_description
const char * iio_context_info_get_description(const struct iio_context_info *info)
Get a description of a discovered context.
Definition: compat.c:621
iio_create_context_from_uri
struct iio_context * iio_create_context_from_uri(const char *uri)
Create a context from a URI description.
Definition: compat.c:383
iio_scan_context_destroy
__api void iio_scan_context_destroy(struct iio_scan_context *ctx)
Destroy the given scan context.
iio_device_set_kernel_buffers_count
int iio_device_set_kernel_buffers_count(const struct iio_device *dev, unsigned int nb_buffers)
Configure the number of kernel buffers for a device.
Definition: compat.c:1631
iio_scan_block_get_info
struct iio_context_info * iio_scan_block_get_info(struct iio_scan_block *blk, unsigned int index)
Get the iio_context_info for a particular context.
Definition: compat.c:641
iio_create_local_context
struct iio_context * iio_create_local_context(void)
Create a context from local IIO devices (Linux only)
Definition: compat.c:499
iiopp::value
double value(Channel ch)
Reads the value of a channel by using "input" or "raw" attribute and applying "scale" and "offset" if...
Definition: iiopp.h:707
iio_create_network_context
struct iio_context * iio_create_network_context(const char *hostname)
Create a context from the network.
Definition: compat.c:494
iio_scan_block_scan
ssize_t iio_scan_block_scan(struct iio_scan_block *blk)
Enumerate available contexts via scan block.
Definition: compat.c:631
iio_context_get_version
int iio_context_get_version(const struct iio_context *ctx, unsigned int *major, unsigned int *minor, char git_tag[8])
Get the version of the backend in use.
Definition: compat.c:678
iio_create_xml_context
struct iio_context * iio_create_xml_context(const char *xml_file)
Create a context from a XML file.
Definition: compat.c:467
iio_scan_block_destroy
void iio_scan_block_destroy(struct iio_scan_block *blk)
Destroy the given scan block.
Definition: compat.c:671
iio_context_info_get_uri
const char * iio_context_info_get_uri(const struct iio_context_info *info)
Get the URI of a discovered context.
Definition: compat.c:626
iio_library_get_version
void iio_library_get_version(unsigned int *major, unsigned int *minor, char git_tag[8])
Get the version of the libiio library.
Definition: compat.c:1983
iio_context_info_list_free
void iio_context_info_list_free(struct iio_context_info **list)
Free a context info list.
Definition: compat.c:509
iio_scan_context_get_info_list
__api __check_ret ssize_t iio_scan_context_get_info_list(struct iio_scan_context *ctx, struct iio_context_info ***info)
Enumerate available contexts.