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
|
#include <stdio.h>
#include <winsock.h>
int main()
{
struct sockaddr_in server;
struct hostent *host_info;
int sock;
char buffer[8192];
int count;
/* Initialisiere TCP für Windows ("winsock") */
short wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD (1, 1);
if (WSAStartup (wVersionRequested, &wsaData) != 0) {
fprintf( stderr, "Failed to init windows sockets\n");
exit(1);
}
sock = socket( PF_INET, SOCK_STREAM, 0);
memset(&server, 0, sizeof(server));
host_info = gethostbyname("www.test.de");
memcpy((char *)&server.sin_addr, host_info->h_addr, host_info->h_length);
printf("IP: %s\n", inet_ntoa(server.sin_addr));
server.sin_family = AF_INET;
server.sin_port = htons(80);
if ( connect( sock, (struct sockaddr*)&server, sizeof( server)) < 0) {
perror( "can't connect to server");
exit(1);
}
printf("Connected!\n");
sprintf(buffer, "GET server.php?action=getlist HTTP/1.0\r\nHost: www.test.de\r\nUser-Agent: Mein Browser\r\nAccept: */*\r\n\r\n");
printf("Sende Anfrage:\n\t%s\n", buffer);
send(sock, buffer, strlen(buffer), 0);
do
{
count = recv(sock, buffer, sizeof(buffer), 0);
buffer[count] = '\0';
printf(buffer);
} while (count > 0);
/* Schließe Verbindung und Socket */
closesocket( sock);
return count;
}
|