From: Guus Sliepen Date: Wed, 23 Dec 2009 18:49:38 +0000 (+0100) Subject: Allow port to be specified in Address statements. X-Git-Tag: release-1.0.12~16 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=a9a803d5662832eb397837055a49fd94118eabf3;p=tinc Allow port to be specified in Address statements. This allows one to connect to use more than one port number to connect to another node. The syntax is now: Address = [] --- diff --git a/doc/tinc.conf.5.in b/doc/tinc.conf.5.in index 1cb2f0c8..8e644450 100644 --- a/doc/tinc.conf.5.in +++ b/doc/tinc.conf.5.in @@ -330,9 +330,10 @@ Since host configuration files only contain public keys, no secrets are revealed by sending out this information. .Bl -tag -width indent -.It Va Address Li = Ar address Bq recommended +.It Va Address Li = Ar address Oo port Oc Bq recommended The IP address or hostname of this tinc daemon on the real network. This will only be used when trying to make an outgoing connection to this tinc daemon. +Optionally, a port can be specified to use for this address. Multiple .Va Address variables can be specified, in which case each address will be tried until a working @@ -380,7 +381,10 @@ When this option is enabled, tinc will try to discover the path MTU to this node After the path MTU has been discovered, it will be enforced on the VPN. .It Va Port Li = Ar port Pq 655 -The port number on which this tinc daemon is listening for incoming connections. +The port number on which this tinc daemon is listening for incoming connections, +which is used if no port number is specified in an +.Va Address +statement. .It Va PublicKey Li = Ar key Bq obsolete The public RSA key of this tinc daemon. diff --git a/doc/tinc.texi b/doc/tinc.texi index e6e6a42e..35658188 100644 --- a/doc/tinc.texi +++ b/doc/tinc.texi @@ -943,10 +943,11 @@ and will only allow nodes and subnets on the VPN which are present in the @table @asis @cindex Address -@item Address = <@var{IP address}|@var{hostname}> [recommended] +@item Address = <@var{IP address}|@var{hostname}> [] [recommended] This variable is only required if you want to connect to this host. It must resolve to the external IP address where the host can be reached, not the one that is internal to the VPN. +If no port is specified, the default Port is used. @cindex Cipher @item Cipher = <@var{cipher}> (blowfish) diff --git a/src/net_socket.c b/src/net_socket.c index 46e0532e..cd41e37b 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -331,7 +331,7 @@ void finish_connecting(connection_t *c) { } void do_outgoing_connection(connection_t *c) { - char *address, *port; + char *address, *port, *space; int result; if(!c->outgoing) { @@ -352,8 +352,14 @@ begin: get_config_string(c->outgoing->cfg, &address); - if(!get_config_string(lookup_config(c->config_tree, "Port"), &port)) - xasprintf(&port, "655"); + space = strchr(address, ' '); + if(space) { + port = xstrdup(space + 1); + *space = 0; + } else { + if(!get_config_string(lookup_config(c->config_tree, "Port"), &port)) + port = xstrdup("655"); + } c->outgoing->ai = str2addrinfo(address, port, SOCK_STREAM); free(address);