Cryptography Reference
In-Depth Information
&proxy_user, &proxy_password ) )
{
fprintf( stderr, “Error - malformed proxy parameter '%s'.\n”,
argv[ 2 ] );
return 2;
}
ind++;
}
if ( parse_url( argv[ ind ], &host, &path ) == -1 )
If the fi rst argument is -p , take the second argument to be a proxy specifi cation
in the canonical form and parse it. Either way, the last argument is still a URL.
If parse_proxy_param succeeds, proxy_host is a non-null pointer to the host-
name of the proxy server. You need to make a few changes to your connection
logic to support this correctly, as shown in Listing 1-9. First you need to establish
a socket connection to the proxy host rather than the actual target HTTP host.
Listing 1-9: “http.c” main (with proxy support) (continued)
if ( proxy_host )
{
printf( “Connecting to host '%s'\n”, proxy_host );
host_name = gethostbyname( proxy_host );
}
else
{
printf( “Connecting to host '%s'\n”, host );
host_name = gethostbyname( host );
}
host_address.sin_family = AF_INET;
host_address.sin_port = htons( proxy_host ? proxy_port : HTTP_PORT );
memcpy( &host_address.sin_addr, host_name->h_addr_list[ 0 ],
sizeof( struct in_addr ) );
http_get( client_connection, path, host, proxy_host,
proxy_user, proxy_password );
Finally, pass the proxy host, user, and password to http_get . The new parse_
proxy_param function works similarly to the parse_url function in Listing
1-2: pass in a pointer to the argv string, insert nulls at strategic places, and set
char * pointers to the appropriate places within the argv string to represent
the individual pieces, as shown in Listing 1-10.
Listing 1-10: “http.c” parse_proxy_param
int parse_proxy_param( char *proxy_spec,
char **proxy_host,
int *proxy_port,
char **proxy_user,
char **proxy_password )
{
Search WWH ::




Custom Search