#include <iostream>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define max_buffer 50000
#define sp_text "GET /\n"
using namespace std;
class read_WWW
{
private:
char *buf;
struct hostent *temp_host;
struct sockaddr_in s_in;
int r_socket;
ssize_t temp_read;
public:
read_WWW(char *www,int port_number)
{
buf=new char[max_buffer];
s_in.sin_family=AF_INET;
r_socket=socket(PF_INET,SOCK_STREAM,0);
temp_host=gethostbyname(www);
s_in.sin_addr=*((struct in_addr*) temp_host->h_addr);
s_in.sin_port=htons(port_number);
sprintf(buf,sp_text);
}
void write_WWW()
{
write(r_socket,buf,strlen(buf));
while(1)
{
temp_read=read(r_socket,buf,max_buffer);
fwrite(buf,sizeof(char),temp_read,stdout);
}
}
~read_WWW()
{
delete buf;
}
};
Brak komentarzy:
Prześlij komentarz