diff options
author | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2005-10-15 09:43:36 +0000 |
---|---|---|
committer | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2005-10-15 09:43:36 +0000 |
commit | 04f4b793f90293a6092f17208810d094a4a96768 (patch) | |
tree | 9c7ce4bee5a8874b7a1cac1461af9dcbe25e51f0 /socket.c | |
parent | svn merge -r 618:619 $SO/patches/openvpn-2-0_rc16-mh/openvpn (diff) | |
download | openvpn-04f4b793f90293a6092f17208810d094a4a96768.tar.xz |
svn merge -r 614:615 $SO/patches/openvpn-2-1_alpha3a-tcpbind
Added --bind option for TCP client connections (Ewan Bhamrah Harley).
Pre-2.1-beta3
git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@623 e7ae566f-a301-0410-adde-c780ea21d3b5
Diffstat (limited to 'socket.c')
-rw-r--r-- | socket.c | 42 |
1 files changed, 30 insertions, 12 deletions
@@ -686,7 +686,25 @@ socket_listen_accept (socket_descriptor_t sd, } static void +socket_bind (socket_descriptor_t sd, + struct openvpn_sockaddr *local) +{ + struct gc_arena gc = gc_new (); + + if (bind (sd, (struct sockaddr *) &local->sa, sizeof (local->sa))) + { + const int errnum = openvpn_errno_socket (); + msg (M_FATAL, "TCP/UDP: Socket bind failed on local address %s: %s", + print_sockaddr (local, &gc), + strerror_ts (errnum, &gc)); + } + gc_free (&gc); +} + +static void socket_connect (socket_descriptor_t *sd, + struct openvpn_sockaddr *local, + bool bind_local, struct openvpn_sockaddr *remote, struct remote_list *remote_list, const char *remote_dynamic, @@ -727,6 +745,8 @@ socket_connect (socket_descriptor_t *sd, } *sd = create_socket_tcp (); + if (bind_local) + socket_bind (*sd, local); update_remote (remote_dynamic, remote, remote_changed); } @@ -796,14 +816,12 @@ resolve_bind_local (struct link_socket *sock) /* bind to local address/port */ if (sock->bind_local) { - if (bind (sock->sd, (struct sockaddr *) &sock->info.lsa->local.sa, - sizeof (sock->info.lsa->local.sa))) - { - const int errnum = openvpn_errno_socket (); - msg (M_FATAL, "TCP/UDP: Socket bind failed on local address %s: %s", - print_sockaddr (&sock->info.lsa->local, &gc), - strerror_ts (errnum, &gc)); - } +#ifdef ENABLE_SOCKS + if (sock->socks_proxy && sock->info.proto == PROTO_UDPv4) + socket_bind (sock->ctrl_sd, &sock->info.lsa->local); + else +#endif + socket_bind (sock->sd, &sock->info.lsa->local); } gc_free (&gc); } @@ -1070,10 +1088,6 @@ link_socket_init_phase1 (struct link_socket *sock, else sock->bind_local = true; } - else if (sock->info.proto == PROTO_TCPv4_CLIENT) - { - sock->bind_local = false; - } /* were we started by inetd or xinetd? */ if (sock->inetd) @@ -1176,6 +1190,8 @@ link_socket_init_phase2 (struct link_socket *sock, else if (sock->info.proto == PROTO_TCPv4_CLIENT) { socket_connect (&sock->sd, + &sock->info.lsa->local, + sock->bind_local, &sock->info.lsa->actual.dest, sock->remote_list, remote_dynamic, @@ -1214,6 +1230,8 @@ link_socket_init_phase2 (struct link_socket *sock, else if (sock->info.proto == PROTO_UDPv4 && sock->socks_proxy) { socket_connect (&sock->ctrl_sd, + &sock->info.lsa->local, + sock->bind_local, &sock->info.lsa->actual.dest, NULL, remote_dynamic, |