Skip to content

Commit 68d1d8a

Browse files
rgetzpcercuei
authored andcommitted
Windows DNS SD : add port knocking like other implementations
Both the Linux and Mac implemations of DNS SD ensures something is there before passing the host information up the stack. The Windows implemnation was missing this, so add it. Add locking since it's needed by those functions. Fix #559 Signed-off-by: Robin Getz <[email protected]>
1 parent e2ce2d3 commit 68d1d8a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

dns_sd_windows.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "debug.h"
1818
#include "dns_sd.h"
19+
#include "iio-lock.h"
1920
#include "iio-private.h"
2021
#include "mdns.h"
2122

@@ -189,6 +190,7 @@ int dnssd_find_hosts(struct dns_sd_discovery_data **ddata)
189190
WSADATA wsaData;
190191
const char service[] = "_iio._tcp.local";
191192
size_t records, capacity = 2048;
193+
struct dns_sd_discovery_data *d;
192194
unsigned int i, isock, num_sockets;
193195
void *buffer;
194196
int sockets[32];
@@ -202,14 +204,19 @@ int dnssd_find_hosts(struct dns_sd_discovery_data **ddata)
202204

203205
IIO_DEBUG("DNS SD: Start service discovery.\n");
204206

205-
*ddata = zalloc(sizeof(**ddata));
206-
if (!*ddata)
207+
d = zalloc(sizeof(*d));
208+
if (!d)
207209
goto out_wsa_cleanup;
210+
/* pass the structure back, so it can be freed if err */
211+
*ddata = d;
208212

213+
d->lock = iio_mutex_create();
214+
if (!d->lock)
215+
goto out_wsa_cleanup;
209216

210217
buffer = malloc(capacity);
211218
if (!buffer)
212-
goto out_wsa_cleanup;
219+
goto out_destroy_lock;
213220

214221
IIO_DEBUG("Sending DNS-SD discovery\n");
215222

@@ -250,7 +257,7 @@ int dnssd_find_hosts(struct dns_sd_discovery_data **ddata)
250257

251258
records += mdns_query_recv(sockets[isock],
252259
buffer, capacity,
253-
query_callback, *ddata,
260+
query_callback, d,
254261
transaction_id[isock]);
255262
}
256263
} while (records);
@@ -266,9 +273,14 @@ int dnssd_find_hosts(struct dns_sd_discovery_data **ddata)
266273

267274
IIO_DEBUG("Closed socket%s\n", (num_sockets > 1) ? "s" : "");
268275

276+
port_knock_discovery_data(&d);
277+
remove_dup_discovery_data(&d);
278+
269279
ret = 0;
270280
out_free_buffer:
271281
free(buffer);
282+
out_destroy_lock:
283+
iio_mutex_destroy(d->lock);
272284
out_wsa_cleanup:
273285
WSACleanup();
274286
return ret;

0 commit comments

Comments
 (0)