i am making a virus submitter tool that automatically checks files online
here is the code, the problem is i am saying to keep the connection alive but after sending the identificador GET packet
recv is coming back with 0 and connection close ,
here is the actual packets live with a firefox addon called live htttp headers
C++ pastebin - collaborative debugging tool, if someone could assist me on my project that would be great
Code:
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#pragma comment(lib , "WS2_32.lib")
int _tmain(int argc, _TCHAR* argv[])
{
//Inialize winsock to version 2.0
WSADATA WSAdata;
WSAStartup(MAKEWORD(2, 2), &WSAdata);
//Resolve the website to get the ip
unsigned long IP = inet_addr("virustotal.com");
if (IP==INADDR_NONE) {
hostent *pHE = gethostbyname("virustotal.com");
if (pHE == 0)
return INADDR_NONE;
IP = *((unsigned long *)pHE->h_addr_list[0]);
}
//Assign type ,port, ip
sockaddr_in sins;
sins.sin_family = AF_INET;
sins.sin_port = htons(80);
sins.sin_addr.s_addr = IP;
SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
//Connect to the resolved ip
if(connect(sock, (sockaddr *)&sins, sizeof(SOCKADDR_IN))!= SOCKET_ERROR)
{
printf("%s\n","Connected:");
}
char Buffer[50000];
sprintf(Buffer,"GET / HTTP/1.1\r\n"
"Host: www.virustotal.com\r\n"
"Keep-Alive: 300\r\n"
"Connection: keep-alive\r\n\r\n");
send(sock,Buffer,strlen(Buffer),0);
int Recvamount = 0;
memset(Buffer,0,sizeof(Buffer));
Recvamount = recv(sock,Buffer,sizeof(Buffer),0);
printf("%s\n",Buffer);
memset(Buffer,0,sizeof(Buffer));
//Build the identificador GET packet
sprintf(Buffer,"GET /vt/en/identificador HTTP/1.1\r\n"
"Host: www.virustotal.com\r\n"
"Keep-Alive: 300\r\n"
"Connection: keep-alive\r\n\r\n");
//Send the identificador packet to website
send(sock,Buffer,strlen(Buffer),0);
//Recv the data that came back from the site
memset(Buffer,0,sizeof(Buffer));
Recvamount = recv(sock,Buffer,sizeof(Buffer),0);
printf("%s\n",Buffer);
return 0;
}