Автор: Quies (05.10.2008 в 17:35)
Пока, вышел такой код:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <iostream>
#include <cstdlib>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <sys/un.h>
#include <arpa/inet.h>
#define NSTRS 30 /* no. of strings */
using namespace std;
int main ( int argc, char *argv[] )
{
char c;
FILE *fp;
int i;
int thisSocket;
struct sockaddr_in destination;
destination.sin_family = AF_INET;
thisSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (thisSocket < 0)
{
printf("\nSocket Creation FAILED!");
return 0;
} else {
destination.sin_port = htons(80);
destination.sin_addr.s_addr = inet_addr("127.0.0.1");
if (connect(thisSocket,(struct sockaddr*)&destination,sizeof(destination))!=0){
printf("\nSocket Connection FAILED!\n");
if (thisSocket) close(thisSocket);
return 0;
}
printf("\nConnected!");
fp = fdopen(thisSocket, "r");
for (i = 0; i < NSTRS; i++) {
while ((c = fgetc(fp)) != EOF) {
putchar(c);
if (c == '\n')
break;
}
}
printf("%s",c);
} // конец условия
close(thisSocket);
return EXIT_SUCCESS;
}
|
Успешно компилируется, соединяется с сервером. Выводит пустую строку. Но дальше не знаю что делать,.. как вытащить страницу сайта,.. и как вообще зайти не по ip, а по имени домена. и пути до файла. Скажем http://www.site.ru/test.html