From ab42c91a491823e67cdbe99c62d16654323d9666 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Tue, 11 Nov 2014 08:03:11 -0500 Subject: [PATCH] Prevent connection ips from switching on LAN. --- toxcore/LAN_discovery.c | 7 +++++++ toxcore/LAN_discovery.h | 7 ------- toxcore/net_crypto.c | 5 +++++ toxcore/net_crypto.h | 1 + 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index 436b16fd..74f10c98 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -28,6 +28,13 @@ #include "LAN_discovery.h" #include "util.h" +/* Used for get_broadcast(). */ +#ifdef __linux +#include +#include +#include +#endif + #define MAX_INTERFACES 16 diff --git a/toxcore/LAN_discovery.h b/toxcore/LAN_discovery.h index fcb094e4..5dffc3ad 100644 --- a/toxcore/LAN_discovery.h +++ b/toxcore/LAN_discovery.h @@ -28,13 +28,6 @@ #include "DHT.h" -/* Used for get_broadcast(). */ -#ifdef __linux -#include -#include -#include -#endif - /* Interval in seconds between LAN discovery packet sending. */ #define LAN_DISCOVERY_INTERVAL 10 diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index c83c5d54..a36bf3ad 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -1700,6 +1700,11 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port) return -1; if (!ipport_equal(&ip_port, &conn->ip_port)) { + if ((UDP_DIRECT_TIMEOUT + conn->direct_lastrecv_time) > current_time_monotonic()) { + if (LAN_ip(ip_port.ip) == 0 && LAN_ip(conn->ip_port.ip) == 0 && conn->ip_port.port == ip_port.port) + return -1; + } + if (bs_list_add(&c->ip_port_list, &ip_port, crypt_connection_id)) { bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id); conn->ip_port = ip_port; diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index f977e741..b9f9e31c 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h @@ -25,6 +25,7 @@ #define NET_CRYPTO_H #include "DHT.h" +#include "LAN_discovery.h" #include "TCP_client.h" #include