mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Make nTox work on MinGW/Win32
This commit is contained in:
parent
9b249c5ca8
commit
14a8ee4e0d
28
configure.ac
28
configure.ac
@ -115,8 +115,6 @@ AC_CANONICAL_HOST
|
|||||||
case $host_os in
|
case $host_os in
|
||||||
*mingw*)
|
*mingw*)
|
||||||
WIN32="yes"
|
WIN32="yes"
|
||||||
AC_MSG_WARN([nTox is not supported on $host_os yet, disabling])
|
|
||||||
BUILD_NTOX="no"
|
|
||||||
EXTRA_LT_LDFLAGS="$EXTRA_LT_LDFLAGS -no-undefined"
|
EXTRA_LT_LDFLAGS="$EXTRA_LT_LDFLAGS -no-undefined"
|
||||||
;;
|
;;
|
||||||
*solaris*)
|
*solaris*)
|
||||||
@ -202,9 +200,8 @@ AC_TYPE_UINT8_T
|
|||||||
|
|
||||||
# Checks for library functions.
|
# Checks for library functions.
|
||||||
AC_FUNC_FORK
|
AC_FUNC_FORK
|
||||||
AC_FUNC_MALLOC
|
|
||||||
AC_FUNC_REALLOC
|
AC_FUNC_REALLOC
|
||||||
AC_CHECK_FUNCS([gettimeofday memset socket strchr])
|
AC_CHECK_FUNCS([gettimeofday memset socket strchr malloc])
|
||||||
|
|
||||||
# pkg-config based tests
|
# pkg-config based tests
|
||||||
PKG_PROG_PKG_CONFIG
|
PKG_PROG_PKG_CONFIG
|
||||||
@ -271,12 +268,30 @@ if (test "x$BUILD_NTOX" = "xyes") && (test "x$NCURSES_FOUND" != "xyes"); then
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
if test "x$BUILD_NTOX" = "xyes"; then
|
if test "x$BUILD_NTOX" = "xyes"; then
|
||||||
|
if test "x$WIN32" = "xyes"; then
|
||||||
|
AC_CHECK_LIB([pdcurses], [clear],
|
||||||
|
[
|
||||||
|
NCURSES_LIBS="-lpdcurses"
|
||||||
|
AC_SUBST(NCURSES_LIBS)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
AC_MSG_ERROR([required library pdcurses was not found on your system])
|
||||||
|
BUILD_NTOX="no"
|
||||||
|
]
|
||||||
|
)
|
||||||
|
else
|
||||||
AC_CHECK_LIB([ncurses], [clear],
|
AC_CHECK_LIB([ncurses], [clear],
|
||||||
[],
|
[
|
||||||
|
NCURSES_LIBS="-lncurses"
|
||||||
|
AC_SUBST(NCURSES_LIBS)
|
||||||
|
],
|
||||||
[
|
[
|
||||||
unset ac_cv_lib_ncurses_clear
|
unset ac_cv_lib_ncurses_clear
|
||||||
AC_CHECK_LIB([ncurses], [clear],
|
AC_CHECK_LIB([ncurses], [clear],
|
||||||
[],
|
[
|
||||||
|
NCURSES_LIBS="-lncurses -ltinfo"
|
||||||
|
AC_SUBST(NCURSES_LIBS)
|
||||||
|
],
|
||||||
[
|
[
|
||||||
AC_MSG_WARN([not building nTox client because required library ncurses was not found on your system])
|
AC_MSG_WARN([not building nTox client because required library ncurses was not found on your system])
|
||||||
BUILD_NTOX="no"
|
BUILD_NTOX="no"
|
||||||
@ -289,6 +304,7 @@ if (test "x$BUILD_NTOX" = "xyes") && (test "x$NCURSES_FOUND" != "xyes"); then
|
|||||||
)
|
)
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (test "x$BUILD_DHT_BOOTSTRAP_DAEMON" = "xyes") && \
|
if (test "x$BUILD_DHT_BOOTSTRAP_DAEMON" = "xyes") && \
|
||||||
|
@ -13,8 +13,8 @@ nTox_CFLAGS = $(LIBSODIUM_CFLAGS) \
|
|||||||
nTox_LDADD = $(LIBSODIUM_LDFLAGS) \
|
nTox_LDADD = $(LIBSODIUM_LDFLAGS) \
|
||||||
libtoxcore.la \
|
libtoxcore.la \
|
||||||
$(LIBSODIUM_LIBS) \
|
$(LIBSODIUM_LIBS) \
|
||||||
$(NCURSES_LIBS)
|
$(NCURSES_LIBS) \
|
||||||
|
$(WINSOCK2_LIBS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,13 +20,30 @@
|
|||||||
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __WIN32__
|
||||||
|
#define _WIN32_WINNT 0x501
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#else
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "nTox.h"
|
#include "nTox.h"
|
||||||
#include "misc_tools.h"
|
#include "misc_tools.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef __WIN32__
|
||||||
#define c_sleep(x) Sleep(1*x)
|
#define c_sleep(x) Sleep(1*x)
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -50,6 +67,67 @@ typedef struct {
|
|||||||
Friend_request pending_requests[256];
|
Friend_request pending_requests[256];
|
||||||
uint8_t num_requests = 0;
|
uint8_t num_requests = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
resolve_addr():
|
||||||
|
address should represent IPv4 or a hostname with A record
|
||||||
|
|
||||||
|
returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i
|
||||||
|
returns 0 on failure
|
||||||
|
|
||||||
|
TODO: Fix ipv6 support
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32_t resolve_addr(const char *address)
|
||||||
|
{
|
||||||
|
struct addrinfo *server = NULL;
|
||||||
|
struct addrinfo hints;
|
||||||
|
int rc;
|
||||||
|
uint32_t addr;
|
||||||
|
|
||||||
|
memset(&hints, 0, sizeof(hints));
|
||||||
|
hints.ai_family = AF_INET; // IPv4 only right now.
|
||||||
|
hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses.
|
||||||
|
|
||||||
|
#ifdef __WIN32__
|
||||||
|
int res;
|
||||||
|
WSADATA wsa_data;
|
||||||
|
|
||||||
|
res = WSAStartup(MAKEWORD(2, 2), &wsa_data);
|
||||||
|
if (res != 0)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
rc = getaddrinfo(address, "echo", &hints, &server);
|
||||||
|
|
||||||
|
// Lookup failed.
|
||||||
|
if (rc != 0) {
|
||||||
|
#ifdef __WIN32__
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPv4 records only..
|
||||||
|
if (server->ai_family != AF_INET) {
|
||||||
|
freeaddrinfo(server);
|
||||||
|
#ifdef __WIN32__
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr;
|
||||||
|
|
||||||
|
freeaddrinfo(server);
|
||||||
|
#ifdef __WIN32__
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
void get_id(Tox *m, char *data)
|
void get_id(Tox *m, char *data)
|
||||||
{
|
{
|
||||||
sprintf(data, "[i] ID: ");
|
sprintf(data, "[i] ID: ");
|
||||||
@ -525,7 +603,7 @@ int main(int argc, char *argv[])
|
|||||||
free(binary_string);
|
free(binary_string);
|
||||||
nodelay(stdscr, TRUE);
|
nodelay(stdscr, TRUE);
|
||||||
|
|
||||||
while (true) {
|
while (1) {
|
||||||
if (on == 0 && tox_isconnected(m)) {
|
if (on == 0 && tox_isconnected(m)) {
|
||||||
new_lines("[i] connected to DHT\n[i] define username with /n");
|
new_lines("[i] connected to DHT\n[i] define username with /n");
|
||||||
on = 1;
|
on = 1;
|
||||||
@ -542,7 +620,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
getmaxyx(stdscr, y, x);
|
getmaxyx(stdscr, y, x);
|
||||||
|
|
||||||
if (c == '\n') {
|
if ((c == 0x0d) || (c == 0x0a)) {
|
||||||
line_eval(m, line);
|
line_eval(m, line);
|
||||||
strcpy(line, "");
|
strcpy(line, "");
|
||||||
} else if (c == 8 || c == 127) {
|
} else if (c == 8 || c == 127) {
|
||||||
|
@ -27,61 +27,16 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ncurses.h>
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include "../toxcore/tox.h"
|
#include "../toxcore/tox.h"
|
||||||
|
|
||||||
#define STRING_LENGTH 256
|
#define STRING_LENGTH 256
|
||||||
#define HISTORY 50
|
#define HISTORY 50
|
||||||
#define PUB_KEY_BYTES 32
|
#define PUB_KEY_BYTES 32
|
||||||
|
|
||||||
/*
|
uint32_t resolve_addr(const char *address);
|
||||||
resolve_addr():
|
|
||||||
address should represent IPv4 or a hostname with A record
|
|
||||||
|
|
||||||
returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i
|
|
||||||
returns 0 on failure
|
|
||||||
|
|
||||||
TODO: Fix ipv6 support
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t resolve_addr(const char *address)
|
|
||||||
{
|
|
||||||
struct addrinfo *server = NULL;
|
|
||||||
struct addrinfo hints;
|
|
||||||
int rc;
|
|
||||||
uint32_t addr;
|
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
|
||||||
hints.ai_family = AF_INET; // IPv4 only right now.
|
|
||||||
hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses.
|
|
||||||
|
|
||||||
rc = getaddrinfo(address, "echo", &hints, &server);
|
|
||||||
|
|
||||||
// Lookup failed.
|
|
||||||
if (rc != 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// IPv4 records only..
|
|
||||||
if (server->ai_family != AF_INET) {
|
|
||||||
freeaddrinfo(server);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr;
|
|
||||||
|
|
||||||
freeaddrinfo(server);
|
|
||||||
return addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void new_lines(char *line);
|
void new_lines(char *line);
|
||||||
void line_eval(Tox *m, char *line);
|
void line_eval(Tox *m, char *line);
|
||||||
void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ;
|
void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width) ;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user