1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
using namespace std;
int main(int argc, char *argv[])
{
char * chaine,* buff;
int socketDescriptor, length, len=0;
struct sockaddr_in sockaddrStruct;
ofstream f;
sockaddrStruct.sin_addr.s_addr = inet_addr("127.0.0.1");
sockaddrStruct.sin_family = AF_INET;
sockaddrStruct.sin_port = htons(3128);//port);
sockaddrStruct.sin_zero[8]=0;
chaine = (char * )malloc(600);
if (!chaine){
cout<<"erreur d'allocation de \'chaine\'"<<endl;
return -1;
}
buff=(char *)malloc(50000);
if (!buff){
cout<<"erreur d'allocation de \'buff\'"<<endl;
return -1;
}
*buff=0;
strcpy(chaine,"GET http://sourceforge.net/index.php HTTP/1.1\r\n"
"Host: sourceforge.net\r\n"
"User-Agent: Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.8.1) Gecko/20061023 SUSE/2.0-30 Firefox/2.0 MEGAUPLOAD 1.0\r\n"
"Accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,;q=0.5\r\n"
"Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3\r\n"
"Accept-Encoding: gzip,deflate\r\n"
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"
"Keep-Alive: 300\r\n"
"Proxy-Connection: close\r\n\r\n");
f.open("f.txt");
if(!f){
cout<<"erreur d'ouverture du fichier"<<endl;
return -1;
}
if ((socketDescriptor = socket(AF_INET, SOCK_STREAM, 0))<0){
cout<<"erreur de creation de socket"<<endl;
return -1;
}
if (connect(socketDescriptor,
(struct sockaddr *)&sockaddrStruct,
sizeof(sockaddrStruct)
)<0){
cout<<"erreur de connexion de la socket"<<endl;
return -1;
}
len=strlen(chaine);
length=write(socketDescriptor,
chaine,
len);
for (;length=recv(socketDescriptor,buff,50000, 0)!=0;) {
cout<<"writing"<<endl;
f<<buff;
sleep(1);
*buff=0;
}
return EXIT_SUCCESS;
} |
Partager