From f932fd400c12271edeec6abf06fd00a554848419 Mon Sep 17 00:00:00 2001 From: "Coren[m]" Date: Mon, 9 Sep 2013 20:14:24 +0200 Subject: [PATCH] tox.*, Messenger.*: - initialisation: argument added to enable/disable ipv6 as socket Messenger_test.c: - initialisation: ipv4 hardcoded for now - delegating IP resolution to DHT_bootstrap_ex() --- testing/Messenger_test.c | 9 ++++----- toxcore/Messenger.c | 8 +++++++- toxcore/Messenger.h | 2 +- toxcore/tox.c | 6 +++++- toxcore/tox.h | 3 +++ 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index e85a85a2..04d3bc14 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -100,7 +100,8 @@ int main(int argc, char *argv[]) exit(0); } - m = initMessenger(); + /* IPv6: maybe allow from cmdline --ipv6? sticking to IPv4 for now */ + m = initMessenger(0); if ( !m ) { fputs("Failed to allocate messenger datastructure\n", stderr); @@ -108,10 +109,8 @@ int main(int argc, char *argv[]) } if (argc > 3) { - IP_Port bootstrap_ip_port; - bootstrap_ip_port.port = htons(atoi(argv[2])); - bootstrap_ip_port.ip.uint32 = inet_addr(argv[1]); - DHT_bootstrap(m->dht, bootstrap_ip_port, hex_string_to_bin(argv[3])); + uint16_t port = htons(atoi(argv[2])); + DHT_bootstrap_ex(m->dht, argv[1], port, hex_string_to_bin(argv[3])); } else { FILE *file = fopen(argv[1], "rb"); diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index e18e9efc..48d40f43 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -650,15 +650,21 @@ static void LANdiscovery(Messenger *m) } /* Run this at startup. */ -Messenger *initMessenger(void) +Messenger *initMessenger(uint8_t ipv6enabled) { Messenger *m = calloc(1, sizeof(Messenger)); if ( ! m ) return NULL; +#ifdef NETWORK_IP_PORT_IS_IPV6 + IPAny ip; + memset(&ip, 0, sizeof(ip)); + ip.family = ipv6enabled ? AF_INET6 : AF_INET; +#else IP4 ip; ip.uint32 = 0; +#endif m->net = new_networking(ip, PORT); if (m->net == NULL) { diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index c512245c..34131a20 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -367,7 +367,7 @@ void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, in * return allocated instance of Messenger on success. * return 0 if there are problems. */ -Messenger *initMessenger(void); +Messenger *initMessenger(uint8_t ipv6enabled); /* Run this before closing shop * Free all datastructures. diff --git a/toxcore/tox.c b/toxcore/tox.c index 1507b2c5..d48de0d8 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -394,9 +394,13 @@ int tox_isconnected(void *tox) * return allocated instance of tox on success. * return 0 if there are problems. */ +void *tox_new_ex(uint8_t ipv6enabled) +{ + return initMessenger(ipv6enabled); +} void *tox_new(void) { - return initMessenger(); + return tox_new_ex(0); } /* Run this before closing shop. diff --git a/toxcore/tox.h b/toxcore/tox.h index 77f0be7f..f8d7975f 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -50,6 +50,8 @@ typedef struct { uint16_t padding; } tox_IP_Port; +#define TOX_IP_IS_IPV6 0 + /* Errors for m_addfriend * FAERR - Friend Add Error */ @@ -307,6 +309,7 @@ int tox_isconnected(Tox *tox); * return 0 if there are problems. */ Tox *tox_new(void); +Tox *tox_new_ex(uint8_t ipv6enabled); /* Run this before closing shop. * Free all datastructures. */