diff --git a/edge.c b/edge.c index 12da835..2c09b6e 100644 --- a/edge.c +++ b/edge.c @@ -394,6 +394,7 @@ static void daemonize() { /** Entry point to program from kernel. */ int main(int argc, char* argv[]) { int opt; + int keep_on_running = 1; int local_port = 0 /* any port */; int mgmt_port = N2N_EDGE_MGMT_PORT; /* 5644 by default */ char tuntap_dev_name[N2N_IFNAMSIZ] = "edge0"; @@ -744,7 +745,7 @@ int main(int argc, char* argv[]) { update_supernode_reg(&eee, time(NULL)); - return run_edge_loop(&eee); + return run_edge_loop(&eee, &keep_on_running); } /* ************************************** */ diff --git a/edge_utils.c b/edge_utils.c index c9ff1a0..249daab 100644 --- a/edge_utils.c +++ b/edge_utils.c @@ -1394,8 +1394,7 @@ static void readFromIPSocket(n2n_edge_t * eee) { /* ************************************** */ -int run_edge_loop(n2n_edge_t * eee) { - int keep_running=1; +int run_edge_loop(n2n_edge_t * eee, int *keep_running) { size_t numPurged; time_t lastIfaceCheck=0; time_t lastTransop=0; @@ -1404,6 +1403,8 @@ int run_edge_loop(n2n_edge_t * eee) { startTunReadThread(eee); #endif + *keep_running = 1; + /* Main loop * * select() is used to wait for input on either the TAP fd or the UDP/TCP @@ -1450,16 +1451,14 @@ int run_edge_loop(n2n_edge_t * eee) { readFromIPSocket(eee); } - if(FD_ISSET(eee->udp_mgmt_sock, &socket_mask)) - { + if(FD_ISSET(eee->udp_mgmt_sock, &socket_mask)) { /* Read a cooked socket from the internet socket. Writes on the TAP * socket. */ - readFromMgmtSocket(eee, &keep_running); + readFromMgmtSocket(eee, keep_running); } #ifndef WIN32 - if(FD_ISSET(eee->device.fd, &socket_mask)) - { + if(FD_ISSET(eee->device.fd, &socket_mask)) { /* Read an ethernet frame from the TAP socket. Write on the IP * socket. */ readFromTAPSocket(eee); @@ -1583,7 +1582,8 @@ void edge_term(n2n_edge_t * eee) { int quick_edge_init(char *device_name, char *community_name, char *encrypt_key, char *device_mac, char *local_ip_address, - char *supernode_ip_address_port) { + char *supernode_ip_address_port, + int *keep_on_running) { n2n_edge_t eee; edge_init(&eee); @@ -1610,5 +1610,5 @@ int quick_edge_init(char *device_name, char *community_name, update_supernode_reg(&eee, time(NULL)); - return(run_edge_loop(&eee)); + return(run_edge_loop(&eee, keep_on_running)); } diff --git a/example_edge_embed.c b/example_edge_embed.c index fbb4c1f..4bd1811 100644 --- a/example_edge_embed.c +++ b/example_edge_embed.c @@ -30,7 +30,8 @@ int main(int argc, char* argv[]) { char *my_mac_address = (char*)"DE:AD:BE:EF:01:10"; char *my_ipv4_addr = (char*)"1.2.3.4"; char *supernode = (char*)"7.8.9.10:1234"; - + int keep_on_running = 1; + /* Increase tracelevel to see what's happening */ traceLevel = 10; @@ -45,5 +46,6 @@ int main(int argc, char* argv[]) { secret_key, my_mac_address, my_ipv4_addr, - supernode)); + supernode, + &keep_on_running)); } diff --git a/n2n.h b/n2n.h index 10f1513..f0a56ca 100644 --- a/n2n.h +++ b/n2n.h @@ -323,11 +323,12 @@ void set_peer_operational(n2n_edge_t * eee, const char * supernode_ip(const n2n_edge_t * eee); int edge_init_twofish(n2n_edge_t * eee, uint8_t *encrypt_pwd, uint32_t encrypt_pwd_len); -int run_edge_loop(n2n_edge_t * eee); +int run_edge_loop(n2n_edge_t * eee, int *keep_running); void edge_term(n2n_edge_t * eee); int quick_edge_init(char *device_name, char *community_name, char *encrypt_key, char *device_mac, char *local_ip_address, - char *supernode_ip_address_port); + char *supernode_ip_address_port, + int *keep_on_running); #endif /* _N2N_H_ */