#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<netdb.h>

int Open( char * ) ;
main()
{
	int cs ;
	char req[] = "GET http://www.cis.uoguelph.ca/~dobo/month HTTP/1.1\r\nHost: www.cis.uoguelph.ca\r\nContent-Length: 0\r\nKeep-Alive: timeout=15\r\nConnection: close\r\n\r\n" ;
	int rc ;
	char mess[500] ;

	cs = Open( "www.cis.uoguelph.ca" ) ; // creates a socket
		// and opens a connection to the http server specified
	rc = send( cs , req , sizeof req , 0 ) ;
	printf( "Sent %d\n%s\n" , rc , req ) ;
	rc = recv( cs , &mess , sizeof mess , 0 ) ;
	printf( "Received: %d\n" , rc ) ;
	mess[rc] = '\0' ;	// printf %s needs it
	printf( "%s\n" , mess ) ;
	close( cs ) ;
}

int Open( char *url )
{
	int cs ;
	struct sockaddr_in csSA ;
	struct hostent *server ;

	bzero( &csSA , sizeof csSA ) ;

//
// csSA is filled right here. The code was deleted for your
// inconvenience; it contained references to htons() and gethostbyname().
// 
	csSA.sin_family = 
	csSA.sin_port = 
	server = 
	memcpy( (char *) &csSA.sin_addr , server->h_addr , server->h_length ) ;

	cs = socket(    // Stolen arguments!!!
	if( cs == -1 ) {
		printf( "Socket failed\n" ) ;
		exit( -1 ) ;
	}
	if( connect(    // Stolen arguments!!!
		printf( "Connect failed c\n" ) ;
		exit( -1 ) ;
	}
	return cs ;
}

