From 4f28d0b194fdd9607955f2e32de44f8fbf5d7d31 Mon Sep 17 00:00:00 2001 From: GDR! Date: Sat, 13 Dec 2014 17:24:39 +0000 Subject: [PATCH] More robust connection algorithm Stolen from uTox --- main.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main.c b/main.c index 73ad1d0..2694ce4 100644 --- a/main.c +++ b/main.c @@ -494,6 +494,12 @@ int parse_lossless_packet(void *sender_uc, const uint8_t *data, uint32_t len) return -1; } + if(!data) + { + fprintf(stderr, "Got NULL pointer from toxcore - WTF?\n"); + return -1; + } + if(data[0] != PROTOCOL_MAGIC_HIGH || data[1] != PROTOCOL_MAGIC_LOW) { fprintf(stderr, "Received data frame with invalid protocol magic number 0x%x%x\n", data[0], data[1]); @@ -836,6 +842,19 @@ int main(int argc, char *argv[]) tox_options.proxy_enabled = 0; tox = tox_new(&tox_options); + if(tox == NULL) + { + fprintf(stderr, "tox_new() failed - trying without proxy\n"); + if(!tox_options.proxy_enabled || (tox_options.proxy_enabled = 0, (tox = tox_new(&tox_options)) == NULL)) + { + fprintf(stderr, "tox_new() failed - trying without IPv6\n"); + if(!tox_options.ipv6enabled || (tox_options.ipv6enabled = 0, (tox = tox_new(&tox_options)) == NULL)) + { + fprintf(stderr, "tox_new() failed - exiting\n"); + exit(1); + } + } + } set_tox_username(tox);