I made this little program, the purpose was for it to send a GET /index.html HTTP/1.0 to a httpd.
The only problem is, however, that although it makes a connection ( i see it with netstat -n ) it doesnt dump the source of index.html to my screen....
heres the code:
It just doesnt do anything, i didnt wait for that long because i know that other similair programs returned the source in a few seconds...
int main( int argc, char **argv )
if( argc < 2 )
printf("Usage: httprq <host>\n");
struct hostent *h;
struct sockaddr_in dest;
if( (h = (struct hostent *)gethostbyname(argv)) == -1 )
printf("Could not lookup hostname\n");
if( (sockfd = socket( AF_INET, SOCK_STREAM, 0 )) == -1 )
printf("Could not create socket\n");
dest.sin_port = htons(80);
dest.sin_family = AF_INET;
dest.sin_addr = *((struct in_addr *)h->h_addr);
char *msg = "GET /index.html HTTP/1.1";
if( (connect( sockfd, (struct sockaddr *)&dest, sizeof(struct sockaddr))) == -1 )
printf("Could not connect to remote host\n");
write( sockfd, msg, strlen(msg) );
read( sockfd, recv, 900 );
printf("%s\n", recv );
btw; i also tried it with send() and recv() no luck either....