i have a problem that it alawys says that the server couldnt understand i dont rlly understand http protocol i quite got some of the picture by packet sniffing but i didnt acctually read the RFC
Code:
#include <stdio.h>
#include <windows.h>
#include <winsock.h>
#pragma comment( lib, "ws2_32" )
char *Http="http://www.google.com.com";
int Port = 80;//default port for http
void Send_Packet(SOCKET sock,char *packets, ... )//by a59 with lil touch by me
{
char buffersize[400];
va_list varagums;
va_start( varagums, packets );
vsprintf( buffersize, packets, varagums );
va_end(varagums);
send(sock,buffersize,strlen(buffersize),0);
}
int Setup_it()
{
SOCKET http;
SOCKADDR_IN Info;
LPHOSTENT hostEntry;
int error;
/*Resolve it*/
hostEntry=gethostbyname(Http);
if(!hostEntry)
return FALSE;
//cr8 the socket
http=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(http==INVALID_SOCKET)
return FALSE;
Info.sin_family = AF_INET;
Info.sin_addr=*((LPIN_ADDR)*hostEntry->h_addr_list);
Info.sin_port=htons(Port);
error=connect(http,(SOCKADDR*)&Info,sizeof Info);
if(error==INVALID_SOCKET)
return FALSE;
return http;
}
BOOL download_it()
{
char path[100];
char buffer[100]={0};
FILE *fp;
SOCKET http;
http=Setup_it();
if(!http) return FALSE;
GetTempPath(sizeof path,path);
fp=fopen(path,"w");
Send_Packet(http,"GET /kosomack1234/exe.exe HTTP/1.1\r\n");
Send_Packet(http,"Host: www.google.com\r\n");
Send_Packet(http,"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5\r\n");
Send_Packet(http,"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n");
Send_Packet(http,"Accept-Language: en-us,en;q=0.5\r\n");
Send_Packet(http,"Accept-Encoding: gzip,deflate\r\n");
Send_Packet(http,"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n");
Send_Packet(http,"Keep-Alive: 300\r\n");
Send_Packet(http,"Connection: keep-alive\r\n");
recv(http,buffer,sizeof buffer,0);
puts(buffer);
}
int main(void)
{
WSADATA Client;
WSAStartup(MAKEWORD(2,2),&Client);
download_it();
return 0;
}