File: dns_sd.h

package info (click to toggle)
libiio 0.26-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,832 kB
  • sloc: ansic: 21,880; python: 1,844; cs: 1,232; sh: 1,062; cpp: 688; yacc: 441; xml: 192; lex: 172; makefile: 40
file content (86 lines) | stat: -rw-r--r-- 2,410 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * libiio - Library for interfacing industrial I/O (IIO) devices
 *
 * Copyright (C) 2014-2020 Analog Devices, Inc.
 * Author: Paul Cercueil
 *         Robin Getz
 */

#ifndef __IIO_DNS_SD_H
#define __IIO_DNS_SD_H

#include <stdbool.h>
#include <stdint.h>

#ifdef _WIN32
#include <winsock2.h>
#include <ntddndis.h>
#include <netioapi.h>
#else
#include <net/if.h>
#include <sys/param.h>
#endif

/* IPv6 Max = 4*8 + 7 + 1 for '%' + interface length */
#define DNS_SD_ADDRESS_STR_MAX (40 + IF_NAMESIZE)
#define FQDN_LEN (255)              /* RFC 1035 */

/* MacOS doesn't include ENOMEDIUM (No medium found) like Linux does */
#ifndef ENOMEDIUM
#define ENOMEDIUM ENOENT
#endif

/* Used everywhere */
#define IIOD_PORT 30431

struct addrinfo;
struct AvahiSimplePoll;
struct AvahiAddress;

/* Common structure which all dns_sd_[*] files fill out
 * Anything that is dynamically allocated (malloc) needs to be managed
 */
struct dns_sd_discovery_data {
	struct iio_mutex *lock;
	struct AvahiSimplePoll *poll;
	struct AvahiAddress *address;
	uint16_t found, resolved;
	char addr_str[DNS_SD_ADDRESS_STR_MAX];
	char *hostname;
	uint16_t port, iface;
	struct dns_sd_discovery_data *next;
};


/* This functions is implemented in network.c, but used in dns_sd.c
 */
int create_socket(const struct addrinfo *addrinfo);

/* These functions are common, and implemented in dns_sd_[*].c  based on the
 * implementations: avahi (linux), bonjour (mac), or ServiceDiscovery (Win10)
 */

/* Resolves all IIO hosts on the available networks, and passes back a linked list */
int dnssd_find_hosts(struct dns_sd_discovery_data ** ddata);

/* Deallocates complete list of discovery data */
void dnssd_free_all_discovery_data(struct dns_sd_discovery_data *d);

/* These functions are common, and found in dns_sd.c, but are used in the
 * dns_sd_[*].c implementations or network.c
 */

/* Passed back the first (random) IIOD service resolved by DNS DS. */
int dnssd_discover_host(char *addr_str, size_t addr_len, uint16_t *port);

/* remove duplicates from the list */
void remove_dup_discovery_data(struct dns_sd_discovery_data **ddata);

/* port knocks  */
void port_knock_discovery_data(struct dns_sd_discovery_data **ddata);

/* Use dnssd to resolve a given hostname */
int dnssd_resolve_host(const char *hostname, char *ip_addr, const int addr_len);

#endif /* __IIO_DNS_SD_H */