Okay men når jeg putter det ind i mit program får jeg fejl:
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#include <fstream>
#define TIMEOUT 15 /* Sec */
using namespace std;
char cmd[1024]; /* Kommando buffer */
char resp[9999999]; /* Vores side havner i denne buffer */
char adresse[1024];
int htmlstorrelse;
void get(char *hostname, short port, char *path)
{
int sd, status, len, ix, tmp;
struct sockaddr local,remote;
struct hostent *hostinfo;
fd_set ReadSet;
struct timeval Time;
/* create socket */
sd = socket(AF_INET, SOCK_STREAM, 0);
if(sd == INVALID_SOCKET)
{
MessageBox(NULL, "Fejl ved oprettning af socket", "Error", MB_OK);
return;
}
/* bind socket */
local.sa_family = AF_INET;
memset(local.sa_data, 0, sizeof(local.sa_data));
status = bind(sd, &local, sizeof(local));
if(status == INVALID_SOCKET)
{
MessageBox(NULL, "Fejl ved bindning af socket", "Error", MB_OK);
closesocket(sd);
return;
}
/* lookup host */
hostinfo = gethostbyname(hostname);
if(!hostinfo)
{
MessageBox(NULL, "Fejl ved hostname", "Error", MB_OK);
closesocket(sd);
return;
}
/* connect to host */
remote.sa_family = hostinfo->h_addrtype;
memcpy(remote.sa_data + 2, hostinfo->h_addr_list[0], hostinfo->h_length);
*((short *)remote.sa_data) = port;
tmp = remote.sa_data[0];
remote.sa_data[0] = remote.sa_data[1];
remote.sa_data[1] = (char )tmp;
status = connect(sd, &remote, sizeof(remote));
if(status != 0)
{
MessageBox(NULL, "Error connection on port", "Error", MB_OK);
closesocket(sd);
return;
}
/* send GET request */
sprintf(cmd, "GET %s HTTP/1.1\\r\\nHost: %s\\r\\n\\r\\n", path, hostname);
status = send(sd, cmd, strlen(cmd), 0);
if(status < 0)
{
MessageBox(NULL, "Error sending POST request", "Error", MB_OK);
closesocket(sd);
return;
}
/* read response */
ix = 0;
memset(&ReadSet, 0, sizeof(ReadSet));
FD_SET(sd, &ReadSet);
Time.tv_sec = TIMEOUT;
Time.tv_usec = 0;
len = 1;
while(len > 0 && select(sd + 1, &ReadSet, 0, 0, &Time) > 0)
{
len = recv(sd, resp + ix, sizeof(resp) - ix - 1, 0);
ix += len;
Time.tv_sec = TIMEOUT;
Time.tv_usec = 0;
}
resp[ix] = 0;
htmlstorrelse = resp.size();
closesocket(sd);
return;
}
int main(void)
{
cout << "Skriv adresse: ";
cin >> adresse;
WORD version = MAKEWORD(1, 1);
WSADATA wsaData;
WSAStartup(version, &wsaData);
get(adresse, 80, "/");
printf("Hit Enter to quit\\n");
getchar();
WSACleanup();
return 0;
}
fejl:
C:\\BORLAND\\BCC55\\BIN>bcc32 hent.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
hent.cpp:
Warning W8012 hent.cpp 84: Comparing signed and unsigned values in function get(
char *,short,char *)
Error E2294 hent.cpp 98: Structure required on left side of . or .* in function
get(char *,short,char *)
Kan du finde ud af hvad fejlen er?