Hi,
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:
Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
int main( int argc, char **argv )
{
if( argc < 2 )
{
printf("Usage: httprq <host>\n");
exit(1);
}
struct hostent *h;
struct sockaddr_in dest;
int sockfd;
if( (h = (struct hostent *)gethostbyname(argv[1])) == -1 )
{
printf("Could not lookup hostname\n");
exit(1);
}
if( (sockfd = socket( AF_INET, SOCK_STREAM, 0 )) == -1 )
{
printf("Could not create socket\n");
exit(1);
}
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";
char recv[900];
if( (connect( sockfd, (struct sockaddr *)&dest, sizeof(struct sockaddr))) == -1 )
{
printf("Could not connect to remote host\n");
close(sockfd);
}
else
{
write( sockfd, msg, strlen(msg) );
read( sockfd, recv, 900 );
printf("%s\n", recv );
close(sockfd);
}
exit(1);
}
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...
btw; i also tried it with send() and recv() no luck either....
thanks,
encrypted