-
Notifications
You must be signed in to change notification settings - Fork 5
/
wsdd.h
140 lines (112 loc) · 3.21 KB
/
wsdd.h
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
WSDD - Web Service Dynamic Discovery protocol server
Copyright (c) 2016 NETGEAR
Copyright (c) 2016 Hiro Sugawara
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _WSDD_H_
#define _WSDD_H_
#define _GNU_SOURCE
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <stdbool.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <time.h>
#include <syslog.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <linux/rtnetlink.h>
extern int debug_L, debug_W;
#define DEBUG(x, y, ...) \
do { \
if (debug_##y >= (x)) { \
fprintf(stderr, __VA_ARGS__); \
putc('\n', stderr); \
syslog(LOG_USER|LOG_ERR, __VA_ARGS__); \
} \
} while (0)
#ifndef HOST_NAME_MAX
#define HOST_NAME_MAX 255
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#endif
#ifndef max
#define max(a, b) ((a)>(b)?(a):(b))
#endif
#define _ADDRSTRLEN max(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)
typedef union {
struct sockaddr_in in;
struct sockaddr_in6 in6;
struct sockaddr_nl nl;
struct sockaddr_storage ss;
} _saddr_t;
#define _SIN_ADDR(x) (((x)->ss.ss_family == AF_INET) \
? (void *)&(x)->in.sin_addr \
: (void *)&(x)->in6.sin6_addr)
#define _SIN_PORT(x) ntohs(((x)->ss.ss_family == AF_INET) \
? (x)->in.sin_port \
: (x)->in6.sin6_port)
struct endpoint {
char ifname[IFNAMSIZ];
struct endpoint *next;
struct service *service;
int family, type, protocol;
in_port_t port;
int sock;
char *errstr;
int _errno;
size_t mlen, llen;
_saddr_t mcast, local;
union {
struct ip_mreq ip_mreq;
/* struct ip_mreqn ip_mreq; */
struct ipv6_mreq ipv6_mreq;
} mreq;
size_t mreqlen;
};
struct service {
const char *name;
const int family, type, protocol;
const char *port_name;
const in_port_t port_num;
const char *mcast_addr;
const uint32_t nl_groups;
int (*init)(struct endpoint *);
int (*recv)(struct endpoint *);
int (*timer)(struct endpoint *);
void (*exit)(struct endpoint *);
time_t interval;
};
extern int wsd_init(struct endpoint *);
extern int wsd_recv(struct endpoint *);
extern void wsd_exit(struct endpoint *);
extern int wsd_http(struct endpoint *);
extern int llmnr_init(struct endpoint *);
extern int llmnr_recv(struct endpoint *);
extern int llmnr_timer(struct endpoint *);
extern void llmnr_exit(struct endpoint *);
extern int connected_if(const _saddr_t *, _saddr_t *);
extern char *ip2uri(const char *);
extern int set_getresp(const char *, const char **);
extern void printBootInfoKeys(FILE *, int);
#endif