X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet_socket.c;h=8c8054900ba0fd718b6472e6d2d5e8c079e45a59;hp=865df78637cddcfb57b8c8019e5ee4c44e1c2127;hb=a227843b739d279b63adcf3736ebb03d856080c4;hpb=41a05f59ba2c3eb5caab555f096ed1b9fbe69ee3 diff --git a/src/net_socket.c b/src/net_socket.c index 865df786..8c805490 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -2,6 +2,7 @@ net_socket.c -- Handle various kinds of sockets. Copyright (C) 1998-2005 Ivo Timmermans, 2000-2009 Guus Sliepen + 2009 Florian Forster 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 @@ -13,11 +14,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - $Id$ + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "system.h" @@ -55,8 +54,7 @@ list_t *outgoing_list = NULL; /* Setup sockets */ -static void configure_tcp(connection_t *c) -{ +static void configure_tcp(connection_t *c) { int option; #ifdef O_NONBLOCK @@ -84,7 +82,7 @@ static void configure_tcp(connection_t *c) #endif } -static bool bind_to_interface(int sd) { /* {{{ */ +static bool bind_to_interface(int sd) { char *iface; #if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) @@ -111,9 +109,9 @@ static bool bind_to_interface(int sd) { /* {{{ */ #endif return true; -} /* }}} bool bind_to_interface */ +} -static bool bind_to_address(connection_t *c) { /* {{{ */ +static bool bind_to_address(connection_t *c) { char *node; struct addrinfo *ai_list; struct addrinfo *ai_ptr; @@ -169,17 +167,14 @@ static bool bind_to_address(connection_t *c) { /* {{{ */ freeaddrinfo(ai_list); return status ? false : true; -} /* }}} bool bind_to_address */ +} -int setup_listen_socket(const sockaddr_t *sa) -{ +int setup_listen_socket(const sockaddr_t *sa) { int nfd; char *addrstr; int option; char *iface; - cp(); - nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP); if(nfd < 0) { @@ -235,14 +230,11 @@ int setup_listen_socket(const sockaddr_t *sa) return nfd; } -int setup_vpn_in_socket(const sockaddr_t *sa) -{ +int setup_vpn_in_socket(const sockaddr_t *sa) { int nfd; char *addrstr; int option; - cp(); - nfd = socket(sa->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP); if(nfd < 0) { @@ -312,12 +304,9 @@ int setup_vpn_in_socket(const sockaddr_t *sa) return nfd; } /* int setup_vpn_in_socket */ -void retry_outgoing(outgoing_t *outgoing) -{ +void retry_outgoing(outgoing_t *outgoing) { event_t *event; - cp(); - outgoing->timeout += 5; if(outgoing->timeout > maxtimeout) @@ -334,10 +323,7 @@ void retry_outgoing(outgoing_t *outgoing) outgoing->timeout); } -void finish_connecting(connection_t *c) -{ - cp(); - +void finish_connecting(connection_t *c) { ifdebug(CONNECTIONS) logger(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname); configure_tcp(c); @@ -347,13 +333,10 @@ void finish_connecting(connection_t *c) send_id(c); } -void do_outgoing_connection(connection_t *c) -{ +void do_outgoing_connection(connection_t *c) { char *address, *port; int result; - cp(); - begin: if(!c->outgoing->ai) { if(!c->outgoing->cfg) { @@ -367,7 +350,7 @@ begin: get_config_string(c->outgoing->cfg, &address); if(!get_config_string(lookup_config(c->config_tree, "Port"), &port)) - asprintf(&port, "655"); + xasprintf(&port, "655"); c->outgoing->ai = str2addrinfo(address, port, SOCK_STREAM); free(address); @@ -443,13 +426,10 @@ begin: return; } -void setup_outgoing_connection(outgoing_t *outgoing) -{ +void setup_outgoing_connection(outgoing_t *outgoing) { connection_t *c; node_t *n; - cp(); - n = lookup_node(outgoing->name); if(n) @@ -490,15 +470,12 @@ void setup_outgoing_connection(outgoing_t *outgoing) accept a new tcp connect and create a new connection */ -bool handle_new_meta_connection(int sock) -{ +bool handle_new_meta_connection(int sock) { connection_t *c; sockaddr_t sa; int fd; socklen_t len = sizeof(sa); - cp(); - fd = accept(sock, &sa.sa, &len); if(fd < 0) { @@ -543,16 +520,13 @@ void free_outgoing(outgoing_t *outgoing) { free(outgoing); } -void try_outgoing_connections(void) -{ +void try_outgoing_connections(void) { static config_t *cfg = NULL; char *name; outgoing_t *outgoing; connection_t *c; avl_node_t *node; - cp(); - if(outgoing_list) { for(node = connection_tree->head; node; node = node->next) { c = node->data;