diff --git a/http.c b/http.c index 8de4f65..71b1f29 100644 --- a/http.c +++ b/http.c @@ -49,7 +49,7 @@ void analyze_HTTP() p = strtok( buf, " "); else { - message( "analyze_HTTP: readline failed: Connection closed by foreign host\n" ); + message( "analyze_HTTP: readline failed: Connection closed by remote host\n" ); exit(2); } } @@ -60,17 +60,17 @@ void analyze_HTTP() exit( 1 ); } - p = strtok( 0, " "); + p = strtok( NULL, " "); if( strcmp( p, "200" ) != 0 ) { if( ! args_info.quiet_flag ) - message( "HTTP return code: '%s'\n", p ); + message( "HTTP return code: %s ", p ); p += strlen( p ) + 1; if( ! args_info.quiet_flag ) - message( "%s\n", p ); + message( "%s", p ); if (!ntlm_challenge && strcmp( p, "407") != 0) { @@ -93,14 +93,18 @@ void analyze_HTTP() } } -void print_line(char *buf) +/* + * Prints lines from a buffer prepended with a prefix + */ +void print_line_prefix(char *buf, char *prefix) { - char *buf2 = strdup(buf); - char *p = strtok(buf2, "\r\n"); - while ( p != NULL) { - message( "-> %s\n", p ); - p = strtok(NULL, "\r\n"); + buf = strdup(buf); + char *cur = strtok(buf, "\r\n"); + while ( cur != NULL) { + message( "%s %s\n", prefix, cur ); + cur = strtok(NULL, "\r\n"); } +// free(buf); } /* @@ -160,7 +164,7 @@ void proxy_protocol() */ if( args_info.verbose_flag ) { message( "Connect string sent to local proxy:\n"); - print_line(buf); + print_line_prefix(buf, "->"); } /* @@ -175,7 +179,7 @@ void proxy_protocol() * Read the first line of the response and analyze it */ if( args_info.verbose_flag ) - message( "Received from local proxy:\n"); + message( "Data received from local proxy:\n"); analyze_HTTP(); @@ -202,7 +206,7 @@ void proxy_protocol() */ if( args_info.verbose_flag ) { message( "Connect string sent to remote proxy:\n"); - print_line(buf); + print_line_prefix(buf, "->"); } /* diff --git a/messages.c b/messages.c index 2b83052..9c37bda 100644 --- a/messages.c +++ b/messages.c @@ -47,7 +47,10 @@ void message( char *s, ... ) */ void my_perror( char *msg ) { - char *err = strerror( errno ); - - message( "Error! %s: %s\n", msg, err ); + if (errno == 0) { + message( "error: %s.\n", msg ); + } else { + char *errstr = strerror( errno ); + message( "error: %s: [%d] %s\n", msg, errno, errstr ); + } } diff --git a/proxytunnel.c b/proxytunnel.c index 1a0189e..75dc282 100755 --- a/proxytunnel.c +++ b/proxytunnel.c @@ -88,7 +88,8 @@ void tunnel_connect() { */ if( ! ( he = gethostbyname( args_info.proxyhost_arg ) ) ) { - my_perror("Proxy host not found"); +// FIXME: my_perror("Local proxy %s could not be resolved", args_info.proxyhost_arg); + my_perror("Local proxy could not be resolved" ); exit(1); } @@ -96,7 +97,7 @@ void tunnel_connect() { snprintf(ip, 16, "%d.%d.%d.%d", he->h_addr[0] & 255, he->h_addr[1] & 255, he->h_addr[2] & 255, he->h_addr[3] & 255); if( args_info.verbose_flag && strcmp(args_info.proxyhost_arg, ip)) { - message( "%s is %d.%d.%d.%d\n", + message( "Local proxy %s resolves to %d.%d.%d.%d\n", args_info.proxyhost_arg, he->h_addr[0] & 255, he->h_addr[1] & 255, @@ -354,7 +355,7 @@ int main( int argc, char *argv[] ) * - Check if we need to run as a daemon. If so, a completely * different mainline is needed... * - Set a signal for the hangup (HUP) signal - * - Optionally create the proxy basic authenticcation cookie + * - Optionally create the proxy basic authentication cookie * - Connect the sd socket to the proxy * - Execute the proxy protocol to connect it to the origin server * - Enter copy in-out mode to channel data hence and forth