summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCoren[m] <Break@Ocean>2013-09-11 15:19:39 +0200
committerCoren[m] <Break@Ocean>2013-09-11 15:19:39 +0200
commitd35fee43ba7fe131e9c3dcda5167a46eacbf315a (patch)
treedcd539e4964b084312e0086072abbc8f25c3033e
parenta326e851ba532756fefd9b83555be66f3c9de764 (diff)
toxcore/util.h:
- moved cmdline_parsefor_ipv46() to testing/misc_tools.c
-rw-r--r--other/DHT_bootstrap.c1
-rw-r--r--testing/DHT_test.c1
-rw-r--r--testing/Lossless_UDP_testclient.c2
-rw-r--r--testing/Lossless_UDP_testserver.c2
-rw-r--r--testing/Messenger_test.c1
-rw-r--r--testing/misc_tools.c33
-rw-r--r--toxcore/util.c32
-rw-r--r--toxcore/util.h2
8 files changed, 35 insertions, 39 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c
index f2e792ac..f5fa9818 100644
--- a/other/DHT_bootstrap.c
+++ b/other/DHT_bootstrap.c
@@ -33,7 +33,6 @@
33#include "../toxcore/DHT.h" 33#include "../toxcore/DHT.h"
34#include "../toxcore/friend_requests.h" 34#include "../toxcore/friend_requests.h"
35#include "../testing/misc_tools.c" 35#include "../testing/misc_tools.c"
36#include "../toxcore/util.h"
37 36
38/* Sleep function (x = milliseconds) */ 37/* Sleep function (x = milliseconds) */
39#ifdef WIN32 38#ifdef WIN32
diff --git a/testing/DHT_test.c b/testing/DHT_test.c
index 5451c467..ba8c2f23 100644
--- a/testing/DHT_test.c
+++ b/testing/DHT_test.c
@@ -34,7 +34,6 @@
34//#include "../core/network.h" 34//#include "../core/network.h"
35#include "../toxcore/DHT.h" 35#include "../toxcore/DHT.h"
36#include "../toxcore/friend_requests.h" 36#include "../toxcore/friend_requests.h"
37#include "../toxcore/util.h"
38#include "misc_tools.c" 37#include "misc_tools.c"
39 38
40#include <string.h> 39#include <string.h>
diff --git a/testing/Lossless_UDP_testclient.c b/testing/Lossless_UDP_testclient.c
index e36ac6eb..7891ce64 100644
--- a/testing/Lossless_UDP_testclient.c
+++ b/testing/Lossless_UDP_testclient.c
@@ -34,7 +34,7 @@
34 34
35#include "../toxcore/network.h" 35#include "../toxcore/network.h"
36#include "../toxcore/Lossless_UDP.h" 36#include "../toxcore/Lossless_UDP.h"
37#include "../toxcore/util.h" 37#include "misc_tools.c"
38 38
39#ifdef WIN32 39#ifdef WIN32
40 40
diff --git a/testing/Lossless_UDP_testserver.c b/testing/Lossless_UDP_testserver.c
index 97c3eb46..0fd4edd9 100644
--- a/testing/Lossless_UDP_testserver.c
+++ b/testing/Lossless_UDP_testserver.c
@@ -34,7 +34,7 @@
34 34
35#include "../toxcore/network.h" 35#include "../toxcore/network.h"
36#include "../toxcore/Lossless_UDP.h" 36#include "../toxcore/Lossless_UDP.h"
37#include "../toxcore/util.h" 37#include "misc_tools.c"
38 38
39//Sleep function (x = milliseconds) 39//Sleep function (x = milliseconds)
40#ifdef WIN32 40#ifdef WIN32
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 93069226..14d9ca20 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -43,7 +43,6 @@
43 43
44#include "../toxcore/Messenger.h" 44#include "../toxcore/Messenger.h"
45#include "misc_tools.c" 45#include "misc_tools.c"
46#include "../toxcore/util.h"
47 46
48#ifdef WIN32 47#ifdef WIN32
49 48
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
index c4dce1bb..824200d8 100644
--- a/testing/misc_tools.c
+++ b/testing/misc_tools.c
@@ -46,3 +46,36 @@ unsigned char *hex_string_to_bin(char hex_string[])
46 46
47 return val; 47 return val;
48} 48}
49
50
51int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
52{
53 int argvoffset = 0, argi;
54 for(argi = 1; argi < argc; argi++)
55 if (!strncasecmp(argv[argi], "--ipv", 5)) {
56 if (argv[argi][5] && !argv[argi][6]) {
57 char c = argv[argi][5];
58 if (c == '4')
59 *ipv6enabled = 0;
60 else if (c == '6')
61 *ipv6enabled = 1;
62 else {
63 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
64 return -1;
65 }
66 }
67 else {
68 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
69 return -1;
70 }
71
72 if (argvoffset != argi - 1) {
73 printf("Argument must come first: %s.\n", argv[argi]);
74 return -1;
75 }
76
77 argvoffset++;
78 }
79
80 return argvoffset;
81};
diff --git a/toxcore/util.c b/toxcore/util.c
index 7b5ddc49..19d464d4 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -43,38 +43,6 @@ void id_cpy(uint8_t *dest, uint8_t *src)
43 memcpy(dest, src, CLIENT_ID_SIZE); 43 memcpy(dest, src, CLIENT_ID_SIZE);
44} 44}
45 45
46int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
47{
48 int argvoffset = 0, argi;
49 for(argi = 1; argi < argc; argi++)
50 if (!strncasecmp(argv[argi], "--ipv", 5)) {
51 if (argv[argi][5] && !argv[argi][6]) {
52 char c = argv[argi][5];
53 if (c == '4')
54 *ipv6enabled = 0;
55 else if (c == '6')
56 *ipv6enabled = 1;
57 else {
58 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
59 return -1;
60 }
61 }
62 else {
63 printf("Invalid argument: %s. Try --ipv4 or --ipv6!\n", argv[argi]);
64 return -1;
65 }
66
67 if (argvoffset != argi - 1) {
68 printf("Argument must come first: %s.\n", argv[argi]);
69 return -1;
70 }
71
72 argvoffset++;
73 }
74
75 return argvoffset;
76};
77
78#ifdef LOGGING 46#ifdef LOGGING
79char logbuffer[512]; 47char logbuffer[512];
80static FILE *logfile = NULL; 48static FILE *logfile = NULL;
diff --git a/toxcore/util.h b/toxcore/util.h
index e7be2d51..71be84ca 100644
--- a/toxcore/util.h
+++ b/toxcore/util.h
@@ -16,8 +16,6 @@ uint64_t random_64b();
16bool id_eq(uint8_t *dest, uint8_t *src); 16bool id_eq(uint8_t *dest, uint8_t *src);
17void id_cpy(uint8_t *dest, uint8_t *src); 17void id_cpy(uint8_t *dest, uint8_t *src);
18 18
19int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled);
20
21#undef LOGGING 19#undef LOGGING
22/* #define LOGGING */ 20/* #define LOGGING */
23#ifdef LOGGING 21#ifdef LOGGING