summaryrefslogtreecommitdiff
path: root/toxcore/LAN_discovery.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-02-05 16:11:49 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-02-08 14:57:34 +0000
commit8a0e98bab8a4bccd11adc0e2c838910ed1b6d794 (patch)
tree09e6cab043b303a26829521914d8b5d1e15df846 /toxcore/LAN_discovery.c
parent36ba80aacb2a582854f0e5e3ed0d69ca63db52ea (diff)
Fix LAN discovery on FreeBSD.
Also, add an auto-test for bootstrap and for LAN discovery. Bootstrap is never tested otherwise, and LAN discovery is a prerequisite for everything else. Having these two tests lets us rule out or identify LAN discovery as a possible cause for test failures.
Diffstat (limited to 'toxcore/LAN_discovery.c')
-rw-r--r--toxcore/LAN_discovery.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index 742b91ab..cb10b0aa 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -29,12 +29,6 @@
29 29
30#include "util.h" 30#include "util.h"
31 31
32/* Used for get_broadcast(). */
33#ifdef __linux
34#include <linux/netdevice.h>
35#include <sys/ioctl.h>
36#endif
37
38#define MAX_INTERFACES 16 32#define MAX_INTERFACES 16
39 33
40 34
@@ -112,7 +106,17 @@ static void fetch_broadcast_info(uint16_t port)
112 } 106 }
113} 107}
114 108
115#elif defined(__linux__) 109#elif defined(__linux__) || defined(__FreeBSD__)
110
111#ifdef __linux__
112#include <linux/netdevice.h>
113#endif
114
115#ifdef __FreeBSD__
116#include <net/if.h>
117#endif
118
119#include <sys/ioctl.h>
116 120
117static void fetch_broadcast_info(uint16_t port) 121static void fetch_broadcast_info(uint16_t port)
118{ 122{
@@ -121,9 +125,9 @@ static void fetch_broadcast_info(uint16_t port)
121 * Definitely won't work like this on Windows... 125 * Definitely won't work like this on Windows...
122 */ 126 */
123 broadcast_count = 0; 127 broadcast_count = 0;
124 Socket sock = 0; 128 const Socket sock = net_socket(TOX_AF_INET, TOX_SOCK_STREAM, 0);
125 129
126 if ((sock = net_socket(TOX_AF_INET, TOX_SOCK_STREAM, 0)) < 0) { 130 if (sock < 0) {
127 return; 131 return;
128 } 132 }
129 133
@@ -217,9 +221,7 @@ static uint32_t send_broadcasts(Networking_Core *net, uint16_t port, const uint8
217 return 0; 221 return 0;
218 } 222 }
219 223
220 int i; 224 for (int i = 0; i < broadcast_count; i++) {
221
222 for (i = 0; i < broadcast_count; i++) {
223 sendpacket(net, broadcast_ip_ports[i], data, length); 225 sendpacket(net, broadcast_ip_ports[i], data, length);
224 } 226 }
225 227
@@ -346,17 +348,23 @@ static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *pack
346{ 348{
347 DHT *dht = (DHT *)object; 349 DHT *dht = (DHT *)object;
348 350
351 char ip_str[IP_NTOA_LEN] = { 0 };
352 ip_ntoa(&source.ip, ip_str, sizeof(ip_str));
353
354 // TODO(iphydf): Add logging for this case.
355 // Why should we reject discovery packets from outside the LAN?
356#if 0
357
349 if (ip_is_lan(source.ip) == -1) { 358 if (ip_is_lan(source.ip) == -1) {
350 return 1; 359 return 1;
351 } 360 }
352 361
362#endif
363
353 if (length != CRYPTO_PUBLIC_KEY_SIZE + 1) { 364 if (length != CRYPTO_PUBLIC_KEY_SIZE + 1) {
354 return 1; 365 return 1;
355 } 366 }
356 367
357 char ip_str[IP_NTOA_LEN] = { 0 };
358 ip_ntoa(&source.ip, ip_str, sizeof(ip_str));
359
360 DHT_bootstrap(dht, source, packet + 1); 368 DHT_bootstrap(dht, source, packet + 1);
361 return 0; 369 return 0;
362} 370}