X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet_socket.c;h=c691780e800f1a063d84cc531086a7b010ac2ae6;hp=efa0f559c1c69f7a8a04f2b17dbfb891f326ff09;hb=df3220a1549f992cbf4a9b6e67c1e67b69896c7d;hpb=7926a156e5b118d06295228e57de0cc9de0433b4 diff --git a/src/net_socket.c b/src/net_socket.c index efa0f559..c691780e 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -1,7 +1,7 @@ /* net_socket.c -- Handle various kinds of sockets. - Copyright (C) 1998-2004 Ivo Timmermans , - 2000-2004 Guus Sliepen + Copyright (C) 1998-2005 Ivo Timmermans , + 2000-2005 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -41,6 +41,7 @@ int addressfamily = AF_UNSPEC; int maxtimeout = 900; int seconds_till_retry = 5; +bool blockingtcp = false; listen_socket_t listen_socket[MAXSOCKETS]; int listen_sockets; @@ -240,6 +241,16 @@ void finish_connecting(connection_t *c) ifdebug(CONNECTIONS) logger(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname); +#ifdef O_NONBLOCK + if(blockingtcp) { + int flags = fcntl(c->socket, F_GETFL); + + if(fcntl(c->socket, F_SETFL, flags & ~O_NONBLOCK) < 0) { + logger(LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno)); + } + } +#endif + c->last_ping_time = now; send_id(c); @@ -413,6 +424,7 @@ bool handle_new_meta_connection(int sock) sockaddrunmap(&sa); c = new_connection(); + c->name = NULL; c->outcipher = myself->connection->outcipher; c->outdigest = myself->connection->outdigest; c->outmaclength = myself->connection->outmaclength; @@ -425,6 +437,16 @@ bool handle_new_meta_connection(int sock) ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Connection from %s"), c->hostname); +#ifdef O_NONBLOCK + if(blockingtcp) { + int flags = fcntl(c->socket, F_GETFL); + + if(fcntl(c->socket, F_SETFL, flags & ~O_NONBLOCK) < 0) { + logger(LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno)); + } + } +#endif + connection_add(c); c->allow_request = ID; @@ -441,8 +463,7 @@ void try_outgoing_connections(void) cp(); - for(cfg = lookup_config(config_tree, "ConnectTo"); cfg; - cfg = lookup_config_next(config_tree, cfg)) { + for(cfg = lookup_config(config_tree, "ConnectTo"); cfg; cfg = lookup_config_next(config_tree, cfg)) { get_config_string(cfg, &name); if(!check_id(name)) {