Browse Source

add sleep() for fix compile error on windows

pull/309/head
ygg 4 years ago
parent
commit
e6c851d276
  1. 6
      include/edge_utils_win32.h
  2. 9
      include/n2n.h
  3. 10
      src/edge.c
  4. 8
      src/edge_utils.c
  5. 4
      win32/n2n_win32.h

6
include/edge_utils_win32.h

@ -21,9 +21,12 @@
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <process.h>
#include <n2n.h>
/* Multicast peers discovery disabled due to https://github.com/ntop/n2n/issues/65 */
#define SKIP_MULTICAST_PEERS_DISCOVERY
@ -34,7 +37,8 @@ struct tunread_arg {
extern HANDLE startTunReadThread(struct tunread_arg *arg);
#endif
#endif /* WIN32 */
#endif /* _EDGE_UTILS_WIN32_H_ */

9
include/n2n.h

@ -65,7 +65,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <unistd.h>
#include <time.h>
#ifndef WIN32
#include <unistd.h>
@ -248,7 +248,7 @@ typedef struct n2n_edge_callbacks {
/* ***************************************************** */
typedef struct n2n_priv_config {
typedef struct n2n_tuntap_priv_config {
char tuntap_dev_name[N2N_IFNAMSIZ];
char ip_mode[N2N_IF_MODE_SIZE];
char ip_addr[N2N_NETMASK_STR_SIZE];
@ -261,7 +261,7 @@ typedef struct n2n_priv_config {
uid_t userid;
gid_t groupid;
#endif
} n2n_priv_config_t;
} n2n_tuntap_priv_config_t;
/* *************************************************** */
@ -299,7 +299,6 @@ struct n2n_edge_stats {
};
struct n2n_edge {
n2n_priv_config_t priv_conf;
n2n_edge_conf_t conf;
/* Status */
@ -336,6 +335,8 @@ struct n2n_edge {
/* Statistics */
struct n2n_edge_stats stats;
/* Tuntap config */
n2n_tuntap_priv_config_t tuntap_priv_conf;
};
typedef struct sn_stats

10
src/edge.c

@ -273,7 +273,7 @@ static void setPayloadEncryption( n2n_edge_conf_t *conf, int cipher) {
/* *************************************************** */
static int setOption(int optkey, char *optargument, n2n_priv_config_t *ec, n2n_edge_conf_t *conf) {
static int setOption(int optkey, char *optargument, n2n_tuntap_priv_config_t *ec, n2n_edge_conf_t *conf) {
/* traceEvent(TRACE_NORMAL, "Option %c = %s", optkey, optargument ? optargument : ""); */
switch(optkey) {
@ -536,7 +536,7 @@ static const struct option long_options[] =
/* *************************************************** */
/* read command line options */
static int loadFromCLI(int argc, char *argv[], n2n_edge_conf_t *conf, n2n_priv_config_t *ec) {
static int loadFromCLI(int argc, char *argv[], n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) {
u_char c;
while((c = getopt_long(argc, argv,
@ -573,7 +573,7 @@ static char *trim(char *s) {
/* *************************************************** */
/* parse the configuration file */
static int loadFromFile(const char *path, n2n_edge_conf_t *conf, n2n_priv_config_t *ec) {
static int loadFromFile(const char *path, n2n_edge_conf_t *conf, n2n_tuntap_priv_config_t *ec) {
char buffer[4096], *line, *key, *value;
u_int line_len, opt_name_len;
FILE *fd;
@ -791,7 +791,7 @@ int main(int argc, char* argv[]) {
tuntap_dev tuntap; /* a tuntap device */
n2n_edge_t *eee; /* single instance for this program */
n2n_edge_conf_t conf; /* generic N2N edge config */
n2n_priv_config_t ec; /* config used for standalone program execution */
n2n_tuntap_priv_config_t ec; /* config used for standalone program execution */
#ifndef WIN32
struct passwd *pw = NULL;
#endif
@ -893,7 +893,7 @@ int main(int argc, char* argv[]) {
traceEvent(TRACE_ERROR, "Failed in edge_init");
exit(1);
}
memcpy(&(eee->priv_conf), &ec, sizeof(ec));
memcpy(&(eee->tuntap_priv_conf), &ec, sizeof(ec));
#ifndef WIN32
if(ec.daemon) {

8
src/edge_utils.c

@ -1503,11 +1503,11 @@ void edge_read_from_tap(n2n_edge_t * eee) {
{
traceEvent(TRACE_WARNING, "read()=%d [%d/%s]",
(signed int)len, errno, strerror(errno));
traceEvent(TRACE_WARNING, "TAP I/O operation aborted, restart after 10 seconds.");
sleep(10);
traceEvent(TRACE_WARNING, "TAP I/O operation aborted, restart later.");
sleep(3);
tuntap_close(&(eee->device));
tuntap_open(&(eee->device), eee->priv_conf.tuntap_dev_name, eee->priv_conf.ip_mode, eee->priv_conf.ip_addr,
eee->priv_conf.netmask, eee->priv_conf.device_mac, eee->priv_conf.mtu);
tuntap_open(&(eee->device), eee->tuntap_priv_conf.tuntap_dev_name, eee->tuntap_priv_conf.ip_mode, eee->tuntap_priv_conf.ip_addr,
eee->tuntap_priv_conf.netmask, eee->tuntap_priv_conf.device_mac, eee->tuntap_priv_conf.mtu);
}
else
{

4
win32/n2n_win32.h

@ -11,6 +11,8 @@
#define _CRT_SECURE_NO_WARNINGS
#endif
#define WIN32_LEAN_AND_MEAN
#if defined(__MINGW32__)
/* should be defined here and before winsock gets included */
#ifndef _WIN32_WINNT
@ -106,6 +108,6 @@ typedef struct tuntap_dev {
} tuntap_dev;
#define index(a, b) strchr(a, b)
#define sleep(x) Sleep(x * 1000)
#endif

Loading…
Cancel
Save