summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac56
-rw-r--r--testing/Makefile.inc4
-rw-r--r--testing/nTox.c84
-rw-r--r--testing/nTox.h49
4 files changed, 121 insertions, 72 deletions
diff --git a/configure.ac b/configure.ac
index 64d53dec..a06d3598 100644
--- a/configure.ac
+++ b/configure.ac
@@ -115,8 +115,6 @@ AC_CANONICAL_HOST
115case $host_os in 115case $host_os in
116 *mingw*) 116 *mingw*)
117 WIN32="yes" 117 WIN32="yes"
118 AC_MSG_WARN([nTox is not supported on $host_os yet, disabling])
119 BUILD_NTOX="no"
120 EXTRA_LT_LDFLAGS="$EXTRA_LT_LDFLAGS -no-undefined" 118 EXTRA_LT_LDFLAGS="$EXTRA_LT_LDFLAGS -no-undefined"
121 ;; 119 ;;
122 *solaris*) 120 *solaris*)
@@ -202,9 +200,8 @@ AC_TYPE_UINT8_T
202 200
203# Checks for library functions. 201# Checks for library functions.
204AC_FUNC_FORK 202AC_FUNC_FORK
205AC_FUNC_MALLOC
206AC_FUNC_REALLOC 203AC_FUNC_REALLOC
207AC_CHECK_FUNCS([gettimeofday memset socket strchr]) 204AC_CHECK_FUNCS([gettimeofday memset socket strchr malloc])
208 205
209# pkg-config based tests 206# pkg-config based tests
210PKG_PROG_PKG_CONFIG 207PKG_PROG_PKG_CONFIG
@@ -271,22 +268,41 @@ if (test "x$BUILD_NTOX" = "xyes") && (test "x$NCURSES_FOUND" != "xyes"); then
271 ] 268 ]
272 ) 269 )
273 if test "x$BUILD_NTOX" = "xyes"; then 270 if test "x$BUILD_NTOX" = "xyes"; then
274 AC_CHECK_LIB([ncurses], [clear], 271 if test "x$WIN32" = "xyes"; then
275 [], 272 AC_CHECK_LIB([pdcurses], [clear],
276 [ 273 [
277 unset ac_cv_lib_ncurses_clear 274 NCURSES_LIBS="-lpdcurses"
278 AC_CHECK_LIB([ncurses], [clear], 275 AC_SUBST(NCURSES_LIBS)
279 [], 276 ],
280 [ 277 [
281 AC_MSG_WARN([not building nTox client because required library ncurses was not found on your system]) 278 AC_MSG_ERROR([required library pdcurses was not found on your system])
282 BUILD_NTOX="no" 279 BUILD_NTOX="no"
283 ], 280 ]
284 [ 281 )
285 -ltinfo 282 else
286 ] 283 AC_CHECK_LIB([ncurses], [clear],
287 ) 284 [
288 ] 285 NCURSES_LIBS="-lncurses"
289 ) 286 AC_SUBST(NCURSES_LIBS)
287 ],
288 [
289 unset ac_cv_lib_ncurses_clear
290 AC_CHECK_LIB([ncurses], [clear],
291 [
292 NCURSES_LIBS="-lncurses -ltinfo"
293 AC_SUBST(NCURSES_LIBS)
294 ],
295 [
296 AC_MSG_WARN([not building nTox client because required library ncurses was not found on your system])
297 BUILD_NTOX="no"
298 ],
299 [
300 -ltinfo
301 ]
302 )
303 ]
304 )
305 fi
290 fi 306 fi
291 fi 307 fi
292fi 308fi
diff --git a/testing/Makefile.inc b/testing/Makefile.inc
index 067b6ead..bd499ab6 100644
--- a/testing/Makefile.inc
+++ b/testing/Makefile.inc
@@ -13,8 +13,8 @@ nTox_CFLAGS = $(LIBSODIUM_CFLAGS) \
13nTox_LDADD = $(LIBSODIUM_LDFLAGS) \ 13nTox_LDADD = $(LIBSODIUM_LDFLAGS) \
14 libtoxcore.la \ 14 libtoxcore.la \
15 $(LIBSODIUM_LIBS) \ 15 $(LIBSODIUM_LIBS) \
16 $(NCURSES_LIBS) 16 $(NCURSES_LIBS) \
17 17 $(WINSOCK2_LIBS)
18endif 18endif
19 19
20 20
diff --git a/testing/nTox.c b/testing/nTox.c
index 9df1e78b..128e729d 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -20,13 +20,30 @@
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 * 21 *
22 */ 22 */
23#ifdef HAVE_CONFIG_H
24 #include "config.h"
25#endif
26
27#ifdef __WIN32__
28 #define _WIN32_WINNT 0x501
29 #include <winsock2.h>
30 #include <ws2tcpip.h>
31#else
32 #include <sys/socket.h>
33 #include <netinet/in.h>
34 #include <arpa/inet.h>
35 #include <sys/types.h>
36 #include <netdb.h>
37#endif
38
39
23#include "nTox.h" 40#include "nTox.h"
24#include "misc_tools.h" 41#include "misc_tools.h"
25 42
26#include <stdio.h> 43#include <stdio.h>
27#include <time.h> 44#include <time.h>
28 45
29#ifdef WIN32 46#ifdef __WIN32__
30#define c_sleep(x) Sleep(1*x) 47#define c_sleep(x) Sleep(1*x)
31#else 48#else
32#include <unistd.h> 49#include <unistd.h>
@@ -50,6 +67,67 @@ typedef struct {
50Friend_request pending_requests[256]; 67Friend_request pending_requests[256];
51uint8_t num_requests = 0; 68uint8_t num_requests = 0;
52 69
70/*
71 resolve_addr():
72 address should represent IPv4 or a hostname with A record
73
74 returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i
75 returns 0 on failure
76
77 TODO: Fix ipv6 support
78*/
79
80uint32_t resolve_addr(const char *address)
81{
82 struct addrinfo *server = NULL;
83 struct addrinfo hints;
84 int rc;
85 uint32_t addr;
86
87 memset(&hints, 0, sizeof(hints));
88 hints.ai_family = AF_INET; // IPv4 only right now.
89 hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses.
90
91#ifdef __WIN32__
92 int res;
93 WSADATA wsa_data;
94
95 res = WSAStartup(MAKEWORD(2, 2), &wsa_data);
96 if (res != 0)
97 {
98 return 0;
99 }
100#endif
101
102 rc = getaddrinfo(address, "echo", &hints, &server);
103
104 // Lookup failed.
105 if (rc != 0) {
106#ifdef __WIN32__
107 WSACleanup();
108#endif
109 return 0;
110 }
111
112 // IPv4 records only..
113 if (server->ai_family != AF_INET) {
114 freeaddrinfo(server);
115#ifdef __WIN32__
116 WSACleanup();
117#endif
118 return 0;
119 }
120
121
122 addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr;
123
124 freeaddrinfo(server);
125#ifdef __WIN32__
126 WSACleanup();
127#endif
128 return addr;
129}
130
53void get_id(Tox *m, char *data) 131void get_id(Tox *m, char *data)
54{ 132{
55 sprintf(data, "[i] ID: "); 133 sprintf(data, "[i] ID: ");
@@ -525,7 +603,7 @@ int main(int argc, char *argv[])
525 free(binary_string); 603 free(binary_string);
526 nodelay(stdscr, TRUE); 604 nodelay(stdscr, TRUE);
527 605
528 while (true) { 606 while (1) {
529 if (on == 0 && tox_isconnected(m)) { 607 if (on == 0 && tox_isconnected(m)) {
530 new_lines("[i] connected to DHT\n[i] define username with /n"); 608 new_lines("[i] connected to DHT\n[i] define username with /n");
531 on = 1; 609 on = 1;
@@ -542,7 +620,7 @@ int main(int argc, char *argv[])
542 620
543 getmaxyx(stdscr, y, x); 621 getmaxyx(stdscr, y, x);
544 622
545 if (c == '\n') { 623 if ((c == 0x0d) || (c == 0x0a)) {
546 line_eval(m, line); 624 line_eval(m, line);
547 strcpy(line, ""); 625 strcpy(line, "");
548 } else if (c == 8 || c == 127) { 626 } else if (c == 8 || c == 127) {
diff --git a/testing/nTox.h b/testing/nTox.h
index df9d404a..a72ce0c2 100644
--- a/testing/nTox.h
+++ b/testing/nTox.h
@@ -27,61 +27,16 @@
27#include <stdio.h> 27#include <stdio.h>
28#include <stdlib.h> 28#include <stdlib.h>
29#include <string.h> 29#include <string.h>
30#include <ncurses.h>
31#include <curses.h> 30#include <curses.h>
32#include <ctype.h> 31#include <ctype.h>
33#include <sys/socket.h> 32
34#include <netinet/in.h>
35#include <arpa/inet.h>
36#include <sys/types.h>
37#include <netdb.h>
38#include "../toxcore/tox.h" 33#include "../toxcore/tox.h"
39 34
40#define STRING_LENGTH 256 35#define STRING_LENGTH 256
41#define HISTORY 50 36#define HISTORY 50
42#define PUB_KEY_BYTES 32 37#define PUB_KEY_BYTES 32
43 38
44/* 39uint32_t resolve_addr(const char *address);
45 resolve_addr():
46 address should represent IPv4 or a hostname with A record
47
48 returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i
49 returns 0 on failure
50
51 TODO: Fix ipv6 support
52*/
53
54uint32_t resolve_addr(const char *address)
55{
56 struct addrinfo *server = NULL;
57 struct addrinfo hints;
58 int rc;
59 uint32_t addr;
60
61 memset(&hints, 0, sizeof(hints));
62 hints.ai_family = AF_INET; // IPv4 only right now.
63 hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses.
64
65 rc = getaddrinfo(address, "echo", &hints, &server);
66
67 // Lookup failed.
68 if (rc != 0) {
69 return 0;
70 }
71
72 // IPv4 records only..
73 if (server->ai_family != AF_INET) {
74 freeaddrinfo(server);
75 return 0;
76 }
77
78
79 addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr;
80
81 freeaddrinfo(server);
82 return addr;
83}
84
85void new_lines(char *line); 40void new_lines(char *line);
86void line_eval(Tox *m, char *line); 41void line_eval(Tox *m, char *line);
87void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ; 42void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ;