open62541 1.4.19
Open source implementation of OPC UA
Loading...
Searching...
No Matches
mdnsd.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2003 Jeremie Miller <jer@jabber.org>
3 * Copyright (c) 2016-2026 Joachim Wiberg <troglobit@gmail.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the copyright holders nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef MDNSD_H_
31#define MDNSD_H_
32
33#include <net/if.h> /* IFNAMSIZ */
34#include <netinet/in.h>
35#include <libmdnsd/mdnsd.h>
36#include <libmdnsd/sdtxt.h>
37
38#include "queue.h"
39
40/** From The Practice of Programming, by Kernighan and Pike */
41#ifndef NELEMS
42#define NELEMS(array) (sizeof(array) / sizeof((array)[0]))
43#endif
44
45#ifndef IN_ZERONET
46#define IN_ZERONET(addr) ((addr & IN_CLASSA_NET) == 0)
47#endif
48
49#ifndef IN_LOOPBACK
50#define IN_LOOPBACK(addr) ((addr & IN_CLASSA_NET) == 0x7f000000)
51#endif
52
53#ifndef IN_LINKLOCAL
54#define IN_LINKLOCALNETNUM 0xa9fe0000
55#define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == IN_LINKLOCALNETNUM)
56#endif
57
58struct iface {
60 char unused;
61 char changed;
62
63 char ifname[IFNAMSIZ];
64 int ifindex; /* Physical interface index */
65 struct in_addr inaddr; /* == 0 for non IP interfaces */
66 struct in_addr inaddr_old;
67 struct in6_addr in6addr; /* == :: for non IP interfaces */
68 struct in6_addr in6addr_old;
69
70 int sd;
71 int sd6; /* IPv6 multicast socket */
72
74 mdns_daemon_t *mdns6; /* IPv6 transport context */
75 int hostid; /* init to 1, +1 on conflict */
76};
77
78void mdnsd_conflict(char *name, int type, void *arg);
79
80/** addr.c */
81struct iface *iface_iterator(int first);
82struct iface *iface_find(const char *ifname);
83void iface_free(struct iface *iface);
84void iface_init(char *ifname);
85void iface_exit(void);
86
87/** conf.c */
88int conf_init(struct iface *iface, const char *path, const char *hostnm);
89
90/** replacement functions for systems that don't have them */
91#ifndef HAVE_PIDFILE
92int pidfile(const char *basename);
93#endif
94
95#ifndef HAVE_STRLCPY
96size_t strlcpy(char *dst, const char *src, size_t siz);
97#endif
98
99static inline int is_linklocal(struct in_addr *ina)
100{
101 return IN_LINKLOCAL(ntohl(ina->s_addr));
102}
103
104static inline int is_zeronet(struct in_addr *ina)
105{
106 return IN_ZERONET(ntohl(ina->s_addr));
107}
108
109static inline int is_add_valid(struct in_addr *ina)
110{
111 in_addr_t addr;
112
113 addr = ntohl(ina->s_addr);
114 if (IN_ZERONET(addr) || IN_LOOPBACK(addr) || IN_LINKLOCAL(addr))
115 return 0;
116
117 return 1;
118}
119
120#endif /* MDNSD_H_ */
struct mdns_daemon mdns_daemon_t
Main daemon data.
Definition mdnsd.h:50
#define TAILQ_ENTRY(type)
Definition queue.h:416
void iface_init(char *ifname)
int conf_init(struct iface *iface, const char *path, const char *hostnm)
conf.c
void iface_free(struct iface *iface)
struct iface * iface_find(const char *ifname)
#define IN_LINKLOCAL(addr)
Definition mdnsd.h:55
#define IN_LOOPBACK(addr)
Definition mdnsd.h:50
struct iface * iface_iterator(int first)
addr.c
#define IN_ZERONET(addr)
Definition mdnsd.h:46
void iface_exit(void)
void mdnsd_conflict(char *name, int type, void *arg)
size_t strlcpy(char *dst, const char *src, size_t siz)
int pidfile(const char *basename)
replacement functions for systems that don't have them
Definition mdnsd.h:58
char ifname[IFNAMSIZ]
Definition mdnsd.h:63
struct in_addr inaddr
Definition mdnsd.h:65
struct in6_addr in6addr_old
Definition mdnsd.h:68
mdns_daemon_t * mdns
Definition mdnsd.h:73
char unused
Definition mdnsd.h:60
int sd
Definition mdnsd.h:70
struct iface::@9 link
struct in6_addr in6addr
Definition mdnsd.h:67
int ifindex
Definition mdnsd.h:64
struct in_addr inaddr_old
Definition mdnsd.h:66
char changed
Definition mdnsd.h:61
mdns_daemon_t * mdns6
Definition mdnsd.h:74
int hostid
Definition mdnsd.h:75
int sd6
Definition mdnsd.h:71
void * dst
Definition types.h:948
qn name
Definition types.h:517
const UA_DataType * type
Definition types.h:626