#include <windows.h>
#include <fstream>
#include <string>
#include <stdio.h>
#include <iostream>
using namespace std;
string cc_escape (string in) {
struct map_t {
char cOld;
char* sNew;
};
const map_t MAP[8] = {
{'"', "%22" },
{'%', "%25" },
{'&', "%26" },
{'?', "%3F" },
{'=', "%3D" },
{' ', "%20" },
{'<', "%3C" },
{'>', "%3E" }
};
string ret;
size_t nLen = in.length ();
for (size_t i = 0; i < nLen; ++i) {
char c = in[i];
bool bFound = false;
for (int j = 0; j < 8; ++j)
if (c == MAP[j].cOld) {
ret += MAP[j].sNew;
bFound = true;
break;
}
if (!bFound)
ret += c;
}
return ret;
}
char* get_host_ip (char* host) {
// Soll die IP des Hosts zurückgeben, ob das Argument der
// Name des Hosts ist oder sdie IP selber...
// Existiert kein Host mit dem eingegebenen Namen/eingegebener IP, 0 zurückgeben...
}
int startWinsock (void);
int main (unsigned short argc, char* argv[]) {
long rc = startWinsock();
if (rc != 0) {
printf ("Winsock konnte nicht gestartet werden -> %d\n", rc);
} else {
printf ("Winsock gestartet!\n");
// --- Socket erstellen.
int s = socket(AF_INET, SOCK_STREAM, 0);
if (s == INVALID_SOCKET) {
printf ("Fehler: Socket konnte nicht erstellt werden -> %d\n", WSAGetLastError());
} else {
printf ("Socket erstellt!\n");
// --- Abfragen, zu welchem host verbinden.
char host[30];
printf ("Host> ");
scanf ("%s", host);
// --- Socket an einen Host verbinden.
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(80);
addr.sin_addr.s_addr = inet_addr(host);
// --- Prüfen, ob Host existiert.
if (addr.sin_addr.s_addr == 0) {
printf ("Konnte Host nicht finden!");
} else {
rc = connect(s, (SOCKADDR*)&addr, sizeof(SOCKADDR));
if (rc == -1) {
printf ("Konnte nicht zum Server verbinden!\n");
} else {
printf ("Verbunden!\n");
// --- Request an Host.
string pst = "test=hallo";
string req = "";
req += "POST /tell.php HTTP/1.0\r\n";
req += "Host: "+host+"\r\n";
req += "Content-Type: application/x-www-form-urlencoded\r\n";
req += "Content-Length: ";
req += pst.length();
req += "\r\n\r\n";
req += pst;
if (!send(s, req.c_str(), req.length(), 0)) {
printf ("Request konnte nicht gesendet werden!\n");
} else {
cout << endl << "--- --- REQ --- ---" << endl << req << endl << "--- --- --- --- ---" << endl << endl;
}
}
}
}
}
system ("PAUSE");
return 0;
}
int startWinsock (void) {
WSADATA wsa;
return WSAStartup(MAKEWORD(2,0),&wsa);
}