--- httptunnel-old/htc.c 2001-05-10 11:04:39.000000000 +0200 +++ httptunnel/htc.c 2008-06-05 23:54:19.000000000 +0200 @@ -29,6 +29,7 @@ int host_port; char *proxy_name; int proxy_port; + int connect; size_t proxy_buffer_size; int proxy_buffer_timeout; size_t content_length; @@ -77,6 +78,7 @@ " -M, --max-connection-age SEC maximum time a connection will stay\n" " open is SEC seconds (default is %d)\n" " -P, --proxy HOSTNAME[:PORT] use a HTTP proxy (default port is %d)\n" +" -C, --connect use a CONNECT request through proxy.\n" " -s, --stdin-stdout use stdin/stdout for communication\n" " (implies --no-daemon)\n" " -S, --strict-content-length always write Content-Length bytes in requests\n" @@ -121,6 +123,7 @@ arg->host_port = DEFAULT_HOST_PORT; arg->proxy_name = NO_PROXY; arg->proxy_port = DEFAULT_PROXY_PORT; + arg->connect = FALSE; arg->proxy_buffer_size = NO_PROXY_BUFFER; arg->proxy_buffer_timeout = -1; arg->content_length = DEFAULT_CONTENT_LENGTH; @@ -147,6 +150,7 @@ #endif { "proxy", required_argument, 0, 'P' }, { "device", required_argument, 0, 'd' }, + { "connect", no_argument, 0, 'C' }, { "timeout", required_argument, 0, 'T' }, { "keep-alive", required_argument, 0, 'k' }, { "user-agent", required_argument, 0, 'U' }, @@ -160,7 +164,7 @@ { 0, 0, 0, 0 } }; - static const char *short_options = "A:B:c:d:F:hk:M:P:sST:U:Vwz:" + static const char *short_options = "A:B:c:d:F:hk:M:P:CsST:U:Vwz:" #ifdef DEBUG_MODE "D:l:" #endif @@ -239,7 +243,11 @@ arg->proxy_buffer_timeout = DEFAULT_PROXY_BUFFER_TIMEOUT; break; - case 's': + case 'C': + arg->connect = TRUE; + break; + + case 's': arg->use_std=TRUE; arg->use_daemon=FALSE; break; @@ -390,6 +398,12 @@ "used without --proxy\n", arg->me); arg->proxy_authorization = NULL; } + + if (arg->connect != FALSE) + { + fprintf (stderr, "%s: warning: --connect can't be used without" + " --proxy\n", arg->me); + } } else if (arg->proxy_buffer_size == NO_PROXY_BUFFER) arg->proxy_buffer_timeout = -1; @@ -423,6 +437,7 @@ log_notice (" host_port = %d", arg.host_port); log_notice (" proxy_name = %s", arg.proxy_name ? arg.proxy_name : "(null)"); log_notice (" proxy_port = %d", arg.proxy_port); + log_notice (" connect = %d", arg.connect); log_notice (" proxy_buffer_size = %d", arg.proxy_buffer_size); log_notice (" proxy_buffer_timeout = %d", arg.proxy_buffer_timeout); log_notice (" content_length = %d", arg.content_length); @@ -538,6 +553,10 @@ &arg.max_connection_age) == -1) log_debug ("tunnel_setopt max_connection_age error: %s", strerror (errno)); + + if (tunnel_setopt (tunnel, "connect", &arg.connect) == -1) + log_debug ("tunnel_setopt connect error: %s", + strerror (errno)); if (arg.proxy_authorization != NULL) { --- httptunnel-old/tunnel.c 2000-09-01 10:59:45.000000000 +0200 +++ httptunnel/tunnel.c 2008-06-05 23:54:19.000000000 +0200 @@ -90,6 +90,7 @@ int strict_content_length; int keep_alive; int max_connection_age; + int connect; }; static const size_t sizeof_header = sizeof (Request) + sizeof (Length); @@ -343,6 +344,26 @@ log_debug ("tunnel_in_disconnect: input disconnected"); } +static void +tunnel_write_connect_header(Tunnel *tunnel, int fd) +{ + char *connect_header; + char buffer[20]; + if (tunnel->connect == TRUE) + { + connect_header= (char*)malloc(55 + +2*strlen(tunnel->dest.host_name)+strlen(tunnel->dest.proxy_name)); + sprintf(connect_header, "CONNECT %s:%d HTTP/1.1\r\nVia: %s:%d\r\n" + "Host: %s:%d\r\n\r\n", tunnel->dest.host_name, tunnel->dest.host_port, + tunnel->dest.proxy_name, tunnel->dest.proxy_port, + tunnel->dest.host_name, tunnel->dest.host_port); + write(fd,connect_header,strlen(connect_header)); + recv(fd,buffer,1,0); + while(recv(fd,buffer,19,MSG_DONTWAIT) > 0) { } + free(connect_header); + } +} + static int tunnel_out_connect (Tunnel *tunnel) { @@ -368,6 +389,7 @@ } tunnel_out_setsockopts (tunnel->out_fd); + tunnel_write_connect_header(tunnel, tunnel->out_fd); #ifdef USE_SHUTDOWN shutdown (tunnel->out_fd, 0); @@ -419,6 +441,7 @@ } tunnel_in_setsockopts (tunnel->in_fd); + tunnel_write_connect_header(tunnel, tunnel->in_fd); if (http_get (tunnel->in_fd, &tunnel->dest) == -1) return -1; @@ -1395,6 +1418,13 @@ else tunnel->max_connection_age = *(int *)data; } + else if (strcmp (opt, "connect") == 0) + { + if (get_flag) + *(int *)data = tunnel->connect; + else + tunnel->connect = *(int *)data; + } else if (strcmp (opt, "proxy_authorization") == 0) { if (get_flag) --- httptunnel-old/tunnel.h 2001-06-12 15:03:02.000000000 +0200 +++ httptunnel/tunnel.h 2008-06-05 23:56:36.000000000 +0200 @@ -66,6 +66,12 @@ keep-alive bytes will be sent when the connection is idle. Otherwise, no keep-alive bytes will be sent. + * connect + + DATA must be a pointer to an int. If the int is nonzero, + all connections through a proxy will use the http CONNECT + method. + * max_connection_age DATA must be a pointer to an int. The int specifies the maximum