I am new to network programming, and trying to read a response from a servers webpage.
I can connect, but cannot get the pages source. Heres what I have
#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
int main(int argc,char **args){
if(argc < 2){
printf("2 args\n");
return 1;
}
int port = atoi(args[1]);
int sockfd = socket(AF_INET,SOCK_STREAM,0);
struct sockaddr_in client;
client.sin_addr.s_addr = inet_addr("192.168.1.3");
client.sin_port = htons(port);
client.sin_family = AF_INET;
printf("here\n");
int conn = connect(sockfd,(struct sockaddr *)&client,sizeof(client));
if(conn < 0)
return 1;
char m[1000];
read(sockfd,m,sizeof(m));
printf("%s\n",m);
close(sockfd);
return 0;
}
i can get my webpage from my other computer fine, theres no firewall blocking
connections to port 80.
But I cant read the page source from this program..
Works fine with ssh, port 22..I get the little ssh message.
Any clues to why I cannot read the servers response from port 80?