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
|
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main (int agrc, char ** argv)
{
int resSocket = 0;
int resSend = 0;
char buff[1024];
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
inet_pton(PF_INET, "88.191.250.104", &addr.sin_addr);
if((resSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
fprintf(stderr, "le socket est ratte");
exit(errno);
}
if (connect(resSocket, (const void*)&addr, sizeof(addr)) < 0)
{
fprintf(stderr, "la connexion a echoue");
exit(-1);
}
char * mesg = "GET http://lesite.org/2009/11/15/26161.html HTTP/1.0";
if((resSend = send(resSocket, (const void*)&mesg, strlen(mesg), 0)) < 0)
{
fprintf(stderr, "l'envois de la requete a rate\n");
exit(errno);
}
recv(resSocket, buff, 1024, 0);
printf("resultat : %s\n", buff);
close(resSocket);
} |
Partager