Cryptography Reference
In-Depth Information
{
perror( “Error in name resolution” );
return 3;
}
host_address.sin_family = AF_INET;
host_address.sin_port = htons( HTTP_PORT );
memcpy( &host_address.sin_addr, host_name->h_addr_list[ 0 ],
sizeof( struct in_addr ) );
if ( connect( client_connection, ( struct sockaddr * ) &host_address,
sizeof( host_address ) ) == -1 )
{
perror( “Unable to connect to host” );
return 4;
}
printf( “Retrieving document: '%s'\n”, path );
Assuming nothing went wrong — the socket structure could be created, the
hostname could be resolved to an IP address, the IP address was reachable, and
the server accepted your connection on the well-known port 80 — you now have
a usable (cleartext) socket with which to exchange data with the web server. Issue
a GET command, display the result, and close the socket, as shown in Listing 1-5.
Listing 1-5: “http.c” main (continued)
http_get( client_connection, path, host );
display_result( client_connection );
printf( “Shutting down.\n” );
#ifdef WIN32
if ( closesocket( client_connection ) == -1 )
#else
if ( close( client_connection ) == -1 )
#endif
{
perror( “Error closing client connection” );
return 5;
}
#ifdef WIN32
WSACleanup();
#endif
return 0;
}
An HTTP GET command is a simple, plaintext command. It starts with the
three ASCII-encoded letters GET , all in uppercase (HTTP is case sensitive), a
space, the path to the document to be retrieved, another space, and the token
 
Search WWH ::




Custom Search