#include #include #include
#include #include #include
int main(int argc,char *argv[]) {
int sock;
int err;
struct sockaddr_in servidor;
char buf[20000];
FILE *f;
/* Abrimos el socket */
sock=socket(PF_INET,SOCK_STREAM,0);
/* Rellenamos la estructura de la direccion */
servidor.sin_family=AF_INET;
servidor.sin_port=htons(80);
servidor.sin_addr.s_addr=htonl(0x82CEA0D7);
/* Conexion al servidor TCP */
err = connect(sock,(struct sockaddr *)&servidor,sizeof(servidor));
if ( err == -1 ) {
printf("Error!! no consigo conectar!!!\n");
exit(-1);
}
/* La conexion esta establecida */
/* Abrimos una Stream sobre el socket */
f=fdopen(sock,"r+");
/* Escribamos la peticion de Web por la Stream */
fprintf(f,"GET / HTTP/1.0\r\n\r\n");
/* Vamos imprimiendo las lineas que llegan */
while (fgets(buf,20000,f)!=NULL) {
printf("%s",buf);
}
printf("Conexion cerrada por el servidor\n");
fclose(f);
}