summaryrefslogtreecommitdiffstats
path: root/src/openvpn/socks.c
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2013-11-21 21:08:02 +0100
committerGert Doering <gert@greenie.muc.de>2013-11-22 19:18:33 +0100
commit076fd3e46bbbe6261317d58cc2442f8eccc927ce (patch)
tree89ab4c04a76ed02fed6fa55d86e6b96922eedc1d /src/openvpn/socks.c
parente85d87523af43c5fe5188f7ee1e2fdd2861dcffc (diff)
downloadopenvpn-076fd3e46bbbe6261317d58cc2442f8eccc927ce.tar.gz
openvpn-076fd3e46bbbe6261317d58cc2442f8eccc927ce.tar.xz
openvpn-076fd3e46bbbe6261317d58cc2442f8eccc927ce.zip
Change the type of all ports in openvpn to const char* and let getaddrinfo resolve the port together with the hostname.
This delays error reporting from config parsing to resolving of host addresses. But it allows statements like remote openvpn.example.org openvpn port https management localhost ntp Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Gert Doering <gert@greenie.muc.de> Message-Id: <1385064495-25877-1-git-send-email-arne@rfc2549.org> URL: http://article.gmane.org/gmane.network.openvpn.devel/8018 Signed-off-by: Gert Doering <gert@greenie.muc.de>
Diffstat (limited to 'src/openvpn/socks.c')
-rw-r--r--src/openvpn/socks.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c
index 235982e..a20f139 100644
--- a/src/openvpn/socks.c
+++ b/src/openvpn/socks.c
@@ -61,7 +61,7 @@ socks_adjust_frame_parameters (struct frame *frame, int proto)
struct socks_proxy_info *
socks_proxy_new (const char *server,
- int port,
+ const char *port,
const char *authfile,
bool retry)
{
@@ -70,7 +70,7 @@ socks_proxy_new (const char *server,
ALLOC_OBJ_CLEAR (p, struct socks_proxy_info);
ASSERT (server);
- ASSERT (legal_ipv4_port (port));
+ ASSERT (port);
strncpynt (p->server, server, sizeof (p->server));
p->port = port;
@@ -389,11 +389,27 @@ recv_socks_reply (socket_descriptor_t sd,
return true;
}
+static int
+port_from_servname(const char* servname)
+{
+ int port =0;
+ port = atoi(servname);
+ if(port >0 && port < 65536)
+ return port;
+
+ struct servent* service;
+ service = getservbyname(servname, NULL);
+ if(service)
+ return service->s_port;
+
+ return 0;
+}
+
void
establish_socks_proxy_passthru (struct socks_proxy_info *p,
socket_descriptor_t sd, /* already open to proxy */
const char *host, /* openvpn server remote */
- const int port, /* openvpn server port */
+ const char *servname, /* openvpn server port */
volatile int *signal_received)
{
char buf[128];
@@ -414,6 +430,13 @@ establish_socks_proxy_passthru (struct socks_proxy_info *p,
buf[4] = (char) len;
memcpy(buf + 5, host, len);
+ int port = port_from_servname (servname);
+ if (port ==0)
+ {
+ msg (D_LINK_ERRORS, "establish_socks_proxy_passthrough: Cannot convert %s to port number", servname);
+ goto error;
+ }
+
buf[5 + len] = (char) (port >> 8);
buf[5 + len + 1] = (char) (port & 0xff);
@@ -426,6 +449,7 @@ establish_socks_proxy_passthru (struct socks_proxy_info *p,
}
}
+
/* receive reply from Socks proxy and discard */
if (!recv_socks_reply (sd, NULL, signal_received))
goto error;